0
0
SciPydata~10 mins

Goodness of fit evaluation in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function used for goodness of fit test from scipy.stats.

SciPy
from scipy.stats import [1]
Drag options to blanks, or click blank then click option'
Attest_ind
Bpearsonr
Cchisquare
Dlinregress
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a test for means like ttest_ind instead of chisquare.
Confusing correlation tests with goodness of fit tests.
2fill in blank
medium

Complete the code to perform a chi-square goodness of fit test on observed data.

SciPy
observed = [20, 30, 50]
expected = [25, 25, 50]
stat, p_value = chisquare(f_obs=[1], f_exp=expected)
Drag options to blanks, or click blank then click option'
Aobserved
Bexpected
C[25, 25, 50]
D[20, 30, 50]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping observed and expected data in the function call.
Passing the expected list to f_obs.
3fill in blank
hard

Fix the error in the code to correctly calculate the chi-square test statistic and p-value.

SciPy
from scipy.stats import chisquare
observed = [15, 25, 60]
expected = [20, 20, 60]
stat, p_value = chisquare(f_obs=observed, f_exp=[1])
Drag options to blanks, or click blank then click option'
Aobserved
Bexpected
C[15, 25, 60]
D[20, 25, 60]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing observed data as expected frequencies.
Using incorrect lists for expected frequencies.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each category to its observed frequency only if the frequency is greater than 20.

SciPy
categories = ['A', 'B', 'C', 'D']
observed = [10, 25, 30, 15]
result = {categories[i]: [1] for i in range(len(categories)) if [2]
Drag options to blanks, or click blank then click option'
Aobserved[i]
Bcategories[i]
Cobserved[i] > 20
Dcategories[i] > 20
Attempts:
3 left
💡 Hint
Common Mistakes
Using category names as values instead of frequencies.
Filtering by category names instead of frequencies.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase category names to observed frequencies only if the frequency is less than or equal to 25.

SciPy
categories = ['a', 'b', 'c', 'd']
observed = [10, 25, 30, 15]
result = { [1]: [2] for i in range(len(categories)) if [3] }
Drag options to blanks, or click blank then click option'
Acategories[i].upper()
Bobserved[i]
Cobserved[i] <= 25
Dcategories[i]
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting category names to uppercase.
Using wrong comparison operators in the condition.
Mixing up keys and values in the dictionary comprehension.