zoukankan      html  css  js  c++  java
  • python画高斯分布图形

    高斯分布,也叫正态分布,是一个在数学、物理及工程等领域都非常重要的概率分布,在统计学的许多方面有着重大的影响力。

    若随机变量X服从一个数学期望为μ、方差为σ^2的正态分布,记为N(μ,σ^2)。其概率密度函数为正态分布的期望值μ决定了其位置,其标准差σ决定了分布的宽度。当μ = 0,σ = 1时的正态分布是标准正态分布。 

    定义 

    ---------以上摘自百度百科

    import numpy as np
    import matplotlib.pyplot as plt
    import math
    
    
    def normal_distribution(x, mean, sigma):
        return np.exp(-1*((x-mean)**2)/(2*(sigma**2)))/(math.sqrt(2*np.pi) * sigma)
    
    
    mean1, sigma1 = 0, 1
    x1 = np.linspace(mean1 - 6*sigma1, mean1 + 6*sigma1, 100)
    
    mean2, sigma2 = 0, 2
    x2 = np.linspace(mean2 - 6*sigma2, mean2 + 6*sigma2, 100)
    
    mean3, sigma3 = 5, 1
    x3 = np.linspace(mean3 - 6*sigma3, mean3 + 6*sigma3, 100)
    
    y1 = normal_distribution(x1, mean1, sigma1)
    y2 = normal_distribution(x2, mean2, sigma2)
    y3 = normal_distribution(x3, mean3, sigma3)
    
    plt.plot(x1, y1, 'r', label='m=0,sig=1')
    plt.plot(x2, y2, 'g', label='m=0,sig=2')
    plt.plot(x3, y3, 'b', label='m=1,sig=1')
    plt.legend()
    plt.grid()
    plt.show()
    

     

  • 相关阅读:
    Java集合
    C#高级应用
    使用C#分层查询多个表数据
    数据库之SQL语句查询基础
    简要介绍一下MD5加密的书写
    C#简单工厂模式和单列设计模式潜要解析
    Struts2测试题
    小程序自定义组件
    flex布局笔记
    小程序的双线程模型
  • 原文地址:https://www.cnblogs.com/lingjiajun/p/10146252.html
Copyright © 2011-2022 走看看