【发布时间】:2021-11-20 07:01:57
【问题描述】:
我需要在我的数据框的两个变量组中计算线性回归和 MSE。问题是我无法将 xtrain 与两个变量与 ytrain 与一个变量进行比较,但我的 ytrain 中只有一列。
代码:
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=100, n_features=4, n_informative=3, n_targets=1, noise=0.01)
问题:
from itertools import combinations
for c in combinations(range(4), 2):
lr=LinearRegression()
lr.fit(Xtrain[:,c].reshape(-1,1),ytrain)
yp=lr.predict(Xtest[:,c].reshape(-1,1))
print('MSE', np.sum((ytest - yp)**2) / len(ytest))
错误:
【问题讨论】:
标签: python scikit-learn linear-regression