Linear regression with multi-features

·

1 min read

In the previous blob, I used scikit-learn linear regression for one feature. This time, I tried multi-linear regression, meaning the dataset has multiple variables.

import numpy as np
from sklearn.linear_model import SGDRegressor
x_train = np.array([[1.0, 2.0, 3.0],
                   [4.0, 2.0, 2.0],
                   [5.0, 1.0, 4.0]])   #features
y_train = np.array([300.0, 500.0, 700.0]) 

sgdr.fit(x_train, y_train)
print(sgdr)
b_norm = sgdr.intercept_
w_norm = sgdr.coef_
print(f"model parameters:   w: {w_norm}, b:{b_norm}")

Here is the printed value

model parameters: 
w: [87.03533013  9.0616632  60.34296761], b:[13.81946812]

If you look at the dataset, the first feature has the strongest correlation, and the third one has the second largest correlation. Therefore, w1 is the largest value, and w3 is the second largest.