FunctionRacerProblemsRace

Smallest Total Miss

HardSciPyPython

A line y = m * x + c misses the point (xs[i], ys[i]) by abs(ys[i] - m * xs[i] - c). Return the smallest total miss any line can have over all the points. This is the fit that outliers cannot drag around, unlike least squares. Answers within 0.01% are accepted.

Example 1

xs [0,1,2]
ys [0,1,2]
returns 0.0

The points are on one line.

Example 2

xs [0,1,2,3]
ys [0,1,2,30]
returns 27.0

The line through the first three points misses only the last one, by 27. Bending toward it would cost more.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More SciPy problems