Calculates the maximum, average, median, and mean variance of the iris petal length.
Generates a random array of normal distributions with np.random.normal () and displays them.
NP.RANDOM.RANDN () produces a random array of normal distributions and displays them.
Shows the normal distribution of iris petal length, graph, scatter plot.
Code:
ImportNumPy as NP fromSklearn.datasetsImportLoad_irisImportMatplotlib.pyplot as Plt#Read the iris DataSet data from the Sklearn packet's own data setData=Load_iris ()#calculates the maximum, average, median, and mean variance of the iris petal length. petal_data=data['Data'][:,2]#Petal Length DataPetal_max=np.max (Petal_data)#Maximum ValuePetal_mean=np.mean (Petal_data)#AveragePETAL_STD=NP.STD (Petal_data)#mean VariancePrint("Petal length data:", Petal_data)Print('Maximum value:', Petal_max,'Average:','Average:', Petal_mean,'mean variance:', PETAL_STD)#generates a random array of normal distributions with np.random.normal () and displays them. Mu=1Sigma=3Num=10000Rand_data=np.random.normal (mu,sigma,num)Print(Rand_data.shape,type (rand_data)) 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='R') plt.show ()#Np.random.randn () produces a random array of normal distributions and displays them. rand_data1=np.random.normal (mu,sigma,num)Print(Rand_data1.shape,type (rand_data)) count,bins,ignored=plt.hist (rand_data1,30,normed=True) Plt.plot (bins,1/(Sigma * NP.SQRT (2 * np.pi)) *np.exp (-(BINS-MU) **2/(2*sigma**2)), linewidth=2, color='g') plt.show ()#shows the normal distribution of iris petal length, graph, scatter plot. Mu=petal_mean#Normal distribution DiagramSigma=Petal_stdnum1=10000Rand_data=np.random.normal (MU,SIGMA,NUM1)Print(Rand_data.shape,type (rand_data)) 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='g') plt.show ()#GraphPlt.plot (Np.linspace (0,150,150), Petal_data,'R') plt.show ()#Scatter ChartPlt.scatter (Np.linspace (0,150,150), Petal_data) plt.show ()
Operation Result:
NumPy Statistical Distribution Display