0
0
SciPydata~20 mins

Goodness of fit evaluation in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Goodness of Fit Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Chi-square test output interpretation

What is the output of the following code that performs a chi-square goodness of fit test?

SciPy
from scipy.stats import chisquare
observed = [20, 30, 50]
expected = [25, 25, 50]
stat, p = chisquare(f_obs=observed, f_exp=expected)
print(round(stat, 2), round(p, 3))
A1.0 0.607
B2.0 0.368
C5.0 0.082
D4.0 0.135
Attempts:
2 left
💡 Hint

Recall the chi-square formula: sum((observed - expected)^2 / expected).

data_output
intermediate
2:00remaining
Kolmogorov-Smirnov test result

Given the following code testing if data fits a normal distribution, what is the output?

SciPy
from scipy.stats import kstest, norm
import numpy as np
data = np.array([1.2, 2.3, 2.9, 3.1, 4.0])
stat, p = kstest(data, 'norm', args=(2.5, 1))
print(round(stat, 3), round(p, 3))
A0.317 0.123
B0.500 0.050
C0.317 0.876
D0.200 0.900
Attempts:
2 left
💡 Hint

Remember the KS test compares empirical and theoretical CDFs.

🔧 Debug
advanced
2:00remaining
Identify the error in chi-square test code

What error does the following code produce?

SciPy
from scipy.stats import chisquare
observed = [10, 20, 30]
expected = [15, 15]
stat, p = chisquare(f_obs=observed, f_exp=expected)
print(stat, p)
ANo error, outputs statistic and p-value
BIndexError: list index out of range
CValueError: operands could not be broadcast together
DTypeError: unsupported operand type(s)
Attempts:
2 left
💡 Hint

Check if observed and expected lists have the same length.

🚀 Application
advanced
2:00remaining
Choosing the right goodness of fit test

You have a dataset of 1000 values and want to check if it follows a uniform distribution. Which scipy test is most appropriate?

Ascipy.stats.kstest with 'uniform' distribution
Bscipy.stats.chisquare with observed frequencies and expected uniform frequencies
Cscipy.stats.ttest_1samp comparing data mean to uniform mean
Dscipy.stats.pearsonr between data and uniform samples
Attempts:
2 left
💡 Hint

Think about tests that compare sample distribution to a continuous theoretical distribution.

🧠 Conceptual
expert
2:00remaining
Interpreting p-values in goodness of fit tests

Which statement best describes the meaning of a p-value of 0.03 in a goodness of fit test?

AThere is a 3% chance the observed data fits the model perfectly
BThere is a 3% probability that the observed data would occur if the model is true
CThere is a 3% chance the null hypothesis is true
DThere is a 3% chance of observing data as extreme as this if the null hypothesis is true
Attempts:
2 left
💡 Hint

Recall the definition of p-value in hypothesis testing.