Beta分布 原理理解及python 绘图

最近用到了β分布,需要理解一下β分布的原理

1.Beta分布

参考:直观理解β分布

2.python 绘图

画图工具源码:https://github.com/technojoe9982/Beta-Distribution-Plotter
画PDF(Probability Density Function)的关键代码段(截取自上述链接的源码):

def plot_pdf(x_range, a, b, **kwargs):
    #this is a function which plots the beta probability desnity function

    #axises are cleared so when you want to draw a plot with new values you don't have multiple lines
    axs[0].cla()
    #here we plot text which shows the outcomes which are being plotted, done for clarity
    goodOutcomes = "Good outcomes: " + str(a-1)
    badOutcomes = "Bad outcomes: " + str(b-1)
    axs[0].text(0.01, 0.95, goodOutcomes, transform=axs[0].transAxes, fontsize=10)
    axs[0].text(0.01, 0.87, badOutcomes, transform=axs[0].transAxes, fontsize=10)

    #labels are re-wrriten as the axis have just been cleared
    axs[0].set_ylabel('Probability Density')
    axs[0].set_xlabel('Probability')
    x = x_range
    #array of y values are calculated using the betapdf function
    y = ss.beta.pdf(x, a, b)
    #plotting the array of x and y values, takes in extra arguements so it's easy to adjust properties of the line
    axs[0].plot(x, y, **kwargs)
    plt.show()

关键代码段的调用:

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as ss
import PySimpleGUI as sg
x = np.linspace(0, 1, 5000)
plot_pdf(x, a, b,  color='red', lw=2, ls='-', alpha=0.7)

a=0.5,b=0.5
在这里插入图片描述
a=1,b=1
(此时β分布等于均匀分布)
在这里插入图片描述
a=2,b=2
在这里插入图片描述
a=4,b=4
在这里插入图片描述

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值