python - 属性错误: module ‘xgboost’ has no attribute ‘XGBRegressor’

标签 python machine-learning regression spyder xgboost

我尝试使用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/

相关文章:

python - 分桶日期并检查是否在 Pandas 的日期范围之间

python - 迭代字符串中子字符串的位置

python-3.x - 如何区分物体曲率的两种不同类型的异常?

python-3.x - 重新训练机器学习的 Inception V3 模型

r - 在R中绘制多元Logistic回归模型的结果

python - 如何从 python 中的字符串中提取某些信息?

python - 这个 for 循环在 python 中是如何工作的

machine-learning - EM 算法的计算复杂度是多少?

r - 为什么来自mgcv的bam对于某些数据比较慢?

python - 梯度下降多元线性回归