Fit a line through 0, y = slope * x, as in “Through the cloud”, but from only a few noisy points. Write careful_slope(xs, ys, caution): a slope that doesn’t trust thin evidence. caution ≥ 0 says how much you distrust a slope built on little evidence; 0 means no caution at all.
Two points near 0 fit a line exactly, but measure them again with a little noise and the line swings wildly; two far-out points with the same noise barely move. The plain best slope trusts thin evidence too much. Your function builds in doubt, as much as the caution says.
careful_slope(xs, ys, caution)| xs | the points, point i is (xs[i], ys[i]) | e.g. [1, 2, 3] |
| ys | the points, point i is (xs[i], ys[i]) | e.g. [2, 5, 5] |
| caution | caution >= 0: how much to distrust a slope built on little evidence | e.g. 0 |
| returns | the slope of the line y = slope * x | |