如何解决ValueError:预期的二维数组,得到一维数组而不是用于 K 折交叉验证
我正在尝试对我的数据集执行 K-Fold 交叉验证,但是却弹出了一条错误消息
@IBAction func sButton(_ sender: UIButton) { /// make sure you have the right function signature
playSound(sound: "Ssound",type: "wav")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
数据如下:
ValueError: Expected 2D array,got 1D array instead:
以下是我使用过的代码:
Fuel Consumption Distance
13.046 298.89
14.717 468.60
15.032 464.38
from sklearn.model_selection import KFold
kf = KFold(n_splits=3,shuffle=True,random_state=42)
kf
x = data.loc[:,'Fuel Consumption'].values
y = data.loc[:,'Distance'].values
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.3,random_state=42,shuffle=True)
for train_index,test_index in kf.split(y):
print(train_index,test_index)
def get_score(model,x_train,y_test):
model.fit(x_train,y_train)
return model.score(x_test,y_test)
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。