2017-08-16 211 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
相關問題