module 'sklearn' has no attribute 'cross_validation'
Question:
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?
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.
you can try this
X_train,X_test,Y_train,Y_test =
sklearn.model_selection.train_test_split(X,boston_df.price)
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)
The equivalent to cross_validation in sklearn is:
sklearn.model_selection
“cross_validation” name is now deprecated and was replaced by “model_selection” inside the new anaconda versions. So you can use
from sklearn.model_selection import train_test_split
Thanks! Successful with this in Colab:
from sklearn.model_selection import train_test_split
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?
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.
you can try this
X_train,X_test,Y_train,Y_test =
sklearn.model_selection.train_test_split(X,boston_df.price)
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)
The equivalent to cross_validation in sklearn is:
sklearn.model_selection
“cross_validation” name is now deprecated and was replaced by “model_selection” inside the new anaconda versions. So you can use
from sklearn.model_selection import train_test_split
Thanks! Successful with this in Colab:
from sklearn.model_selection import train_test_split