0
0
SciPydata~10 mins

Spearman correlation 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 to calculate Spearman correlation.

SciPy
from scipy.stats import [1]
Drag options to blanks, or click blank then click option'
Akendalltau
Bspearmanr
Cpearsonr
Dttest_ind
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'pearsonr' instead of 'spearmanr'.
Using unrelated functions like 'ttest_ind'.
2fill in blank
medium

Complete the code to calculate Spearman correlation between two lists x and y.

SciPy
corr, p_value = spearmanr([1], y)
Drag options to blanks, or click blank then click option'
Ax
Brange(10)
C[1, 2, 3]
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'y' twice.
Passing a range instead of the variable.
3fill in blank
hard

Fix the error in the code to correctly calculate Spearman correlation for lists a and b.

SciPy
result = spearmanr(a, [1])
Drag options to blanks, or click blank then click option'
Ab
Bc
Ca
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'a' twice.
Passing an undefined variable like 'c'.
4fill in blank
hard

Fill both blanks to create a dictionary of Spearman correlations for each pair of columns in data.

SciPy
correlations = {col1: {col2: spearmanr(data[col1], data[1])[0] for col2 in data if col1 [2] col2} for col1 in data}
Drag options to blanks, or click blank then click option'
A[col2]
B(col2)
C!= col2
D== col2
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for column access.
Using '==' instead of '!=' in the condition.
5fill in blank
hard

Fill all three blanks to filter pairs with correlation above 0.5 and create a result dictionary.

SciPy
result = [1]: corr for col1, corr in correlations.items() for col2, corr in corr.items() if corr [2] 0.5 and col1 [3] 'target'}
Drag options to blanks, or click blank then click option'
Acol1
B>
C!=
Dcol2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'col1' as the key instead of 'col2'.
Using '<' instead of '>' for filtering.
Using '==' instead of '!=' to exclude 'target'.