X
1回の成功に必要なベルヌーイ試行回数の確率分布は、幾何分布( https://en.wikipedia.org/wiki/Geometric_distribution )に従い、次の式で直接X=n
与えられる対応する確率を計算できます。p
p = 1./6 # prob of successes
geom_prob = []
for n in range(1,25):
geom_prob.append((1-p)**(n-1)*p)
print geom_prob
# [0.16666666666666666, 0.1388888888888889, 0.11574074074074076, 0.09645061728395063, 0.08037551440329219, 0.06697959533607684, 0.05581632944673069, 0.04651360787227558, 0.038761339893562986, 0.032301116577969156, 0.02691759714830763, 0.022431330956923026, 0.018692775797435855, 0.015577313164529882, 0.012981094303774901, 0.010817578586479085, 0.009014648822065905, 0.0075122073517215875, 0.006260172793101323, 0.005216810660917769, 0.0043473422174314744, 0.003622785181192896, 0.0030189876509940797, 0.002515823042495067]
import matplotlib.pyplot as plt
plt.plot(geom_prob)
plt.xlabel('n')
plt.ylabel('probability')
plt.title('Probability of getting first head on nth roll of a die')
plt.show()

次のように、シミュレーションを使用して確率を見つけることもできます。
import numpy as np
sim_geom = np.random.geometric(p=p, size=1000)
import seaborn as sns
sns.distplot(sim_geom)
plt.show()
