I'm trying to solve a linear regression problem and I'm using the LinearRegression()
function from sklearn
. Is it possible to display the weights and bias?
How can I display the weights and bias from LinearRegression()?
Asked Answered
Once you fit
the model use coef_
attribute to retrive weights and intercept_
to get bias term.
See below example:
import numpy as np
from sklearn.linear_model import LinearRegression
a = np.array([[5,8],[12,24],[19,11],[10,15]])
## weights
w = np.array([0.2, 0.5])
## bias
b = 0.1
y = np.matmul(w, a.T) + b
lr = LinearRegression()
lr.fit(a, y)
print(lr.coef_)
# array([0.2, 0.5])
print(lr.intercept_)
# 0.099
For more details refer documentation
© 2022 - 2024 — McMap. All rights reserved.