线性回归:需要明确Coef*Feature的含义

Linear Regression: Need to clarify the Coef*Feature meaning

谁能解释一下我是否有因变量,例如结果 (y),由

定义
y = K1*F1 + K2*F2 + ... + Kn*Fn + E

每 n 个特征,其中 K - 系数,F - 特征(分类特征和连续特征),E - 误差

那么这是否意味着 K1*F1 是每 1 个特征的结果?

简答: 是的,就是这个意思(如果你不考虑E)。

长答案: 请参阅下面我刚刚在 Jupyter 上执行的代码。

如您所见,我用 "noise" 生成了一些数据,然后用 sklearn.linear_model.LinearRegression 对其进行了拟合。然后我得到我的系数(+截距),你会看到回归实际上是 x.coeff+截距,如果我是对的,这就是你的 K1*F1

from sklearn.linear_model import LinearRegression
import numpy as np
from matplotlib import pyplot as plt

noise = 2

lr = LinearRegression()
x, y = [], []
i=0
while i<10:
    for j in range(np.random.randint(1,5)):
        x.append(i)
        y.append(i+np.random.rand()*noise+(noise/2))
    i+=np.random.rand()

%matplotlib inline
plt.scatter(x, y)

x = np.asarray(x).reshape(-1, 1)
y = np.asarray(y).reshape(-1)

lr.fit(x,y)
plt.plot(x, np.multiply(x, lr.coef_[0])+lr.intercept_)