机器学习中的概率分布(二)

6.β分布(连续)

表示形式为:

其中,a和b为形状参数,定义域为(0,1),通常用于建模伯努利试验事件成功的概率的概率分布。

  • 掷骰子可以确定系统成功的概率的简单实验,但实际情况下,系统成功的概率未知,但可通过频率估计概率。
  • 对于n次试验,统计成功次数k。但系统成功的概率未知,因此,通过该公式最终得到的是系统成功概率的最佳估计。实际值可能是其他数值,只是概率较小。所以,硬币正面出现概率就是这个数值,是随机变量,符合Beta分布,取值范围为0到1。
  • 因此,Beta分布可看作一个概率的概率密度分布。如果某个东西具体概率未知,Beta分布给出的是所有概率出现的可能性大小。

Beta函数:

 Beta分布:

Beta 分布的期望:

EX=\frac{\alpha }{\alpha +\beta }

Beta 分布的方差:

DX=\frac{\alpha \beta }{(\alpha +\beta +1)(\alpha +\beta)^{2}}

https://zhuanlan.zhihu.com/p/69606875?ivk_sa=1024320uicon-default.png?t=M5H6https://zhuanlan.zhihu.com/p/69606875?ivk_sa=1024320u

28b1a60d83db71aedca3d38ef8e0d6a0.png

7.Dirichlet 分布(连续)

  • 狄利克雷分布,又称多元Beta分布;
  • 在Bayesian inference里,Dirichlet分布是多项分布的共轭先验;
  • 如果 k=2,则为β分布。

  • 代码:https://github.com/graykode/distribution-is-all-you-need/blob/master/dirichlet.py 

https://en.wikipedia.org/wiki/Dirichlet_distributionicon-default.png?t=M5H6https://en.wikipedia.org/wiki/Dirichlet_distributionc9612fd7723bdf437d67c82485435807.png

8.伽马分布(连续)

https://en.wikipedia.org/wiki/Gamma_distributionicon-default.png?t=M5H6https://en.wikipedia.org/wiki/Gamma_distribution 

"""
    https://github.com/graykode/distribution-is-all-you-need/blob/master/gamma.py
    https://en.wikipedia.org/wiki/Gamma_distribution
"""
import numpy as np
from matplotlib import pyplot as plt

def gamma_fun(n):
    cal = 1
    for i in range(2,n):
        cal *= i
    return cal

def gamma(x, a, b):
    c = (a ** b) / gamma_fun(a)
    y = c *(x ** (a-1)) * np.exp(-b * x)
    return x, y, np.mean(y), np.std(y)

for ls in [(1, 1), (2, 1), (3, 1), (2, 2)]:
    a, b = ls[0], ls[1]

    x = np.arange(0, 20, 0.01, dtype = np.float)
    x, y, u, s = gamma(x, a=a, b=b)
    plt.plot(x, y, label=r'$\mu=%.2f,\ \sigma=%.2f,'
                         r'\ \alpha=%d,\ \beta=%d$' % (u, s, a, b))
plt.legend()
# plt.savefig('graph/gamma.png')
plt.show()

 9.指数分布(连续)

指数分布是 α 为 1 时 γ 分布的特例。https://en.wikipedia.org/wiki/Exponential_distributionicon-default.png?t=M5H6https://en.wikipedia.org/wiki/Exponential_distribution

 

"""
    https://github.com/graykode/distribution-is-all-you-need/blob/master/exponential.py
    https://en.wikipedia.org/wiki/Exponential_distribution
"""
import numpy as np
from matplotlib import pyplot as plt

def exponential(x, lamb):
    y = lamb * np.exp(-lamb * x)
    return x, y, np.mean(y), np.std(y)

for lamb in [0.5, 1, 1.5]:

    x = np.arange(0, 20, 0.01, dtype=np.float)
    x, y, u, s = exponential(x, lamb=lamb)
    plt.plot(x, y, label=r'$\mu=%.2f,\ \sigma=%.2f,'
                         r'\ \lambda=%d$' % (u, s, lamb))
plt.legend()
# plt.savefig('graph/exponential.png')
plt.show()

 

10.高斯分布(连续)

 

"""
    https://github.com/graykode/distribution-is-all-you-need/blob/master/exponential.py
    https://en.wikipedia.org/wiki/Exponential_distribution
"""
import numpy as np
from matplotlib import pyplot as plt

def gaussian(x,n):
    u = x.mean()
    s = x.std()

    # divide [x.min(), x.max()] by 
    x = np.linspace(x.min(), x.max(), n)
    a = ((x - u)**2) / (2 * (s ** 2))
    y = 1 / (s * np.sqrt(2 * np.pi)) * np.exp(-a)
    return x, y, x.mean(), x.std()

x = np.arange(-100, 100) # define range of x
x, y, u, s = gaussian(x, 10000)

plt.plot(x, y, label=r'$\mu=%.2f,\ \sigma=%.2f$' % (u, s))
plt.legend()
# plt.savefig('graph/gaussian.png')
plt.show()

 

11.正态分布(连续)

正态分布为标准高斯分布,平均值为 0,标准差为 1。

"""
    https://github.com/graykode/distribution-is-all-you-need/blob/master/exponential.py
    https://en.wikipedia.org/wiki/Exponential_distribution
"""
import numpy as np
from matplotlib import pyplot as plt

def normal(x,n):
    u = x.mean()
    s = x.std()

    #normalization
    x = (x - u) / s

    # divide [x.min(), x.max()] by 
    x = np.linspace(x.min(), x.max(), n)

    a = ((x - 0)**2) / (2 * (1 ** 2))
    y = 1 / (s * np.sqrt(2 * np.pi)) * np.exp(-a)
    return x, y, x.mean(), x.std()

x = np.arange(-100, 100) # define range of x
x, y, u, s = normal(x, 10000)

plt.plot(x, y, label=r'$\mu=%.2f,\ \sigma=%.2f$' % (u, s))
plt.legend()
# plt.savefig('graph/normal.png')
plt.show()

 

12.卡方分布(连续)

  • k 自由度的卡方分布是 k 个独立标准正态随机变量的平方和的分布。

  • 卡方分布是 β 分布的特例.

  • https://en.wikipedia.org/wiki/Chi-squared_distributionicon-default.png?t=M5H6https://en.wikipedia.org/wiki/Chi-squared_distribution

    """
        https://github.com/graykode/distribution-is-all-you-need/blob/master/chi-squared.py
        https://en.wikipedia.org/wiki/Chi-squared_distribution
    """
    import numpy as np
    from matplotlib import pyplot as plt
    
    def gamma_function(n):
        cal = 1
        for i in range(2, n):
            cal *= i
        return cal
    
    def chi_squared(x, k):
        
        c = 1 / (2 ** (k/2)) * gamma_function(k//2)
        y = c * (x ** (k/2 - 1)) * np.exp(-x /2)
    
        return x, y, np.mean(y), np.std(y)
    
    for k in [2, 3, 4, 6]:
        x = np.arange(0, 10, 0.01, dtype=np.float)
        x, y, _, _ = chi_squared(x, k)
        plt.plot(x, y, label=r'$k=%d$' % (k))
    
    plt.legend()
    # plt.savefig('graph/chi-squared.png')
    plt.show()
    

     13.t 分布(连续)

  • t 分布是对称的钟形分布,与正态分布类似,但尾部较重,这意味着它更容易产生远低于平均值的值。https://en.wikipedia.org/wiki/Student%27s_t-distributionicon-default.png?t=M5H6https://en.wikipedia.org/wiki/Student%27s_t-distribution

     
    """
        https://github.com/graykode/distribution-is-all-you-need/blob/master/student-t.py
        https://en.wikipedia.org/wiki/Student%27s_t-distribution
    """
    import numpy as np
    from matplotlib import pyplot as plt
    
    def gamma_function(n):
        cal = 1
        for i in range(2, n):
            cal *= i
        return cal
    
    def student_t(x, freedom, n):
    
        # divide [x.min(), x.max()] by n
        x = np.linspace(x.min(), x.max(), n)
    
        c = gamma_function((freedom + 1) // 2) \
            / np.sqrt(freedom * np.pi) * gamma_function(freedom // 2)
        y = c * (1 + x**2 / freedom) ** (-((freedom + 1) / 2))
    
        return x, y, np.mean(y), np.std(y)
    
    for freedom in [1, 2, 5]:
    
        x = np.arange(-10, 10) # define range of x
        x, y, _, _ = student_t(x, freedom=freedom, n=10000)
        plt.plot(x, y, label=r'$v=%d$' % (freedom))
    
    plt.legend()
    # plt.savefig('graph/student_t.png')
    plt.show()

     

     

 

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 概率模型是基于概率理论的一种建模方法,它用数学语言描述随机变量之间的关系,并且通过给定一些观测数据来学习这些关系的参数。概率模型可以用于分类、回归、聚类以及其他各种机器学习任务。常见的概率模型包括朴素贝叶斯、高斯混合模型、隐马尔可夫模型和条件随机场等。概率模型的优点是可以自然地处理不确定性和噪声,同时也可以很好地应对小样本数据的情况。 ### 回答2: 在机器学习,概率模型指的是一种用于建模和预测不确定性的数学模型。它基于概率论的基本原理,通过对观测和未观测变量之间的关系进行建模,来描述数据的统计特性。 概率模型可以分为生成模型和判别模型。生成模型试图通过学习样本的联合概率分布来建模数据的生成过程,即给定输入变量x,学习输出变量y的条件概率分布P(y|x)。典型的生成模型有朴素贝叶斯分类器和隐马尔可夫模型等。 判别模型则直接对条件概率分布P(y|x)进行建模,以直接预测输出变量y。判别模型关注的是给定输入变量x情况下输出变量y的后验概率分布,而不考虑输入和输出之间的联合概率分布。常见的判别模型包括逻辑回归、支持向量机和神经网络等。 概率模型提供了一种可以反映数据不确定性的框架。利用概率模型,我们可以通过已知的观测数据来推断未知的变量,并进行概率推理和预测。概率模型还能够进行统计学习,即通过最大似然估计或贝叶斯推断等方法,从数据学习模型参数,以便更好地进行预测和决策。 总而言之,概率模型是一种可以通过建模数据的统计特性,描述输入和输出变量之间关系的数学模型。它在机器学习广泛应用,为我们提供了一种分析和预测数据的有力工具。 ### 回答3: 概率模型是机器学习一种常用的模型,它基于概率理论构建,用于描述和预测数据的分布以及变量之间的关系。概率模型主要涉及数据的生成过程,并通过已知的数据来估计模型的参数。 概率模型通常包括两个重要的组成部分:参数和随机变量。参数是模型固定的但未知的数值,代表了数据分布的特征。随机变量则是根据参数和已知数据生成的数据。概率模型通过已知数据来估计参数,进而生成新的数据或进行预测。 概率模型常见的应用包括分类、回归、聚类等。在分类任务,概率模型可以根据特征和标签之间的关系来预测新样本的标签。在回归任务,概率模型可以根据变量之间的关系预测目标变量的值。而在聚类任务,概率模型可以将具有相似特征的样本分组。 概率模型的基本假设是数据是根据某个未知分布生成的,并且该分布具有一定的参数。模型的目标是通过已知数据推断这些参数,从而能够更好地描述和预测数据。概率模型的优势在于它能够提供关于不确定性和可信度的推断,以及对数据的灵活建模能力。 总之,概率模型是机器学习常用的一种模型,它基于概率理论构建,用于描述和预测数据的分布和变量之间的关系。通过估计模型的参数,概率模型能够生成新的数据或进行预测,并提供关于不确定性和可信度的推断。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值