0
0
SciPydata~20 mins

Pearson correlation in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pearson Correlation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Calculate Pearson correlation coefficient
What is the output of this code that calculates the Pearson correlation coefficient between two lists?
SciPy
from scipy.stats import pearsonr
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
result = pearsonr(x, y)
print(round(result[0], 2))
A1.00
B0.00
C-1.00
D0.50
Attempts:
2 left
💡 Hint
Pearson correlation measures linear relationship strength between two variables.
data_output
intermediate
2:00remaining
Number of pairs with strong positive correlation
Given this DataFrame, how many pairs of columns have a Pearson correlation coefficient greater than 0.8?
SciPy
import pandas as pd
import numpy as np
np.random.seed(0)
data = pd.DataFrame({
  'A': np.random.rand(10),
  'B': np.random.rand(10),
  'C': np.linspace(0, 1, 10),
  'D': np.linspace(0, 1, 10) * 2
})
corr_matrix = data.corr()
strong_pairs = (corr_matrix.where(np.triu(np.ones(corr_matrix.shape), k=1).astype(bool)) > 0.8).sum().sum()
print(int(strong_pairs))
A2
B0
C3
D1
Attempts:
2 left
💡 Hint
Check pairs only once and ignore diagonal.
🔧 Debug
advanced
2:00remaining
Identify the error in Pearson correlation calculation
What error does this code raise when trying to calculate Pearson correlation?
SciPy
from scipy.stats import pearsonr
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8]
pearsonr(x, y)
AIndexError: list index out of range
BTypeError: unsupported operand type(s) for -: 'list' and 'list'
CValueError: x and y must have the same length
DNo error, returns correlation
Attempts:
2 left
💡 Hint
Check if both lists have the same number of elements.
🚀 Application
advanced
2:00remaining
Interpret Pearson correlation result
If the Pearson correlation coefficient between two variables is -0.85, what does this mean?
AStrong negative linear relationship
BPerfect positive linear relationship
CNo linear relationship
DStrong positive linear relationship
Attempts:
2 left
💡 Hint
Negative values indicate inverse relationships.
🧠 Conceptual
expert
2:00remaining
Effect of outliers on Pearson correlation
Which statement best describes how outliers affect the Pearson correlation coefficient?
AOutliers always increase the Pearson correlation value
BOutliers can greatly distort the Pearson correlation, making it unreliable
COutliers have little to no effect on Pearson correlation
DOutliers convert Pearson correlation into a non-linear measure
Attempts:
2 left
💡 Hint
Think about how extreme values influence averages and covariance.