zoukankan      html  css  js  c++  java
  • numpy统计分布显示

    #导包
    import numpy as np
    #导入鸢尾花数据
    from sklearn.datasets import load_iris
    data = load_iris()
    pental_len = data.data[:,2]
    print(pental_len)
    
    #计算尾花花瓣长度的最大值,平均值,中值,均方差
    print("最大值:",np.max(pental_len))
    print("平均值:",np.mean(pental_len))
    print("中值:",np.median(pental_len))
    print("均方差:",np.std(pental_len))
    
    #用np.random.normal()产生一个正态分布的随机数组,并显示出来
    #正态分布
    import numpy as np
    import matplotlib.pyplot as plt
    mu = 2  #期望为2
    sigma = 3  #标准差为3
    num = 1000  #个数为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()
    
    #np.random.randn()产生一个正态分布的随机数组,并显示出来
    Data=np.random.randn(50)
    print(Data)
    
    #显示鸢尾花花瓣长度的正态分布图,曲线图,散点图
    
    #正态分布图
    import numpy as np
    import matplotlib.pyplot as plt
    mu=np.mean(pental_len)
    sigma=np.std(pental_len)
    num=99999
    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(1,150,num=150),pental_len,'c')
    plt.show()
    #散点图#
    plt.scatter(np.linspace(0,150,num=150),pental_len,alpha=0.5,marker='4')
    plt.show()

  • 相关阅读:
    window端口被占用
    webstorm中关闭烦人Eslint语法检查
    STM32 printf 函数原型
    Memset、Memcpy、Strcpy 的作用和区别(转)
    SMD贴片元件的封装尺寸(转)
    Windows Phone开发工具初体验(转载)
    Open Cell(转载)
    标题:常用贴片元件封装(转载)
    关于TV Dongle的功能设计和思考【图】(转载)
    图片预览加上传遇到的一系列问题
  • 原文地址:https://www.cnblogs.com/moon2/p/9822790.html
Copyright © 2011-2022 走看看