Let’s check how to perform Chi-Squared test using SciPy Python library.
Chi-square calculations
We will see how to calculate chi-squared test based on given numbers set. We will calculate ch-squared test using with scipy library because it offers built-in chisquare function which will do the job.
Chisquare returns pvalue. We can set 5.0% value level to determine if observed deviations are significant.
from scipy import stats numbers = [45, 67, 33, 54, 33] chi = stats.chisquare(numbers) print(f"pvalue equals {round(chi.pvalue, 4)}") if chi.pvalue < 0.05: print("Hypothesis can be rejected") else: print("Hypothesis is valid")