#计算鸢尾花花瓣长度的最大值, mean, median, mean variance. Import as np from sklearn.datasets import load_irisdata=Load_iris ( ) Iris=data.datapetal_length=iris[:,2] #取所有行的第二列print (Np.mean (petal_length)) #平均值print (NP.STD (petal_length)) #标准差print (Np.median (petal_length)) #中位数print (Np.max (Petal_ Length) print (Np.min (petal_length))
#用np. Random.normal () produces a random array of normal distributions and displays them. Print (Np.random.normal (1,3,))
#np. RANDOM.RANDN () produces a random array of normal distributions and displays them. Print (Np.random.randn (3,3)) #3行3列正太分布随机数组print (Np.random.randn ( ))
#显示鸢尾花花瓣长度的正态分布图import Matplotlib.pyplot asPLTMU=Np.mean (petal_length) #期望sigma=np.std (petal_length) #标准差num= +#个数为1000rand_data=np.random.normal (mu,sigma,num) print (rand_data.shape) print (Type (rand_data)) print (Np.mean (petal_length), NP.STD (Petal_length), Np.median (petal_length)) count,bins,ignored=plt.hist (Rand_data, -, normed=True) Plt.plot (bins,1/(Sigma*np.sqrt (2*NP.PI)) *np.exp (-(BINS-MU) * *2/(2*sigma**2)), linewidth=2, color="R") plt.show ()
#显示鸢尾花花瓣长度的曲线图mu=Np.mean (petal_length) #期望sigma=np.std (petal_length) #标准差print (Np.mean ( Petal_length), NP.STD (Petal_length), Np.median (petal_length)) count,bins,ignored=plt.hist (rand_data,30 , normed=True) plt.plot (np.linspace (0,num=),petal_length,' R') plt.show ()
#显示鸢尾花花瓣长度的散点图. Mu=np.mean (petal_length) #期望sigma=np.std (petal_length) #标准差print (Np.mean (petal_length), NP.STD ( Petal_length), Np.median (petal_length)) Plt.scatter (np.linspace (0,num=), Petal_length,alpha=0.5, marker='D') plt.show ()
NumPy Statistical Distribution Display