Correlation Is Not Cause
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 33 of 64.
r only sees straight lines. Here y is fully decided by x, yet r is 0:
The falling half cancels the rising half. An r near 0 means no straight line, not no relationship: plot before you drop a feature.
And one far point can fake a strong r, so check outliers first:
Finally, r never proves a cause. Older children have bigger shoes and read better: age, a hidden third variable, drives both.
Challenge
MediumA tea shop tests its cups: steep and taste for 9 cups (steeping minutes, score), sugar and score for 10 others (sugar cubes, score). The program reads one extra cup's sugar, then score.
- Print the
rof steep and taste. - Print the
rof sugar and score, then with the extra cup added.
Round to 2 decimals, labelled as below. For another shop and extra cup 10, 2.0:
Steeping r: -0.05
Sugar r: -0.23
Sugar r with the extra cup: -0.88Try it yourself
import numpy as np
# Steeping time in minutes and taste score of 9 cups
steep = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
taste = np.array([3.1, 5.0, 6.6, 7.7, 8.1, 7.6, 6.5, 5.1, 3.4])
# Sugar cubes and taste score of 10 other cups
sugar = np.array([0, 2, 1, 3, 0, 2, 1, 3, 2, 1])
score = np.array([6.5, 5.8, 7.4, 6.1, 5.9, 7.0, 6.2, 6.8, 6.4, 5.7])
# The extra cup
extra_sugar = float(input())
extra_score = float(input())
# Write your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Statistics for ML
1Center and Spread
Mean and MedianPercentiles and QuartilesVariance and StdSample or Population?The Most Common ValueRecap: Delivery Times4Samples and Populations
Population and SampleSample Means VaryThe Sampling DistributionBigger Samples, Less NoiseRecap: Polling a Town2Distributions
Density HistogramsShapes of DataThe Normal CurveThe 68-95-99.7 RuleZ-ScoresRecap: Battery Life3Probability by Simulation
Probability as FrequencyThe Law of Large NumbersSums of DiceExpected ValueConditional ProbabilityRecap: Dice Stall Odds6Relationships
Reading Scatter PlotsCorrelationCorrelation MatrixCorrelation HeatmapsCorrelation Is Not CauseRecap: Ice Cream and SunPractice on your own: Online Python compiler