Anaconda问题与py-xgboost和sklearn

时间:2018-10-24 18:01:04

标签: python scikit-learn anaconda xgboost

我安装了Anaconda 5.3.0 Winx86。我使用
安装了xgboost软件包 conda install -c anaconda py-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,但没有任何效果。

1 个答案:

答案 0 :(得分:0)

使用pip安装sklearn。

sudo pip install sklearn

现在在代码中导入XGBRegressor:

from xgboost.sklearn import XGBRegressor