我正在尝试使用 spyder 和 python 运行 xgboost,但我不断收到此错误:
AttributeError: 模块 ‘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'
我有 Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
我该如何解决这个问题?
原文由 Amit 发布,翻译遵循 CC BY-SA 4.0 许可协议
我们可能有同样的问题。
我通过明确告诉 Python 在哪里可以找到 xgboost 库来解决它。
原因是我有多个名为 xgboost.py 的脚本。 Python 可能错误地导入了其中之一,因此无法找到“XGBRegressor”的定义。
这是我使用的命令:
对我来说,PATH_TO_YOUR_setup.py_file 是 ~/xgboost/python-package