What the Line Misses
Fit an ordinary least squares line to the points (x[i], y[i]) and return the residuals: for each point, its y minus the height of the line there.
Example 1
x [0,1,2]
y [0,3,0]
returns [-1.0,2.0,-1.0]
The best line is flat at height 1, so the points miss it by -1, 2 and -1.
Constraints
3 <= len(x) <= 40- 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 statsmodels problems
- Echo of YesterdayEasy
- Fair R SquaredEasy
- Group GapsEasy
- Is the Share DifferentEasy
- Is the Slope RealEasy
- Prices for New RowsEasy
- Range for the SlopeEasy
- Two CausesEasy