Challenge - 5 Problems
Spearman Correlation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Spearman correlation output for simple arrays
What is the output of the following code that calculates Spearman correlation between two arrays?
SciPy
from scipy.stats import spearmanr x = [1, 2, 3, 4, 5] y = [5, 6, 7, 8, 7] correlation, pvalue = spearmanr(x, y) print(round(correlation, 2))
Attempts:
2 left
💡 Hint
Spearman correlation measures monotonic relationship, not linear.
✗ Incorrect
The Spearman correlation here is about 0.9, showing a strong positive monotonic relationship.
❓ data_output
intermediate2:00remaining
Spearman correlation matrix from DataFrame columns
Given a DataFrame with columns A, B, and C, what is the Spearman correlation matrix output?
SciPy
import pandas as pd from scipy.stats import spearmanr data = {'A': [1, 2, 3, 4], 'B': [4, 3, 2, 1], 'C': [1, 3, 2, 4]} df = pd.DataFrame(data) correlation, _ = spearmanr(df) print(correlation)
Attempts:
2 left
💡 Hint
Spearman correlation matrix is symmetric with 1s on diagonal.
✗ Incorrect
Column A and B are perfectly negatively correlated (-1), A and C have 0.8 positive correlation.
🔧 Debug
advanced2:00remaining
Identify the error in Spearman correlation code
What error does this code raise when trying to calculate Spearman correlation?
SciPy
from scipy.stats import spearmanr x = [1, 2, 3] y = [4, 5] spearmanr(x, y)
Attempts:
2 left
💡 Hint
Check if input arrays have the same length.
✗ Incorrect
Spearman correlation requires inputs of equal length; otherwise, ValueError is raised.
🧠 Conceptual
advanced2:00remaining
Understanding Spearman correlation properties
Which statement about Spearman correlation is TRUE?
Attempts:
2 left
💡 Hint
Think about how Spearman correlation handles data values.
✗ Incorrect
Spearman correlation uses ranks to measure monotonic relationships, not just linear.
🚀 Application
expert2:00remaining
Interpreting Spearman correlation p-value
You calculate Spearman correlation between two variables and get correlation=0.6 and p-value=0.07. What is the correct interpretation?
Attempts:
2 left
💡 Hint
Check both correlation strength and p-value significance.
✗ Incorrect
Correlation 0.6 is moderate positive, but p-value 0.07 is above 0.05 threshold, so not significant.