toto01
toto01

Reputation: 153

NameError:name 'cross_validation' is not defined

I am trying a code but it show me this error

NameError:name 'cross_validation' is not defined

when I run this line

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

sklrean version is 0.19.1

Upvotes: 6

Views: 30569

Answers (1)

user8403237
user8403237

Reputation:

use cross_val_score and train_test_split separately. Import them using

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

Then before applying cross validation score you need to pass the data through some model. Follow below code as an example and change accordingly:

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)

import random forest from sklearn before using it.

Upvotes: 10

Related Questions