Bird
0
0

Identify the error in this code snippet for performing a chi-square goodness of fit test:

medium📝 Debug Q14 of 15
SciPy - Curve Fitting and Regression
Identify the error in this code snippet for performing a chi-square goodness of fit test:
from scipy.stats import chisquare
observed = [15, 25, 35]
expected = [20, 20]
result = chisquare(f_obs=observed, f_exp=expected)
print(result)
AObserved and expected arrays have different lengths
Bchisquare function is not imported correctly
CExpected frequencies must be integers
DMissing p-value extraction from result
Step-by-Step Solution
Solution:
  1. Step 1: Check input array lengths

    The observed array has 3 elements, but expected has only 2 elements, which is invalid for chi-square test.
  2. Step 2: Understand scipy requirement

    Both observed and expected arrays must be the same length to compare frequencies correctly.
  3. Final Answer:

    Observed and expected arrays have different lengths -> Option A
  4. Quick Check:

    Array length mismatch causes error [OK]
Quick Trick: Observed and expected must be same length [OK]
Common Mistakes:
  • Ignoring length mismatch
  • Assuming expected must be integers
  • Thinking import or print is the error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes