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("最大值:",np.max(pental_len))
    print("平均值:",np.mean(pental_len))
    print("中值:",np.median(pental_len))
    print("均方差:",np.std(pental_len))
    
    # 用np.random.normal()产生一个正态分布的随机数组,并显示出来
    print(np.random.normal(1,4,50))
    print('============================================================================')
    
    # np.random.randn()产生一个正态分布的随机数组,并显示出来
    print(np.random.randn(50))
    
    # 显示鸢尾花花瓣长度的正态分布图
    import matplotlib.pyplot as plt
    mu = np.mean(pental_len)
    sigma = np.std(pental_len)
    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(1,160,num=150),pental_len,'g') plt.show() # 显示鸢尾花花瓣长度的散点图 plt.scatter(np.linspace(1,160,num=150),pental_len,alpha=1,marker='x') plt.show()

     

  • 相关阅读:
    LayoutInflater
    android 顶部的通知栏
    ..搞Android了
    数据分组取最大值行
    decode、sign、case在统计中的用法:
    Row generator
    存储过程包实例分享
    Bind variables in 'in' condition(在in中动态的绑定参数(参数个数可变))
    WM_CONCAT字符超过4000的处理办法
    oracle script
  • 原文地址:https://www.cnblogs.com/hodafu/p/9815890.html
Copyright © 2011-2022 走看看