Python Data Science 简明教程
Python - Bernoulli Distribution
伯努利分布是二项分布的一个特例,其中进行单个实验,以便观测数量为 1。因此,伯努利分布描述的事件恰好具有两个结果。
The Bernoulli distribution is a special case of the Binomial distribution where a single experiment is conducted so that the number of observation is 1. So, the Bernoulli distribution therefore describes events having exactly two outcomes.
我们在 numpy 库中使用各种函数来计算伯努利分布的值。创建直方图,我们在其上绘制概率分布曲线。
We use various functions in numpy library to mathematically calculate the values for a bernoulli distribution. Histograms are created over which we plot the probability distribution curve.
from scipy.stats import bernoulli
import seaborn as sb
data_bern = bernoulli.rvs(size=1000,p=0.6)
ax = sb.distplot(data_bern,
kde=True,
color='crimson',
hist_kws={"linewidth": 25,'alpha':1})
ax.set(xlabel='Bernouli', ylabel='Frequency')
它的 output 如下所示 −
Its output is as follows −
