FunctionRacerProblemsRace

Pattern in the Leftovers

MediumstatsmodelsPython

The points (x[i], y[i]) are in time order. Fit an ordinary least squares line and return the Durbin-Watson statistic of its residuals: about 2 when neighbors in time are unrelated, toward 0 when each residual resembles the one before it, toward 4 when they alternate.

Example 1

x [1,2,3,4,5,6]
y [1,3,2,4,3,5]
returns 3.547619047619047

The residuals flip sign at every step, which pushes the statistic toward 4.

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