4

I'm trying CatBoost based on this article

In it's code, CatBoost has plot in model.fit(), so I want to try it on my IPython.

Here's my CatBoost code:

from catboost import CatBoostRegressor

# indicate categorical features for CatBoost
categorical_features_indices = np.where(X.dtypes != np.float)[0]

model=CatBoostRegressor(iterations=50, depth=3, learning_rate=0.1, 
loss_function='RMSE')
model.fit(X_train, y_train, 
cat_features=categorical_features_indices,
          use_best_model=True,
          eval_set=(X_validation, y_validation), plot=True)

But, it cannot show any plot and kept giving me error:

enter image description here

I did install ipywidgets and ipython. Do you know how to deal with this problem?

Cherry Wu
  • 3,844
  • 9
  • 43
  • 63

1 Answers1

2

Finally, I solved the problem, and now I can see this plot

enter image description here

In my case, the solution is to install Conda and create a conda virtual environment, then install ipywidgets through Conda. Let me write down all the details here, hope it will help. This may only help Mac users

  1. Download Conda here: https://www.continuum.io/downloads
  2. Add conda into $PATH: How to run Conda?
  3. Create Conda virtual environment conda create -n yourenvname python=x.x anaconda
  4. Activate conda virtual environment source activate yourenvname
  5. Install IPython Notebook in this virtual environment (if you have already user python virtualenv and installed IPython for that, you can skip this step):
    • (yourenvname)$ pip install jupyter
    • (yourenvname)$ pip install ipykernel
    • (yourenvname)$ python -m ipykernel install --user --name testenv --display-name "Python2 (yourenvname)", if you have multiple ipykernel, here testenv should also be changed to another name
  6. Install ipywidgets, (yourenvname)$ conda install ipywidgets --no-deps
  7. Install catboost, (yourenvname)$ pip install catboost
  8. Turn on Jupyter Notebook, jupyter notebook and create a new notebook under Python2 (yourenvname), then it should work

NOTE: If doesn't work, before step 8, try this:

  • pip install widgetsnbextension
  • jupyter nbextension enable --py widgetsnbextension --sys-prefix
Cherry Wu
  • 3,844
  • 9
  • 43
  • 63