AttributeError:模块"xgboost"没有属性"XGBRegressor" [英] AttributeError: module ‘xgboost’ has no attribute ‘XGBRegressor’

查看:430
本文介绍了AttributeError:模块"xgboost"没有属性"XGBRegressor"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用spyder和python运行xgboost,但我一直收到此错误:

I am trying to run xgboost using spyder and python, but I keep getting this error:

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)

I have Python 3.5.2 :: Anaconda 4.2.0 (x86_64)

我该如何解决?

推荐答案

我们可能有相同的问题.

We probably have the same problem.

我通过明确告诉Python在哪里找到xgboost库来解决它.

I solved it by telling Python explicitly where to find xgboost library.

原因是我有多个脚本,名称为xgboost.py. Python可能错误地导入了其中一个,因此找不到'XGBRegressor'的定义.

The reason is that I have more than one scripts with the name xgboost.py. Python might have imported one of them mistakenly, so that it cannot find the definition of 'XGBRegressor'.

这是我使用的命令:

export PYTHONPATH=PATH_TO_YOUR_setup.py_file

对我来说,PATH_TO_YOUR_setup.py_file是〜/xgboost/python-package

For me, PATH_TO_YOUR_setup.py_file is ~/xgboost/python-package

这篇关于AttributeError:模块"xgboost"没有属性"XGBRegressor"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆