有人可以解释一下我是否有因变量,例如结果 (y),定义为
y = K1*F1 + K2*F2 + ... + Kn*Fn + E
每 n 个特征,其中 K - 系数,F - 特征(分类特征和连续特征),E - 误差
那么这是否意味着K1*F1
是每1个特征的结果?
最佳答案
简短回答:
是的,就是这个意思(如果您不考虑 E
)。
长答案: 请参阅下面我刚刚在 Jupyter 上完成的代码。
如您所见,我生成了一些带有一些“噪声”的数据,然后将其与 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_)
关于machine-learning - 线性回归 : Need to clarify the Coef*Feature meaning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35338270/