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?
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.
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 ...
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With