Loading...
Implement simple linear regression using the closed-form (least squares) solution.
Given a list of x values and a list of y values, compute the slope m and intercept b of the best-fit line y=mx+b.
The formulas are: m=n∑xi2−(∑xi)2n∑xiyi−∑xi∑yi b=yˉ−mxˉ
where n is the number of data points and xˉ, yˉ are the means.
Return a tuple (slope, intercept), both rounded to 4 decimal places.
X = [1, 2, 3, 4, 5] y = [2, 4, 5, 4, 5]
(0.6, 2.2)