Calculate and Interpret Correlation
Advanced · Write the code · from SciPy Statistics: Distributions, Hypothesis Tests, and Correlations
From the lesson: SciPy Statistics: Distributions, Hypothesis Tests, and Correlations
A pharmaceutical company develops a new headache medicine. They give it to 100 patients and a placebo to another 100. The treatment group reports slightly fewer headaches. But is that difference real, or just random chance? This is the question statistics answers.
Read the lessonCalculate the Pearson correlation between ad_spend and revenue. Print the correlation coefficient rounded to 3 decimal places. Then print the interpretation: 'Strong positive' if r > 0.7, 'Moderate positive' if r > 0.4, 'Weak positive' if r > 0, 'Negative' if r <= 0.
from scipy import stats
import numpy as np
ad_spend = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
revenue = np.array([15, 28, 38, 52, 55, 68, 72, 89, 95, 110])
# Calculate Pearson correlation
# Print r value (3 decimals)
# Print interpretation
More SciPy Statistics exercises
- Compute Descriptive StatisticsAdvanced
- Work with the Normal DistributionAdvanced
- Run an A/B Test with a T-TestAdvanced
- Test Survey Results with Chi-SquareAdvanced
- Compute a Confidence IntervalAdvanced
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz