- The
- calculates the maximum, average, median, and mean variance of the iris petal length.
from sklearn.datasets import load_irisimport numpy as Npiris = Load_iris () print (Iris) Petal_length=np.array (list (len[2]for len in iris[' data ')) Np.max (petal_length) #花瓣长度最大值np. Min (petal_length) # Petal length min np.std (petal_length) #花瓣长度数值的标准差np. Median (petal_length) #花瓣长度数值的中位数
Run result:
- The
- generates a random array of normal distributions with np.random.normal () and displays them.
np.random.normal (loc=1,scale=10,size=100) #产生一个均值为1, random array of normal distribution with a standard deviation of 10
Run result:
- The
- Np.random.randn () produces a random array of normal distributions and displays them.
np.random.randn (3,3) #3行3列正态分布随机数组
Run Result: & nbsp , &NB Sp &nbs p;
- A normal distribution graph showing the length of the iris petals.
Import Matplotlib.pyplot as PLTMU = Np.mean (petal_length) #花瓣长度期望值sigma = NP.STD (petal_length) #花瓣长度标准差num = 150rand_data= np.random.normal (mu,sigma,num) print (Rand_data.shape,type (rand_data)) 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 ( bins,1/(Sigma * NP.SQRT (2 * np.pi)) *np.exp (-(BINS-MU) **2/(2 * sigma**2)), linewidth=2, color= ' B ') #花瓣长度正态分布图plt. Sh OW ()
- Graph showing the length of iris petals
mu = Np.mean (petal_length) #花瓣长度期望值sigma = NP.STD (petal_length) #花瓣长度标准差num =150rand_data= Np.random.normal ( Mu,sigma,num) Print (Rand_data.shape,type (rand_data)) print (Np.mean (petal_length), NP.STD (Petal_length), Np.median ( petal_length)) Plt.plot (Np.linspace (0,150,num=150), petal_length, ' B ') #花瓣曲线图plt. Show ()
Scatter plot showing the length of iris petals
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,150,num=150), petal_length,alpha=0.5,marker= ' D ') #花瓣散点图plt. Show ()
NumPy Statistical Distribution Display