Chi-squared Test for Independence
📖 Scenario: You work in a small shop and want to check if the type of product customers buy depends on their age group. You collected data on how many customers in each age group bought each product type.
🎯 Goal: You will create a table of observed counts, set up the test, run the chi-squared test for independence, and print the test results to see if product choice depends on age group.
📋 What You'll Learn
Create a 2D list called
observed with exact counts for each age group and product typeCreate a variable called
alpha and set it to 0.05 for the significance levelUse
scipy.stats.chi2_contingency on observed to get the test resultsPrint the chi-squared statistic, p-value, degrees of freedom, and expected frequencies
💡 Why This Matters
🌍 Real World
Chi-squared tests help businesses understand if two categories, like age group and product choice, are related or independent.
💼 Career
Data analysts and scientists use chi-squared tests to analyze survey data, customer behavior, and other categorical data to make informed decisions.
Progress0 / 4 steps