0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonで学ぶ統計入門3

Posted at

復習用に確率分布の一部を記載

▶️ 確率分布ってなに?

確率分布は、「値がどんな分布で出現するか」を描くものです!
たとえば、実験や現実のデータが、正規分布(ガウス分布)になることも多いです。


▶️ Pythonで実践する確率分布

1. 正規分布 (Normal Distribution)

$$
P(x) = \frac{1}{\sqrt{2\pi\sigma^2}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}
$$

  • $\mu$:平均(分布の中心)
  • $\sigma$:標準偏差(広がり具合)
  • $P(x)$:xにおける確率密度

数値の意味

  • $\mu$ が大きい → 分布の中心が右に移動!
  • $\sigma$ が大きい → データが広くばらつく!

Pythonコード

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

# パラメータ
mu, sigma = 0, 1

# x範囲
x = np.linspace(-5, 5, 100)

# PDF計算
pdf = norm.pdf(x, mu, sigma)

# プロット
plt.plot(x, pdf)
plt.title('Normal Distribution')
plt.xlabel('x')
plt.ylabel('Probability Density')
plt.grid(True)
plt.show()

実践ポイント: 平均周辺に値が集中する!


2. ベルヌーイ分布 (Bernoulli Distribution)

$$
P(x) = p^x (1-p)^{1-x}, \quad x \in {0,1}
$$

  • $p$:1になる確率(成功確率)
  • $x$:結果 (0または1)

数値の意味

  • $p$ が大きい → 1が出やすい!
  • $p$ が小さい → 0が出やすい!

Pythonコード

from scipy.stats import bernoulli

# p = 0.3のベルヌーイ分布
p = 0.3
x = [0, 1]
y = bernoulli.pmf(x, p)

plt.bar(x, y)
plt.title('Bernoulli Distribution')
plt.xlabel('x')
plt.ylabel('Probability')
plt.show()

実践ポイント: 事象が起こるか起こらないかをモデリング!


3. ポアソン分布 (Poisson Distribution)

$$
P(x;\lambda) = \frac{\lambda^x e^{-\lambda}}{x!}
$$

  • $\lambda$:単位時間に発生する事象の平均回数
  • $x$:発生回数

数値の意味

  • $\lambda$ が大きい → たくさん発生する!
  • $\lambda$ が小さい → ほとんど発生しない!

Pythonコード

from scipy.stats import poisson

# パラメータ
lambda_ = 3
x = np.arange(0, 10)
y = poisson.pmf(x, lambda_)

plt.bar(x, y)
plt.title('Poisson Distribution')
plt.xlabel('Number of Events')
plt.ylabel('Probability')
plt.show()

実践ポイント: 一定期間のイベント回数を数えるときに使う!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?