Flag the Odd Readings

Machine Learning in CodeMedium+10 XP+10

Flag the Odd Readings

A greenhouse sensor reports [temperature_c, humidity_percent] every hour. Most hours look alike; a faulty hour sits far away from the rest. You want DBSCAN to mark those hours as noise.

Temperature and humidity are in different units, so scale them first.

Task: write odd_hours(readings, eps, min_samples).

  • Scale the columns with StandardScaler().fit_transform(...).
  • Fit DBSCAN(eps=eps, min_samples=min_samples) on the scaled data.
  • Return the row indices of the readings labelled -1, from smallest to largest, as plain ints.

If nothing is noise, return an empty list.

Examples

readings = [[21.0, 40], [21.4, 42], [20.8, 41], [21.2, 39], [21.1, 43], [35.0, 41], [21.3, 40], [20.9, 70], [21.0, 42], [21.5, 41]]
eps = 0.8
min_samples = 3
returns [5, 7]
readings = [[18.2, 55], [18.5, 54], [18.1, 56], [26.0, 30], [26.3, 31], [25.9, 29], [18.4, 55], [26.1, 30], [22.0, 80], [18.3, 57], [26.2, 32]]
eps = 0.6
min_samples = 3
returns [8]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run