gpt4 book ai didi

machine-learning - 名称错误 :name 'cross_validation' is not defined

转载 作者:行者123 更新时间:2023-11-30 09:26:56 25 4
gpt4 key购买 nike

我正在尝试一个代码,但它显示了这个错误

NameError:name 'cross_validation' is not defined

当我运行这一行时

X_train, X_test, y_train, y_test = cross_validation.train_test_split(X,y,test_size=0.2)

sklrean版本是0.19.1

最佳答案

分别使用cross_val_score和train_test_split。使用导入它们

from sklearn.model_selection import cross_val_score
from sklearn.model_selection import train_test_split

然后在应用交叉验证分数之前,您需要通过某个模型传递数据。以下面的代码为例并进行相应的更改:

xtrain,ytrain,xtest,ytest=train_test_split(balancedData.iloc[:,0:29],balancedData['Left'],test_size=0.25,random_state=123)

rf=RandomForestClassifier(max_depth=8,n_estimators=5)
rf_cv_score=cross_val_score(estimator=rf,X=xtrain,y=xtest,cv=5)
print(rf_cv_score)

在使用之前从 sklearn 导入随机森林。

关于machine-learning - 名称错误 :name 'cross_validation' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50570306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com