NumPy Statistical Distribution Display

Source: Internet
Author: User

  1. The
  2. 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:                                                                                          

  3. The
  4. 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:                                                                                                       

  5. The
  6. 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; 

  7. 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 ()

  8. 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 ()

  9. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.