ベータ分布とは
ベータ分布とは、ある試行の成功数
ベータ分布の確率密度関数は次の式で表されます。
ベータ分布は下図が示す通り、
そのため、事前確率分布として扱いやすいためベイズ統計で頻繁に使用されます。
ベータ分布の α の影響
ベータ分布の
ベータ分布の β の影響
ベータ分布の
ベータ分布の期待値と分散
ベータ分布の期待値、分散はそれぞれ以下になります。
Python コード
今回使用したPythonコードは以下になります。
ベータ分布の描画
import numpy as np
from scipy.stats import beta
import matplotlib.pyplot as plt
plt.style.use('ggplot')
fig, ax = plt.subplots(facecolor="w", figsize=(10, 5))
# x axis
x = np.linspace(0, 1, 100)
# draw graph
plt.plot(x, beta.pdf(x, 1, 1), label='beta(1,1)')
plt.plot(x, beta.pdf(x, 1, 2), label='beta(1,2)')
plt.plot(x, beta.pdf(x, 2, 1), label='beta(2,1)')
plt.plot(x, beta.pdf(x, 5, 1), label='beta(5,1)')
plt.plot(x, beta.pdf(x, 7, 2), label='beta(7,2)')
plt.plot(x, beta.pdf(x, 5, 5), label='beta(5,5)')
plt.plot(x, beta.pdf(x, 1, 5), label='beta(1,5)')
plt.plot(x, beta.pdf(x, 2, 7), label='beta(2,7)')
plt.plot(x, beta.pdf(x, 10, 10), label='beta(10,10)')
plt.legend()
plt.xlabel("x")
plt.ylabel("Probability density")
plt.show()
α の影響の描画
import numpy as np
from scipy.stats import beta
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import animation, rc
from matplotlib.animation import FuncAnimation
rc('animation', html='html5')
np.random.seed(5)
# Set up formatting for the movie files
Writer = animation.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)
prob_vals = np.arange(start=0.1, stop=10.01, step=0.2)
plt.style.use('ggplot')
fig = plt.figure(figsize=(10, 5))
# x axis
x = np.linspace(0, 1, 100)
def update(i):
# initialize the graph of the previous frame
plt.cla()
p = prob_vals[i]
# draw graph
plt.plot(x, beta.pdf(x, round(p, 1), 2))
plt.title(f'$alpha={str(round(p, 1))}, beta=2$', loc='left')
plt.xlabel("x")
plt.ylabel("Probability density")
plt.ylim(0.1, 10.1)
plt.xticks(ticks=[0, 1]) # x axis ticks
anime_prob = FuncAnimation(fig, update, frames=len(prob_vals), interval=1000)
anime_prob.save('beta_dist_alpha.gif', writer='pillow', fps=10)
β の影響の描画
import numpy as np
from scipy.stats import beta
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import animation, rc
from matplotlib.animation import FuncAnimation
rc('animation', html='html5')
np.random.seed(5)
# Set up formatting for the movie files
Writer = animation.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)
prob_vals = np.arange(start=0.1, stop=10.01, step=0.2)
plt.style.use('ggplot')
fig = plt.figure(figsize=(10, 5))
# x axis
x = np.linspace(0, 1, 100)
def update(i):
# initialize the graph of the previous frame
plt.cla()
p = prob_vals[i]
# draw graph
plt.plot(x, beta.pdf(x, 2, round(p, 1)))
plt.title(f'$alpha=2, beta={str(round(p, 1))}$', loc='left')
plt.xlabel("x")
plt.ylabel("Probability density")
plt.ylim(0.1, 10.1)
plt.xticks(ticks=[0, 1]) # x axis ticks
anime_prob = FuncAnimation(fig, update, frames=len(prob_vals), interval=1000)
anime_prob.save('beta_dist_beta.gif', writer='pillow', fps=10)
AlloyDB
Amazon Cognito
Amazon EC2
Amazon ECS
Amazon QuickSight
Amazon RDS
Amazon Redshift
Amazon S3
API
Autonomous Vehicle
AWS
AWS API Gateway
AWS Chalice
AWS Control Tower
AWS IAM
AWS Lambda
AWS VPC
BERT
BigQuery
Causal Inference
ChatGPT
Chrome Extension
CircleCI
Classification
Cloud Functions
Cloud IAM
Cloud Run
Cloud Storage
Clustering
CSS
Data Engineering
Data Modeling
Database
dbt
Decision Tree
Deep Learning
Descriptive Statistics
Differential Equation
Dimensionality Reduction
Discrete Choice Model
Docker
Economics
FastAPI
Firebase
GIS
git
GitHub
GitHub Actions
Google
Google Cloud
Google Search Console
Hugging Face
Hypothesis Testing
Inferential Statistics
Interval Estimation
JavaScript
Jinja
Kedro
Kubernetes
LightGBM
Linux
LLM
Mac
Machine Learning
Macroeconomics
Marketing
Mathematical Model
Meltano
MLflow
MLOps
MySQL
NextJS
NLP
Nodejs
NoSQL
ONNX
OpenAI
Optimization Problem
Optuna
Pandas
Pinecone
PostGIS
PostgreSQL
Probability Distribution
Product
Project
Psychology
Python
PyTorch
QGIS
R
ReactJS
Regression
Rideshare
SEO
Singer
sklearn
Slack
Snowflake
Software Development
SQL
Statistical Model
Statistics
Streamlit
Tabular
Tailwind CSS
TensorFlow
Terraform
Transportation
TypeScript
Urban Planning
Vector Database
Vertex AI
VSCode
XGBoost