0
0
Data Analysis Pythondata~20 mins

Correlation analysis (Pearson, Spearman) in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Correlation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Pearson correlation calculation
What is the output of this Python code calculating Pearson correlation between two lists?
Data Analysis Python
import numpy as np
from scipy.stats import pearsonr
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
correlation, p_value = pearsonr(x, y)
print(round(correlation, 2))
A0.50
B0.80
C1.00
D-1.00
Attempts:
2 left
💡 Hint
Pearson correlation measures linear relationship strength.
data_output
intermediate
2:00remaining
Spearman correlation output for rank data
Given these two lists, what is the Spearman correlation coefficient output?
Data Analysis Python
from scipy.stats import spearmanr
x = [10, 20, 30, 40, 50]
y = [2, 1, 3, 5, 4]
correlation, _ = spearmanr(x, y)
print(round(correlation, 2))
A0.70
B0.60
C0.90
D0.80
Attempts:
2 left
💡 Hint
Spearman correlation measures monotonic relationship using ranks.
🧠 Conceptual
advanced
2:00remaining
Difference between Pearson and Spearman correlation
Which statement correctly describes the difference between Pearson and Spearman correlation?
APearson measures monotonic relationships; Spearman measures linear relationships.
BPearson measures linear relationships; Spearman measures monotonic relationships using ranks.
CBoth measure only linear relationships but use different formulas.
DSpearman correlation is only used for categorical data.
Attempts:
2 left
💡 Hint
Think about how each correlation handles data ordering and linearity.
🔧 Debug
advanced
2:00remaining
Identify the error in correlation calculation code
What error will this code raise when calculating Pearson correlation?
Data Analysis Python
from scipy.stats import pearsonr
x = [1, 2, 3]
y = [4, 5]
correlation, p = pearsonr(x, y)
AValueError: x and y must have the same length
BTypeError: unsupported operand type(s)
CIndexError: list index out of range
DNo error, code runs successfully
Attempts:
2 left
💡 Hint
Check if the input lists have the same number of elements.
🚀 Application
expert
2:00remaining
Choosing correlation method for non-linear but monotonic data
You have two variables with a clear monotonic but non-linear relationship. Which correlation method should you use to best capture their association?
ASpearman correlation
BPearson correlation
CBoth Pearson and Spearman will give the same result
DNeither Pearson nor Spearman is suitable
Attempts:
2 left
💡 Hint
Consider which method uses ranks and can detect monotonic relationships.