我正在尝试将我的数据集拆分为训练和测试数据集,但我收到此错误:
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'
我该如何处理?
答案 0 :(得分:55)
sklearn
不会自动导入其子包。如果您只通过:import sklearn
导入,那么它将无法正常工作。改为使用import sklearn.cross_validation
导入。
在版本0.20中将弃用sklearn.cross_validation
。请改用sklearn.model_selection.train_test_split
。
答案 1 :(得分:2)
尝试一下:
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)
答案 2 :(得分:2)
现在不赞成使用“ cross_validation”名称,并在新的anaconda版本中将其替换为“ model_selection”。所以你可以使用
from sklearn.model_selection import train_test_split
答案 3 :(得分:1)
您可以尝试
X_train,X_test,Y_train,Y_test =
sklearn.model_selection.train_test_split(X,boston_df.price)
答案 4 :(得分:1)
sklearn中的cross_validation等效于:
sklearn.model_selection