Beta分布 原理理解及python 绘图
2021/12/5 12:17:26
本文主要是介绍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
这篇关于Beta分布 原理理解及python 绘图的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享