问题
I’m experimenting with XGBoost and am blocked by an error I can’t figure out. I have sklearn installed in the active environment and can verify it by training a sklearn RandomForestClassifier in the same notebook. When I try to train a XGBoost model I get the error XGBoostError: sklearn needs to be installed in order to use this module
This works:
clf = RandomForestClassifier(n_estimators=200, random_state=0, n_jobs=-1)
This throws the exception:
clf = xgb.XGBClassifier(max_depth=3, n_estimators=300, learning_rate=0.05).fit(train_X, train_y)
UPDATE: Created a PyCharm module with exactly the same code and imports and it executed without an exception. So this appears to be a Jupyter Notebook issue. PyCharm is pointed to the same Anaconda environment as the notebook.
UPDATE 2: Created a new notebook and copied the code from the one that was throwing the exception. The code runs OK in the new notebook. Sigh. Case closed.
回答1:
Ran into the same issue, I had installed sklearn
after installing xgboost
while my jupyter notebook was running. By restarting my Jupyter notebook server, xgboost
was able to find the sklearn
installation.
Tested this in another fresh environment where I've installed sklearn
before installing xgboost
then starting my jupyter notebook without the issue.
来源:https://stackoverflow.com/questions/49353243/xgboost-cant-find-sklearn