python-numpy-正态分布的模拟--pdf图--cdf图---正态分布的拟合
2018-03-17 10:02
841 查看
# Draw 100000 samples from Normal distribution with stds of interest: samples_std1, samples_std3, samples_std10 samples_std1=np.random.normal(20,1,size=100000) samples_std3=np.random.normal(20,3,size=100000) samples_std10=np.random.normal(20,10,size=100000) # Make histograms plt.hist(samples_std1,bins=100,normed=True,histtype='step') plt.hist(samples_std3,bins=100,normed=True,histtype='step') plt.hist(samples_std10,bins=100,normed=True,histtype='step') # Make a legend, set limits and show plot _ = plt.legend(('std = 1', 'std = 3', 'std = 10')) plt.ylim(-0.01, 0.42) plt.show()
cdf图的画法# Generate CDFs
x_std1,y_std1=ecdf(samples_std1)
x_std3,y_std3=ecdf(samples_std3)
x_std10,y_std10=ecdf(samples_std10)
# Plot CDFs
plt.plot(x_std1,y_std1,marker='.',linestyle='none')
plt.plot(x_std3,y_std3,marker='.',linestyle='none')
plt.plot(x_std10,y_std10,marker='.',linestyle='none')
# Make 2% margin
plt.margins(0.02)
# Make a legend and show the plot
_ = plt.legend(('std = 1', 'std = 3', 'std = 10'), loc='lower right')
plt.show()
正态分布的拟合# Compute mean and standard deviation: mu, sigma
mu=np.mean(belmont_no_outliers)
sigma=np.std(belmont_no_outliers)
# Sample out of a normal distribution with this mu and sigma: samples
samples=np.random.normal(mu,sigma,10000)
# Get the CDF of the samples and of the data
x,y=ecdf(belmont_no_outliers)
x_theor,y_theor=ecdf(samples)
# Plot the CDFs and show the plot
_ = plt.plot(x_theor, y_theor)
_ = plt.plot(x, y, marker='.', linestyle='none')
plt.margins(0.02)
_ = plt.xlabel('Belmont winning time (sec.)')
_ = plt.ylabel('CDF')
plt.show()
相关文章推荐
- Python处理PDF与CDF
- python 正态分布随机数 numpy.random.randn 使用小技
- (python_numpy_)用直线拟合理解主元素分析(PCA)(直线重构)
- python-numpy-伯努利试验模拟-np.random.binomial--自定义bins的直方图
- python-numpy-指数分布模拟
- python 正态分布随机数 numpy.random.randn 使用小技
- Python实现曲线拟合操作示例【基于numpy,scipy,matplotlib库】
- Python使用numpy产生正态分布随机数的向量或矩阵操作示例
- Python 最小二乘法多项式拟合曲线numpy.polyfit(),numpy.poly1d(),pylab
- 用python的numpy作线性拟合、多项式拟合、对数拟合
- python数据分析——安装numpy,生成正态分布并简单分析
- Python numpy的简单操作(一)
- python 模拟知乎登陆
- python.numpy学习
- Python Intro - Compile and Install numpy library on Ubuntu
- 模拟登陆百度 python
- Python爬虫002浏览器的模拟Header属性
- windows下python,numpy,scipy,matplotlib安装
- [置顶] Python-Numpy
- 图文并茂的Python教程-numpy.pad