KNN regression on 391 real cars. To predict the selected car's mpg, find the K closest cars in (horsepower, weight) and average their mpg.
Raw units:
Weight spans thousands of lbs and horsepower spans tens, so the weight gap dominates every distance and raw distance behaves like a weight-only model.
Normalized: rescale each variable to \(z = (x - \bar{x})/s\) first, so both count in standard deviations.
Everything inside the boundary lies closer to the selected car than the K-th neighbor. In raw units a large horsepower gap barely changes the distance, so the region is a flat slab. Normalized, it is round.
Select the 48-hp VW Dasher diesel. Raw distance matches it with 75–85 hp gasoline compacts (25.8 mpg predicted); normalized distance finds the other Volkswagens (37.1). Its actual economy: 43.4 mpg.
A grid search fits every candidate K and selects the one with the smallest held-out RMSE. Both curves are U-shaped.
The star marks the smallest RMSE. The diamond marks the elbow, where the curve stops improving quickly: the point farthest from the straight line joining the curve's ends. Analysts who value simplicity stop at the elbow; the grid search selects the minimum.
Small K overfits: the predictions track noise in individual cars (high variance). Large K includes neighbors far from the query, so the average drifts toward the overall mean (high bias). At K = 390 every prediction is the same number.
\(\hat{y}_{(-i)}\) is car \(i\)'s prediction from the other 390 cars. If a car's own row helped predict it, the error would shrink toward zero and K = 1 would look nearly perfect.
The L05 boardsheet runs the same search with 5-fold cross-validation inside a 300-car training set, saving a 91-car test set for the final grade. The logic is identical; only the split differs.