numpy统计分布显示
生活随笔
收集整理的這篇文章主要介紹了
numpy统计分布显示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import numpy as np from sklearn.datasets import load_iris data=load_iris()petal_length=numpy.array(list(len[2]for len in data['data']))#取出花瓣長度數據 print(np.max(petal_length))#花瓣長度最大值 print(np.mean(petal_length))#花瓣長度平均值 print(np.std(petal_length))#花瓣長度的中值 print(np.median(petal_length))#花瓣長度的均方差
運行結果:
np.random.normal(1,5,100)#用np.random.normal()產生一個正態分布的隨機數組,并顯示出來運行結果:
?
?
?
np.random.randn(3, 3)np.random.randn()#產生一個正態分布的隨機數組,并顯示出來。運行結果為:
?
#顯示鳶尾花花瓣長度的正態分布圖 import numpy as np import matplotlib.pyplot as plt mu=np.mean(petal_length) sigma=np.std(petal_length) num=10000 rand_data = np.random.normal(mu, sigma, num) 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()運行結果為:
?
#顯示鳶尾花花瓣長度的曲線圖 plt.plot(np.linspace(0,150,num=150),petal_length,'y') plt.show()運行結果為:
#顯示鳶尾花花瓣長度的散點圖 import numpy as np import matplotlib.pyplot as plt plt.scatter(np.linspace(0,150,num=150),petal_length,alpha=0.5,marker='h',color='y') plt.show()運行結果為:
?
轉載于:https://www.cnblogs.com/fanfanfan/p/9813634.html
總結
以上是生活随笔為你收集整理的numpy统计分布显示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到掉上牙齿是什么预兆
- 下一篇: Javassist实现JDK动态代理