java能使用sklearn吗,使用sklearn进行多元线性回归

我开始研究 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 -

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 1 和 Feature 2 之间做一个像点积的东西来获得一些 [[number],[number],[number]]

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

不知道我哪里错了 .

非常感谢您的帮助 :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值