[英]NameError:name 'cross_validation' is not defined
我正在尝试一个代码,但它显示了这个错误
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 导入随机森林。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.