我尝试使用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'
我有 Python 3.5.2::Anaconda 4.2.0 (x86_64)
如何解决这个问题?
最佳答案
我们可能有同样的问题。
我通过明确告诉 Python 在哪里可以找到 xgboost 库来解决这个问题。
原因是我有多个名为 xgboost.py 的脚本。 Python 可能错误地导入了其中之一,因此无法找到“XGBRegressor”的定义。
这是我使用的命令:
export PYTHONPATH=PATH_TO_YOUR_setup.py_file
对我来说,PATH_TO_YOUR_setup.py_file 是 ~/xgboost/python-package
关于python - 属性错误: module ‘xgboost’ has no attribute ‘XGBRegressor’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40005093/