【问题标题】:Anaconda issues with py-xgboost and sklearnpy-xgboost 和 sklearn 的 Anaconda 问题
【发布时间】:2018-10-25 14:05:50
【问题描述】:

我安装了 Anaconda 5.3.0 Winx86。我使用
conda install -c anaconda py-xgboost 安装了 xgboost 包 在 Jupyter Notebook 中,我可以导入 XGBRegressor
from xgboost import XGBRegressor 但是当我使用xgb = XGBRegressor() 时。我收到以下错误:

XGBoostError                              Traceback (most recent call last)
<ipython-input-2-99b3db9fba2c> in <module>
----> 1 xgb = XGBRegressor()

C:\ProgramData\Anaconda3\lib\site-packages\xgboost\sklearn.py in __init__(self, max_depth, learning_rate, n_estimators, silent,objective,nthread, gamma, min_child_weight, max_delta_step, subsample, colsample_bytree, colsample_bylevel, reg_alpha, reg_lambda, scale_pos_weight, base_score, seed, missing)
119                  base_score=0.5, seed=0, missing=None):
120         if not SKLEARN_INSTALLED:
--> 121     raise XGBoostError('sklearn needs to be installed in order to use this module')
122         self.max_depth = max_depth
123         self.learning_rate = learning_rate

XGBoostError: sklearn needs to be installed in order to use this module

但我可以导入 sklearn 模块而不会出现任何错误: import sklearn。我尝试重新安装 anaconda 和 xgboost 但没有任何效果。

【问题讨论】:

    标签: python scikit-learn anaconda xgboost


    【解决方案1】:

    使用 pip 安装 sklearn。

    sudo pip install sklearn
    

    现在在代码中导入 XGBRegressor:

    from xgboost.sklearn import XGBRegressor
    

    【讨论】:

    • 我已经安装了sklearn,我也签入了包,我也可以将它导入到jupyter notebook。我仍然尝试按照您所说的做,但得到了同样的错误。看起来像是某种版本问题,但不确定是什么
    • 您的系统中是否同时安装了 Python 2 和 Python 3?
    • 我安装了 python 3。是的,我在这里问这个问题之前做了足够的研究,提到的解决方案对我不起作用。
    • 我没有在我的电脑上使用 PyCharm
    猜你喜欢
    • 2016-07-17
    • 1970-01-01
    • 2020-10-04
    • 2020-08-25
    • 2018-10-29
    • 2019-05-09
    • 2014-07-11
    • 2018-08-27
    • 2020-09-01
    相关资源
    最近更新 更多