Issue
Is it possible to build a LinearRegression in sklearn by passing in the intercept and coefficents instead of using .fit
?
Solution
As Suggested by Mustafa Aydin in its comment, you can simply assign coefficient and intercept to scikit-learn LinearRegression.
The following snippet is modeling the function y = 10 + x*5
.
from sklearn.linear_model import LinearRegression
import numpy as np
l = LinearRegression()
l.coef_ = np.array([5])
l.intercept_ = np.array([10])
l.predict([[3]])
NOTES: If you are not using scikit-learn to fit your linear regression, you can simply use numpy, which might be more performant.
Answered By - Antoine Dubuis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.