Skip to content
DeepForgeby svx
RegressionMedium10 min25 pts

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.

Target
MSE ↓ 8.00
Baseline
84.91
Time
10 min
Points
25

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.

Training split · 28 rows · 2 features. Scored by MSE on 12 held-out rows; target ≤ 8, baseline 84.91.

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.

Timed run

10 min limit

25 points

not started · 10:00

The clock starts when you press start. Your predict(train_X, train_y, test_X) is then scored on 12 held-out rows within 10 minutes.

Starter codePython
def predict(train_X, train_y, test_X):
    # Baseline: predict the mean training target.
    # Replace with a fitted regression, then return one value per test row.
    mean = sum(train_y) / len(train_y)
    return [mean for _ in test_X]
Tab inserts 4 spaces · ⌘+Enter runs your code

Related