foreword
In the process of doing the algorithm, you may encounter knowledge such as probability density distribution. Here is a supplement to the use of the corresponding scipy piece.
Mainly from scipy.stats import norm
The corresponding is also a normal distribution (Gaussian distribution)
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html
The normal distribution formula is:
The graph looks like this:
This graph is the probability density
say a few nouns here
Random variables (including discrete random variables + continuous random variables)
Probability Density Functions (Probability Density Functions - PDF)
Cumulative Distribution Functions (CDF)
For details, you can read this article, which is well understood with some small examples (toss a coin) https://blog.csdn.net/neweastsun/article/details/124191560
Probability Density Function (PDF) and Cumulative Distribution Function (CDF) and scipy.stats.norm use
the code
The corresponding pdf and cdf functions are provided in from scipy.stats import norm
from scipy.stats import norm
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 2)
x = np.linspace(norm.ppf(0.0001),
norm.ppf(0.9999), 100)
print(x)
rv = norm()
ax[0].bar(x, rv.pdf(x), width=0.01, label='pdf')
ax[0].set_xticks([-3, -2, -1, 0, 1, 2, 3])
ax[0].set_yticks([0.0, 0.1, 0.2, 0.3, 0.4])
ax[0].set_title("pdf")
ax[1].plot(x, rv.cdf(x), '-^', linewidth=1, label='cdf', markersize=2)
ax[1].set_xticks([-3, -2, -1, 0, 1, 2, 3])
ax[1].set_yticks(np.linspace(0.0, 1.0, 5))
ax[1].set_title("cdf")
plt.show()
result:
The left side is the probability density distribution map (the peak is around 0, and the two sides are descending successively, and it is highly symmetrical), and the right side is the cumulative distribution map (the maximum value is 1, and the range is 0-1)
In order to draw this picture, we need the original data (in fact, the x-axis data of the pdf and cdf images), which can be obtained by ppf. ppf is the reverse calculation of cdf, which is equivalent to giving a cumulative quantile point (0 to 1, 0 is close to the leftmost side of the pdf picture, and 1 is close to the far right side of the pdf picture), and the corresponding x value is returned.
Recommended reading:
My 2022 Internet School Recruitment Sharing
Talking about the difference between algorithm post and development post
Internet school recruitment research and development salary summary
The 2022 Internet job hunting status, gold 9 silver 10 will soon become copper 9 iron 10! !
Public number: AI snail car
Stay humble, stay disciplined, keep improving
Send [Snail] to get a copy of "Hands-on AI Project" (written by AI Snail Car)
Send [1222] to get a good leetcode brushing notes
Send [AI Four Classics] Get four classic AI e-books