我正试图使用spyder和python运行xgboost,但我一直收到以下错误:
属性错误:模块“xgboost”没有属性“XGBRegressor”
代码如下:
import xgboost as xgb
xgb.XGBRegressor(max_depth=3, learning_rate=0.1, n_estimators=100, silent=True,
objective='reg:linear', gamma=0, min_child_weight=1,
max_delta_step=0, subsample=1, colsample_bytree=1,
seed=0, missing=None)
错误是
Traceback (most recent call last):
File "<ipython-input-33-d257a9a2a5d8>", line 1, in <module>
xgb.XGBRegressor(max_depth=3, learning_rate=0.1, n_estimators=100, silent=True,
AttributeError: module 'xgboost' has no attribute 'XGBRegressor'
我有 Python3.5.2::Python4.2.0(x86_64)
我该怎么解决?
我在Windows1064bits上遇到了与Python3.6.2和Anaconda1.6.8完全相同的问题(FallCreator更新)
为了让它发挥作用,我做了如下工作:
1/在选定的环境中从anaconda中卸载xgboost。
2/手动删除了C:\ProgramData\Anaconda3中的xgboost目录
3/已从This page下载xgboost
4/从Anaconda启动命令提示符(当然是从您希望xgboost进入的环境)
5/CD到您下载whl文件的目录,然后键入:pip install xgboost-0.6+20171121-cp36-cp36m-win-u amd64.whl(或您下载的文件的确切名称)
我做了所有这些步骤,xgboost工作正常
由于您的
dir
调用基本上丢失了所有内容,我怀疑无论您从何处启动脚本,都有一个xgboost
子文件夹,其中有一个空的__init__.py
子文件夹,该子文件夹首先由您的import
找到。我们可能也有同样的问题。
我通过显式地告诉Python在哪里可以找到xgboost库来解决这个问题。
原因是我有多个名为xgboost.py的脚本。Python可能错误地导入了其中一个,因此找不到“XGBRegressor”的定义。
下面是我使用的命令:
对我来说,PATH_TO_YOUR_setup.py_文件是~/xgboost/python包
相关问题 更多 >
编程相关推荐