Chi-Square Distribution
The Chi-Square distribution is commonly used in statistics, particularly for hypothesis testing.
It has two key parameters:
- df — Degrees of freedom (this controls the shape of the distribution).
- size — The shape or dimensions of the output array.
Program:
Generate a random sample from a Chi-Square distribution with 2 degrees of freedom and a shape of 2x3:
from numpy import random
x = random.chisquare(df=2, size=(2, 3))
print(x)
Output:
[[0.98342076 0.15330841 1.49937139]
[2.50436604 0.07464287 1.22988812]]
Visualizing the Chi-Square Distribution
Here’s how you can visualize the Chi-Square distribution using Seaborn and Matplotlib:
Program:
from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns
# Generate sample data with 1 degree of freedom
data = random.chisquare(df=1, size=1000)
# Plot the distribution using KDE (Kernel Density Estimation)
sns.displot(data, kind="kde")
plt.show()