import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
from scipy.stats import bernoulli
sns.set(style="white")
X = bernoulli(p=0.3)
Python
サンプリング
In [2]:
x = X.rvs(size=5)print(x)
Python
[1 1 1 0 0]
確率質量関数
In [3]:
x =[0,1]
y = X.pmf(x)
fig, ax = plt.subplots()
ax.stem(x, y, use_line_collection=True)
ax.set_xlim(-0.1,1.1)
ax.set_ylim(-0.1,1.1)
ax.grid()
plt.show()
Python
累積分布関数
In [4]:
x = np.linspace(-0.1,1.1,100)
y = X.cdf(x)
fig, ax = plt.subplots()
ax.step(x, y)
ax.set_xlim(-0.1,1.1)
ax.set_ylim(-0.1,1.1)
ax.grid()
plt.show()
コメント