You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SciKit Learn provides a linear regression class that follows the standard scikit-learn API, so we just need to call lr = LinearRegression() and then lr.fit(X, y) to fit the model.
Linear regression from scratch
An exact way of performing linear regression would be minimising the squared error, which is the sum of the squared distances between the model and the data.
To get an approximate result, we can compute the line of best fit, being the ratio between covariance and variance of the data:
where $t$ is the value that we can get from the t-Student distribution with $n-1$ degrees of freedom.
Notice that we usually use the critical value when dealing with approximately normal distributions. This is, for 90% confidence $1.64$, for 95% confidence $1.96$, for 99% confidence $2.58$ and for 99.9% confidence $3.29$.