Pythonで学ぶサンプリング
James Chapman
Curriculum Manager, DataCamp
方法や意図的な選択なしに、作られ・行われ・起こり・選ばれること。
seed = 1
calc_next_random(seed)
3
calc_next_random(3)
2
calc_next_random(2)
6
numpy.random を前置。例: numpy.random.beta()| function | distribution | function | distribution |
|---|---|---|---|
| .beta | ベータ | .hypergeometric | 超幾何分布 |
| .binomial | 二項分布 | .lognormal | 対数正規分布 |
| .chisquare | カイ二乗分布 | .negative_binomial | 負の二項分布 |
| .exponential | 指数分布 | .normal | 正規分布 |
| .f | F分布 | .poisson | ポアソン分布 |
| .gamma | ガンマ分布 | .standard_t | t分布 |
| .geometric | 幾何分布 | .uniform | 一様分布 |
randoms = np.random.beta(a=2, b=2, size=5000)
randoms
array([0.6208281 , 0.73216171, 0.44298403, ...,
0.13411873, 0.52198411, 0.72355098])
plt.hist(randoms, bins=np.arange(0, 1, 0.05))
plt.show()

np.random.seed(20000229)
np.random.normal(loc=2, scale=1.5, size=2)
array([-0.59030264, 1.87821258])
np.random.normal(loc=2, scale=1.5, size=2)
array([2.52619561, 4.9684949 ])
np.random.seed(20000229)
np.random.normal(loc=2, scale=1.5, size=2)
array([-0.59030264, 1.87821258])
np.random.normal(loc=2, scale=1.5, size=2)
array([2.52619561, 4.9684949 ])
np.random.seed(20000229)
np.random.normal(loc=2, scale=1.5, size=2)
array([-0.59030264, 1.87821258])
np.random.normal(loc=2, scale=1.5, size=2)
array([2.52619561, 4.9684949 ])
np.random.seed(20041004)
np.random.normal(loc=2, scale=1.5, size=2)
array([1.09364337, 4.55285159])
np.random.normal(loc=2, scale=1.5, size=2)
array([2.67038916, 2.36677492])
Pythonで学ぶサンプリング