Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module 'sklearn' has no attribute 'cross_validation'

I am trying to split my dataset into training and testing dataset, but I am getting this error:

X_train,X_test,Y_train,Y_test = sklearn.cross_validation.train_test_split(X,df1['ENTRIESn_hourly']) 

AttributeError                            Traceback (most recent call last) <ipython-input-53-5445dab94861> in <module>() ----> 1 X_train,X_test,Y_train,Y_test = sklearn.cross_validation.train_test_split(X,df1['ENTRIESn_hourly'])  AttributeError: module 'sklearn' has no attribute 'cross_validation' 

How can I handle this?

like image 221
Naren Avatar asked Oct 04 '17 19:10

Naren


People also ask

Why Sklearn Cross_validation is not working?

Solution: Replace cross_validation with model_selectionThis error may be related to renaming and deprecation of cross_validation sub-module to model_selection . cross_validation was deprecated in version 0.18 and was changed to model_selection from version 0.20 onwards. It should resolve this issue.

What is Sklearn Cross_validation?

sklearn.cross_validation.train_test_split(*arrays, **options) Split arrays or matrices into random train and test subsets. Quick utility that wraps calls to check_arrays and next(iter(ShuffleSplit(n_samples))) and application to input data into a single call for splitting (and optionally subsampling) data in a oneliner ...


2 Answers

sklearn does not automatically import its subpackages. If you only imported via: import sklearn, then it won't work. Import with import sklearn.cross_validation instead.

Further, sklearn.cross_validation will be deprecated in version 0.20. Use sklearn.model_selection.train_test_split instead.

like image 130
Brenden Petersen Avatar answered Sep 29 '22 04:09

Brenden Petersen


Try this:

from sklearn.model_selection import train_test_split X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.33, random_state=101) 
like image 34
gogasca Avatar answered Sep 29 '22 05:09

gogasca