我试图将数据集拆分为培训和测试数据集,但是我遇到了此错误:
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'
我该如何处理?
sklearn
不会自动导入其子弹。如果您仅通过以下方式导入:import sklearn
,则它将无法正常工作。用import sklearn.cross_validation
导入。
此外,sklearn.cross_validation
将在0.20版中弃用。改用sklearn.model_selection.train_test_split
。
尝试以下:
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)
您可以尝试此
X_train,X_test,Y_train,Y_test =
sklearn.model_selection.train_test_split(X,boston_df.price)
等效于sklearn中的cross_validation是:
sklearn.model_selection
" cross_validation"名称现在已弃用,并在新的anaconda版本中被" model_selection"取代。因此您可以使用
from sklearn.model_selection import train_test_split
谢谢!在Colab中成功:
from sklearn.model_selection import train_test_split