Robust Sensor Calibration
Two sensor readings predict a target, but a few training rows are corrupted by outliers. Lower is better: the training-mean baseline scores an MSE of 84.91.
Lower is better. Scored on 12 held-out rows.
Dataset
x: feature 1 · y: feature 2
Each dot is one training row: feature 1 against feature 2, coloured by class.
What this lab teaches
Fit both sensor readings with least squares, then find and drop the corrupted rows that pull the fit off the clean relation.
The clean relation plus outliers
There are 28 training rows with two sensor readings and 12 hidden rows. Predicting the training mean scores MSE 84.91 on the hidden rows - the recorded baseline - and the target is 8. A plain least-squares fit over all 28 rows gives roughly 11.95 + 1.85*s1 + 1.48*s2 and already reaches MSE 4.44, which shows the relation is mostly linear.
Three rows break the slope
Rows 3, 11, and 22 sit 10 to 13 units above the fitted surface - far beyond the remaining noise. Refitting on the other 25 rows moves the coefficients to about 7.67 + 2.50*s1 + 1.54*s2 and drops hidden MSE to roughly 0.30, an order of magnitude better than the plain fit.
Residual screening as a rule
Compute residuals on the training rows, drop the rows whose absolute residual exceeds a threshold a few times the median, and refit. A cutoff near 2 to 3 times the residual spread removes the three corrupted rows without touching anything else; removing more than about 15% of rows starts to bias the slope.
Common pitfalls
- Letting the outliers set the slope and reporting the training MSE. Three bad rows out of 28 are enough to bend a two-feature fit, and the damage only shows on held-out rows.
- Dropping rows by feature magnitude instead of residual size. The corruption lives in the label, not in the sensor readings, so a feature-based filter removes good rows and keeps bad ones.
- Refitting after removing too many rows. Tightening the cutoff until most rows are gone makes the surface follow the remaining noise rather than the clean relation.
Rules of the run
- Define predict(train_X, train_y, test_X) and return exactly one value per test row.
- Pure Python or numpy both run; no external data or network access.
- Return a numeric prediction for every test row.
Hint
Start with ordinary least squares on both sensors. If the outliers pull the fit, drop the largest-residual rows and refit.
Reference solution
Revealing doesn't affect your record — but try the hint first.