numpy統計分析

來源:互聯網
上載者:User

標籤:隨機數   均值   atp   otl   隨機數組   imp   ase   顯示   bubuko   

#計算鳶尾花的花瓣長度的最大值,均值,中值,均方差from sklearn.datasets import load_irisdata=load_iris()data_length=data.data[:,2]print("最大值:",np.max(data_length),"\n","平均值:",np.mean(data_length),"\n","中值:",np.median(data_length),"\n","均方差:",np.std(data_length))

#用np.random.normal()產生一個常態分佈的隨機數組,並顯示出來np.random.normal(3,5,100)import matplotlib.pyplot as pltmu=3sigma=5num=100rand_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()產生一個常態分佈的隨機數組,並顯示出來n1=np.random.randn(4,4)mu=np.median(n1)sigma=np.std(n1)import matplotlib.pyplot as pltmu=np.median(n1)sigma=5num=np.std(n1)print(n1.shape,type(n1))count,bins,ignored=plt.hist(n1,15,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()
##顯示鳶尾花花瓣長度的常態分佈圖import matplotlib.pyplot as pltmu=np.median(data_length)sigma=np.std(data_length)num=data_length.shaperand_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()

#鳶尾花花瓣的曲線圖,import matplotlib.pyplot as plty=np.linspace(0,150)x=data_lengthplt.plot(np.linspace(0,150,num=150),data_length,"g")plt.show()

#鳶尾花花瓣的散佈圖,import matplotlib.pyplot as plty=np.linspace(0,150)x=data_lengthplt.scatter(np.linspace(0,150,num=150),data_length,alpha=0.5,marker="+")plt.show()

numpy統計分析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.