Air Quality
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 62 of 64.
A city wants a quick forecast of fine dust, PM2.5. Its street sensor logged 40 days in air.csv:
Each row holds a day's wind, temperature, humidity, traffic and pm25. One of them tracks the dust far better than the rest.
Find it, fit a line, and say how far to trust it: how much it explains, where it misses most, and when a forecast leaves the data behind.
Challenge
HardThe program reads a new day's value of the best feature. Round to 2 decimals.
- Print the feature with the strongest r with
pm25, sign ignored, and its signed r. - Fit a line. Print it, its R squared, and the row it misses most with that residual.
- Predict for the value, and warn when it lies outside the feature's data.
- Draw dots and the red line from the smallest value to the largest: title
Air Quality, the feature across,PM2.5up.
For another city and the input 8:
Best feature: traffic_k (r = 0.86)
Line: pm25 = 1.11 * traffic_k + 13.67
R squared: 0.73
Largest miss: row 14 (residual 11.15)
Prediction at 8.0: 22.57
Warning: outside the dataAfter your lines, Coddy describes your chart.
Try it yourself
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
value = float(input())
df = pd.read_csv("air.csv")
# 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