0
0
SciPydata~10 mins

Chi-squared test 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 chi2_contingency function from scipy.stats.

SciPy
from scipy.stats import [1]
Drag options to blanks, or click blank then click option'
Achi2_contingency
Bchi_square
Ccontingency_test
Dchi2_test
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like chi_square or chi2_test.
Trying to import from the wrong module.
2fill in blank
medium

Complete the code to create a 2x2 contingency table using a list of lists.

SciPy
table = [[20, 15], [[1], 30]]
Drag options to blanks, or click blank then click option'
A10
B35
C40
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number that makes the table invalid or unbalanced.
Using a non-integer value.
3fill in blank
hard

Fix the error in the code to perform the chi-squared test on the table.

SciPy
chi2, p, dof, expected = [1](table)
Drag options to blanks, or click blank then click option'
Achi_square
Bchi2_contingency
Ccontingency_chi2
Dchi_test
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that does not exist in scipy.stats.
Misspelling the function name.
4fill in blank
hard

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

SciPy
result = {category: expected.flatten()[[1]] for [2], category in enumerate(['A', 'B', 'C', 'D']) if expected.flatten()[[1]] > 20}
Drag options to blanks, or click blank then click option'
Ai
Bcategory
Cj
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using the category name as an index.
Using different variables for the two blanks.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each category name in uppercase to its expected count if the count is less than 25.

SciPy
filtered = {category[1](): expected.flatten()[[2]] for [3], category in enumerate(['A', 'B', 'C', 'D']) if expected.flatten()[[2]] < 25}
Drag options to blanks, or click blank then click option'
A.upper
Bi
Cindex
D.lower
Attempts:
3 left
💡 Hint
Common Mistakes
Using .lower() instead of .upper().
Using different variables for the index in the comprehension.