2017-04-25 769 views
1

我想通過Python中的Keras Deep Learning Library學習神經網絡。我使用Python 3和參考以下鏈接:Tutorial LinkPython 3:沒有名爲'sklearn.model_selection'的模塊

我嘗試運行下面的代碼,但出現以下錯誤:

導入錯誤:沒有名爲「sklearn.model_selection」

import numpy 
import pandas 

from keras.models import Sequential 
from keras.layers import Dense 
from keras.wrappers.scikit_learn import KerasRegressor 
from sklearn.model_selection import cross_val_score 
from sklearn.model_selection import KFold 
from sklearn.preprocessing import StandardScaler 
from sklearn.pipeline import Pipeline 

任何模塊非常感謝幫助!

回答

2

我想你會安裝錯誤版本的sklearn。

請試試這個: import sklearn print (sklearn.__version__) 0.17.1

如果版本低於0.18,請與pip install -U scikit-learnpip3 install -U scikit-learn

如果你有import Error,請pip install scikit-learnpip3 install scikit-learn

+0

謝謝你的指令。我結束了安裝更新,但它仍然在這裏出現錯誤: ImportError:無法導入名稱'rankdata'; ---> 32 from ..utils.fixes import rankdata – PineNuts0

+0

這很可能是你用conda安裝的,但用pip更新的。不要這樣做。卸載scikit-learn,刪除文件夾,然後使用conda或pip重新安裝。如果您使用anaconda,我會推薦conda。通過@amueller on GitHub –

+0

是的,你是正確的;我安裝了conda。我發現用'conda install ...'更新我的numpy會自動更新一切 – PineNuts0

-1

此命令的作用安裝sklearn更新對於我在Ubuntu和Python 2中:

sudo apt-get install python-sklearn 

對於Python 3,使用這個命令:

sudo apt install python3-sklearn 
0

嘗試此python3

pip3 install -U scikit-learn