本文介绍了模块“ sklearn”没有属性“ 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'
我该如何处理?
推荐答案
sklearn
不会自动导入其子包。如果仅通过以下方式导入: import sklearn
,则它将无法正常工作。改为使用导入sklearn.cross_validation
。
sklearn
does not automatically import its subpackages. If you only imported via: import sklearn
, then it wont work. Import with import sklearn.cross_validation
instead.
Furhter, sklearn.cross_validation
将在0.20版中弃用。改为使用 sklearn.model_selection.train_test_split
。
Furhter, sklearn.cross_validation
will be deprecated in version 0.20. Use sklearn.model_selection.train_test_split
instead.
这篇关于模块“ sklearn”没有属性“ cross_validation”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!