我开始研究 sklearn 并一直在尝试实现多线性回归 . 我提到了example并尝试用我的数据框实现相同的方式 - 但最终得到了

Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample

这是我的代码

# content - pandas object
# content - <class 'pandas.core.frame.DataFrame'>
x = content[['Feature 1', 'Feature 3']].values.reshape(-1,2)
y = content['Feature 2']
# 70 / 30 split
x_train, x_test, y_train, y_test = cross_validation.train_test_split(x, y, test_size=0.3)model = LinearRegression()
model.fit(x_train, y_train)
y_predict = model.predict(x_test)
accuracy_score = model.score(y_test, y_predict)
return x_test, y_test, model.coef_, model.intercept_, y_predict, accuracy_score, x_train, y_train

我将 reshape(-1,1) 添加到 y = content['Feature 2'] ,我最终得到一个陈述 ValueError: shapes (3,1) and (2,1) not aligned: 1 (dim 1) != 2 (dim 0) 的问题 . 我很确定我犯了一个微不足道的错误 - 只是无法弄清楚在哪里 .

数据基本上是一组功能和类 Feature 1, Feature 2, Feature 3, Feature 4... Class . 每个功能并不是很重要 . 虽然它只是一个具有一组特征和类的虚拟数据集 .

而我想要做的是 - 在 x = [Feature 1, Feature 2]y = [Feature 3] 之间应用多线性回归

不确定我是否应该在 Feature 1Feature 2 之间做一个像点积的东西来获得一些 [[number],[number],[number]]

当我删除 .value.shape(-1,2) 时,我得到 ValueError: shapes (1,1) and (2,1) not aligned: 1 (dim 1) != 2 (dim 0)

不知道我哪里错了 .

非常感谢您的帮助 :)