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?
Weighted linear regression is a generalization of linear regression where the covariance matrix of errors is incorporated in the model. Hence, it can be beneficial when we are dealing with a heteroscedastic data. Here, we use the y ...
The linear regression model is expressed as where y is the response variable, x is the ( n +1) × 1 feature vector, w is ( n +1) × 1 vector containing the regression coefficients and e represents the observation error. Note that the first element of the vector x is 1 to represent the interception (or bias):
You can read more about OLS linear regression here, here, or here. A big p art of building the best models in machine learning deals with the bias-variance tradeoff. Bias refers to how correct (or incorrect) the model is. A very simple model that makes a lot of mistakes is said to have high bias.
Currently there is no robust errors option for the Weighted Linear Regression data analysis tool. There is a robust errors option for the Multiple Regression data analysis tool. I am still confused. Figure 3 shows that the independent variables (X) are D4:D12 while the Weights are H4:H12 and are required to be assigned to a separate input box.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With