0
0
SciPydata~30 mins

Goodness of fit evaluation in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Goodness of Fit Evaluation with SciPy
📖 Scenario: You are a data analyst working with a small dataset of observed counts from a survey. You want to check if these observed counts fit a theoretical expected distribution using a goodness of fit test.
🎯 Goal: Build a Python program that uses SciPy to perform a chi-square goodness of fit test comparing observed data to expected data.
📋 What You'll Learn
Create a list called observed_counts with exact values [18, 22, 20, 15, 25]
Create a list called expected_counts with exact values [20, 20, 20, 20, 20]
Use scipy.stats.chisquare to perform the goodness of fit test
Print the chi-square statistic and p-value with clear labels
💡 Why This Matters
🌍 Real World
Goodness of fit tests are used in surveys, quality control, and scientific experiments to check if data matches expected patterns.
💼 Career
Data analysts and scientists use these tests to validate models and assumptions about data distributions.
Progress0 / 4 steps
1
Create observed data list
Create a list called observed_counts with these exact values: [18, 22, 20, 15, 25].
SciPy
Need a hint?

Use square brackets to create a list and separate numbers with commas.

2
Create expected data list
Create a list called expected_counts with these exact values: [20, 20, 20, 20, 20].
SciPy
Need a hint?

Use the same list syntax as before to create the expected counts list.

3
Perform chi-square goodness of fit test
Import chisquare from scipy.stats and use it to perform a chi-square test comparing observed_counts and expected_counts. Store the result in a variable called chi2_result.
SciPy
Need a hint?

Use chisquare(f_obs=observed_counts, f_exp=expected_counts) to run the test.

4
Print chi-square statistic and p-value
Print the chi-square statistic and p-value from chi2_result with labels: Chi-square statistic: and p-value:.
SciPy
Need a hint?

Use print(f"Chi-square statistic: {chi2_result.statistic}") and similarly for p-value.