Which code correctly computes the Pearson correlation and interprets a strong positive relationship?
hard📝 Application Q15 of 15
SciPy - Statistical Tests
You have two variables: temperature (in Celsius) and ice cream sales. You want to check if higher temperature relates to higher sales. Which code correctly computes the Pearson correlation and interprets a strong positive relationship?
Afrom scipy.stats import pearsonr
corr, p = pearsonr(temp, sales)
if p > 0.7:
print('Strong positive correlation')
Bfrom scipy.stats import pearsonr
corr, p = pearsonr(temp, sales)
if corr > 0.7:
print('Strong positive correlation')
Cfrom scipy.stats import pearsonr
corr, p = pearsonr(temp, sales)
if corr < -0.7:
print('Strong positive correlation')
Dfrom scipy.stats import pearsonr
corr, p = pearsonr(temp, sales)
if abs(corr) < 0.3:
print('Strong positive correlation')
Step-by-Step Solution
Solution:
Step 1: Calculate Pearson correlation
Use pearsonr to get correlation coefficient and p-value between temperature and sales.
Step 2: Interpret correlation coefficient
A strong positive correlation means corr > 0.7. Checking p-value > 0.7 or negative corr is incorrect.
Final Answer:
from scipy.stats import pearsonr
corr, p = pearsonr(temp, sales)
if corr > 0.7:
print('Strong positive correlation') -> Option B
Quick Check:
Strong positive correlation if corr > 0.7 [OK]
Quick Trick:Check corr > 0.7 for strong positive relation [OK]
Common Mistakes:
MISTAKES
Using p-value instead of correlation coefficient
Checking for negative correlation for positive relation
Using absolute value less than threshold incorrectly
Master "Statistical Tests" in SciPy
9 interactive learning modes - each teaches the same concept differently