2017-08-16 217 views
3

我基于this articleIPython的导入错误:无法导入名称布局

试图CatBoost在它的代码,CatBoost在model.fit()plot,所以我想尝试一下我的IPython。

这里是我的CatBoost代码:

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) 

但是,它不能表现出任何情节,不停地给我的错误:

enter image description here

我没有安装ipywidgets和IPython中。 你知道如何处理这个问题吗?

+0

你是否将ipython作为笔记本或外壳运行?你在虚拟环境中运行它吗? –

+0

我将它作为笔记本运行。我尝试了虚拟环境和非虚拟环境,都得到了这个错误 –

回答

1

最后,我解决了这个问题,现在我可以看到这个图

enter image description here

在我的情况下,解决办法是安装Conda并创建一个畅达的虚拟环境,然后通过康达安装ipywidgets。 让我在这里写下所有的细节,希望它会有所帮助。 这可能只是帮助Mac用户

  1. 下载康达这里:https://www.continuum.io/downloads
  2. 添加畅达到$PATHHow to run Conda?
  3. 创建康达虚拟环境conda create -n yourenvname python=x.x anaconda
  4. 激活畅达虚拟环境source activate yourenvname
  5. 安装IPython的笔记本在这个虚拟环境中(如果你已经有用户python virtualenv并且安装了IPython for这一点,你可以跳过这一步):
    • (yourenvname)$ pip install jupyter
    • (yourenvname)$ pip install ipykernel
    • (yourenvname)$ python -m ipykernel install --user --name testenv --display-name "Python2 (yourenvname)",如果你有多个ipykernel,这里testenv应该也可以改成另外一个名字
  6. 安装ipywidgets,(yourenvname)$ conda install ipywidgets --no-deps
  7. 安装catboost,(yourenvname)$ pip install catboost
  8. 打开Jupyter Noteboo K,jupyter notebook创造Python2 (yourenvname)下一个新的笔记本,那么它应该工作

注:如果没有第8步工作之前,试试这个:

  • pip install widgetsnbextension
  • jupyter nbextension enable --py widgetsnbextension --sys-prefix
相关问题