iTranslated by AI
[Statistics] Mean and Variance of the Beta Distribution
Since I covered the Beta distribution in my articles on Bayesian estimation for Bernoulli and binomial distributions, I will also describe the Beta distribution here.
Probability Density Function
Expectation and Variance
Properties of the Beta Function
To calculate the expected value, it is efficient to use the properties of the Beta function. The Beta function has the following property:
The proof is as follows.
First, perform the calculation as follows:
Using this, the left-hand side of equation (2) can be transformed as follows:
Simplify the derived equation (4):
Expectation
Using equation (2), derive the expected value.
Variance
Similar to the expected value, calculate the second moment using equation (2).
From the above,
Visualization
Let's check the probability density function of the Beta distribution. First, we vary the values of

Next, we visualize how the distribution changes as we increase the absolute values of


Code
There are three plots, but since the differences are only in the variable a_b and ax.legend([...]), only the code for the first one is provided here.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import beta
a_b = [
[9,1],
[8,2],
[7,3],
[6,4],
[5,5],
[4,6],
[3,7],
[2,8],
[1,9],
]
# data
x = np.arange(0, 1, 0.001)
ys = []
for ab in a_b:
y = [beta.pdf(x_i, ab[0], ab[1])for x_i in x]
ys.append(y)
sns.set()
sns.set_style("whitegrid", {'grid.linestyle': '--'})
sns.set_context("talk", 0.8, {"lines.linewidth": 2})
sns.set_palette("cool", 9, 0.9)
fig=plt.figure(figsize=(16,9))
ax1 = fig.add_subplot(1, 1, 1)
ax1.set_title('Beta Distribution')
ax1.set_xlabel('mu')
ax1.set_ylabel('probability density')
for ys_i in ys:
ax1.plot(x,ys_i)
ax1.legend([
'a=9, b=1',
'a=8, b=2',
'a=7, b=3',
'a=6, b=4',
'a=5, b=5',
'a=4, b=6',
'a=3, b=7',
'a=2, b=8',
'a=1, b=9',
])
plt.show()
References
(1) C.M. Bishop. "Pattern Recognition and Machine Learning, Vol. 1". 2019. Maruzen Publishing.
(2) Atsushi Suyama. "Machine Learning Startup Series: Introduction to Machine Learning through Bayesian Inference". 2018. Kodansha Scientific.
Discussion