Expected 2D array, got 1D array instead:Reshape your data either using array.reshape(-1, 1) if your

在新版 sklearn 中,所有输入数据必须为二维。遇到`Expected2Darray,got1Darray instead`错误时,需使用`reshape`方法调整数据形状。正确做法是将一维数据重塑为(-1, 1)或(1, -1)。修正后的代码为`model.fit(x_train.reshape(-1,1), y_train)`。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Expected 2D array, got 1D array instead: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.
错误代码:

model.fit(x_train,y_train)

新版sklearn中,所有数据都应为二维矩阵,独行独列也应是二维。

正确代码:

model.fit(x_train.reshqp(-1,1),y_train)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值