Smallest Total Miss
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
3 <= len(xs) <= 30- The xs are not all equal
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More SciPy problems
- Volume Over a TriangleHard
- Area Under the PointsBeginner
- Chance of at MostBeginner
- City Block DistanceBeginner
- Percent at or BelowBeginner
- Standard ErrorBeginner
- Standard ScoresBeginner
- The ModeBeginner