FunctionRacerProblemsRace

Trust Some Points More

MediumstatsmodelsPython

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

Race itor take your time

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

More statsmodels problems