Issue
Fit training data $x = [0,1,3], y=[0,1,2.5]$ using simple linear model, $y = \alpha x + \beta$, we get $\alpha = 0.82142857$ and $\beta = 0.0714285$ using formula provided here: https://en.wikipedia.org/wiki/Simple_linear_regression
Using sklean, I wanted to verify that the linear model give the same model params as above,
reg = LinearRegression()
X = [[0], [1], [3]]
Y = [0, 1, 2.5]
y_intercept = reg.predict([[0]])
print(y_intercept)
print(reg.coef_)
But I found that reg.coef_
only give 0.82142857, and the $\beta=y_intercept=0.07142857$ is not included in the reg.coef_
. Can anyone explain why this is the case? And how can I get parameter the $\beta$ without using reg.predict([[0,0,..,.0]])?
Solution
reg.coef_
will only return the coefficient of the model (slope of the line).
You can use reg.intercept_
to get the intercept value.
Answered By - Mattravel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.