Machine learning 名称错误:名称';交叉验证&x27;没有定义

Machine learning 名称错误:名称';交叉验证&x27;没有定义,machine-learning,Machine Learning,我正在尝试一个代码,但它显示了这个错误 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分别使用交叉评分和训练测试分割。使用 from sklearn.model_selection import cross_val_

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

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

分别使用交叉评分和训练测试分割。使用

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导入随机林