Step 1: Create the Noticed Information
Right here’s the survey knowledge collected from the mall:
Step 2: Compute the Anticipated Values
The anticipated worth for every class is calculated as:
For instance, the anticipated variety of males shopping for electronics is:
Step 3: Implement the Chi-Sq. Check in Python
from scipy.stats import chi2_contingency# Noticed frequency desk
knowledge = [[50, 30], # Electronics: Male, Feminine
[20, 40]] # Clothes: Male, Feminine
# Carry out Chi-Sq. check
chi2_stat, p_value, dof, anticipated = chi2_contingency(knowledge)
print(f"Chi-Sq. Statistic: {chi2_stat}")
print(f"p-value: {p_value}")
print(f"Levels of Freedom: {dof}")
print("Anticipated Frequencies:")
print(anticipated)
Step 4: Interpret the Outcomes
- Chi-Sq. Statistic (χ²) = 10.53
- p-value = 0.00117 (lower than 0.05 significance degree)
- Conclusion: For the reason that p-value is small, we reject the null speculation, that means gender does affect buying preferences!
- Market Analysis: Identifies buyer preferences throughout demographics.
- A/B Testing: Determines if a brand new web site format performs higher.
- Healthcare: Checks if a illness is linked to a selected way of life.
- Social Science: Analyzes voting patterns and client conduct.
Chi-Sq. is a strong statistical check that helps to extract insights from categorical knowledge.
You’ll be able to run the code and examine:
Github : https://github.com/kukretinishtha/medium_blog/blob/main/chi_square_test.ipynb
Colab Pocket book Hyperlink:
https://colab.research.google.com/drive/1TMs09fKykjweGxdNDB7u045LhJUr_osh?usp=sharing