我正在尝试使用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'我有Python3.5.2 ::Anaconda4.2.0 (x86_64)
我该怎么解决这个问题?
发布于 2017-10-31 13:58:37
我们可能也有同样的问题。
我通过明确告诉Python在哪里找到xgboost库来解决这个问题。
原因是我有多个名为xgboost.py的脚本。Python可能错误地导入了其中的一个,因此它找不到'XGBRegressor‘的定义。
下面是我使用的命令:
export PYTHONPATH=PATH_TO_YOUR_setup.py_file对我来说,PATH_TO_YOUR_setup.py_file是~/xgboost/package
发布于 2016-10-13 15:21:15
由于您的dir调用基本上丢失了所有内容,因此我怀疑,无论从何处开始,脚本都有一个xgboost子文件夹,其中包含一个空的__init__.py,该文件夹首先由您的import找到。
发布于 2021-12-15 03:35:57
对于我的情况,我很容易解决这个问题
from xgboost import XGBRegressor
https://stackoverflow.com/questions/40005093
复制相似问题