Calculates the maximum, average, median, and mean variance of the iris petal length.
Import NumPy as NP
From sklearn.datasets import Load_iris
data = Load_iris ()
Iris = data[' data '][:,2]
Print (IRIS)
D1 = Np.max (Iris) #最大值
D2 = Np.min (Iris) #最小值
D3 = Np.mean (Iris) #平均值
D4 = NP.STD (Iris) #标准差
d5 = Np.median (Iris) #中位数
d6 = Np.var (Iris) #均方差
Print (' Max: ', D1, ' Minimum value: ', D2, ' mean: ', D3, ' Standard deviation: ', ' D4, ' median: ', D5, ' mean variance: ', d6)
Operation Result:
[1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 1.5 1.6 1.4 1.1 1.2 1.5 1.3 1.4 1.7 1.5 1.7 1.5 1. 1.7 1.9 1.6 1.6 1.5 1.4 1.6 1.6 1.5 1.5 1.4 1.5 1.2 1.3 1.5 1.3 1.5 1.3 1.3 1.3 1.6 1.9 1.4 1.6 1.4 1.5 1.4 4.7 4.5 4.9 4. 4.6 4.5 4.7 3.3 4.6 3.9 3.5 4.2 4. 4.7 3.6 4.4 4.5 4.1 4.5 3.9 4.8 4. 4.9 4.7 4.3 4.4 4.8 5. 4.5 3.5 3.8 3.7 3.9 5.1 4.5 4.5 4.7 4.4 4.1 4. 4.4 4.6 4. 3.3 4.2 4.2 4.2 4.3 3. 4.1 6. 5.1 5.9 5.6 5.8 6.6 4.5 6.3 5.8 6.1 5.1 5.3 5.5 5. 5.1 5.3 5.5 6.7 6.9 5. 5.7 4.9 6.7 4.9 5.7 6. 4.8 4.9 5.6 5.8 6.1 6.4 5.6 5.1 5.6 6.1 5.6 5.5 4.8 5.4 5.6 5.1 5.1 5.9 5.7 5.2 5. 5.2 5.4 5.1] Maximum value: 6.9 min: 1.0 average: 3.758666666666666 standard deviation: 1.7585291834055212 median: 4.35 mean variance: 3.092424888888889
Generates a random array of normal distributions with np.random.normal () and displays them.
Print (Np.random.normal (1,5,50))
Operation Result:
[ -5.10198013e-01-1.81127171e+00 5.34966309e-03 5.24510514e-01 2.07924729e+00-3.45949650e-01- 1.87590835e+00-5.90793739e+00 4.03057879e+00-5.35822967e+00-4.85137851e+00 3.66594079e-01 2.90050275e+00 3.98166421e+00 6.01702926e-01-3.82470992e-01 1.42019409e+00 3.11379512e+00 1.58160501e+00 3.70511275e-01 1.26240090e+01-2.34050982e-02-3.31556855e+00-8.31884546e-01 1.03108864e+01-2.64570955e+00 5.03789132e-01-1.54695868e+00 2.33496569e+00 4.48225666e+00 6.97529467e+00 5.93501594e-01 9.51437532e+00-1.63662989e+00 2.78086368e+00-3.39023516e+00 -5.36499527e+00 6.20385466e+00 7.60688118e+00 9.90523253e+00-3.28345342e+00 1.13692427e+01 -6.43695936e-01 1.52830168e+00 3.08966939e+00 3.62968008e-01-7.30428859e+00 7.38387038e+00 -3.37837186E+00-9.59828248E+00]
Generates a random array of normal distributions with NP.RANDOM.RANDN () and displays them.
Print (NP.RANDOM.RANDN (5,5))
Operation Result:
[[0.33772723 1.01557765-0.90059905 0.07573804-0.079598 ] [0.42330696 0.03920182-0.26022139 1.71730775 1.29189732] [ -3.30138842-1.52347219-1.76926508-1.05615513 1.08341371] [0.47337674-0.12343634- 0.46157369 0.06619216 0.92866926] [ -0.70744157-0.18383115-1.66756331 0.81238919-1.90095927]
Shows the normal distribution of iris petal length, graph, scatter plot.
Normal distribution Map
Import NumPy as NP
Import Matplotlib.pyplot as Plt
mu = 1 #期望值为1
Sigma = 3 #标准差为3
num = 10000 #个数为10000
Rand_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 ()
Operation Result:
(10000,) <class ' Numpy.ndarray ' >
Graph
Import NumPy as NP
Import Matplotlib.pyplot as Plt
Plt.plot (Np.linspace (0,150,num=150), petal_length, ' R ')
Plt.show ()
Operation Result:
Scatter chart
Plt.scatter (Np.linspace (0,200,num=150), petal_length,alpha=1,marker= ' x ', color = ' R ')
Plt.show ()
Operation Result:
NumPy Statistical Distribution Display