Trust Some Points More
Some measurements are more reliable than others: w[i] is the weight of the point (x[i], y[i]). Fit a weighted least squares line and return [intercept, slope].
Example 1
x [0,1,2]
y [0,3,0]
w [1,1,1]
returns [1.0,0.0]
With equal weights this is the ordinary line, flat at height 1.
Example 2
x [0,1,2]
y [0,2,10]
w [10,10,0.1]
returns [-0.05714285714285647,2.1714285714285713]
The last point hardly counts, so the line follows the first two.
Constraints
3 <= len(x) <= 400.1 <= w[i] <= 10- 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
- Uneven SpreadMedium
- Do the Effects CombineHard
- Drop the Weak OnesHard
- Effect of the ProgramHard
- Enough PeopleHard
- Honest ErrorHard
- Next Three ValuesHard
- Slope Through TimeHard