Fit a straight line y=slope⋅x+intercept to paired data by ordinary least squares. x and y must have the same length.
Implement solve(x,y).
Returns. Return a tuple (slope, intercept) of floats. A different length raises ValueError. If all x values are equal the slope is undefined.
Example 1
Input:
solve([1.0, 2.0, 3.0], [2.0, 4.0, 5.0])
Output:
(1.5, 0.666667)
Example 2
Input:
solve([0.0, 1.0, 2.0, 3.0], [1.0, 3.0, 5.0, 7.0])
Output:
(2.0, 1.0)
No results yet
Run your code to check it against the examples, or submit to run every test.