2017-01-05 22 views
1

下面是當我嘗試運行我的Python代碼時所遇到的錯誤代碼。這是我的安裝問題嗎? 我安裝了python 64-bit 3.6.0,我確定我安裝了64位版本的sci-kit。我也有numpy,scipy作爲先決條件安裝。SciKit-Learn Python軟件包有錯誤

Traceback (most recent call last): 
    File "C:/Users/kevinshen/Desktop/Kaggle/GettingStarted/makeSubmission.py", line 1, in <module> 
    from sklearn.ensemble import RandomForestClassifier 
    File "C:\Users\kevinshen\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\__init__.py", line 57, in <module> 
    from .base import clone 
    File "C:\Users\kevinshen\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\base.py", line 12, in <module> 
    from .utils.fixes import signature 
    File "C:\Users\kevinshen\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\__init__.py", line 11, in <module> 
    from .validation import (as_float_array, 
    File "C:\Users\kevinshen\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\validation.py", line 18, in <module> 
    from ..utils.fixes import signature 
    File "C:\Users\kevinshen\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\fixes.py", line 406, in <module> 
    if np_version < (1, 12, 0): 
TypeError: '<' not supported between instances of 'str' and 'int 

Python代碼:

from sklearn.ensemble import RandomForestClassifier 
from numpy import genfromtxt, savetxt 

def main(): 
    #create the training & test sets, skipping the header row with [1:] 
    dataset = genfromtxt(open('Data/train.csv','r'), delimiter=',', dtype='f8')[1:] 
    target = [x[0] for x in dataset] 
    train = [x[1:] for x in dataset] 
    test = genfromtxt(open('Data/test.csv','r'), delimiter=',', dtype='f8')[1:] 

    #create and train the random forest 
    #multi-core CPUs can use: rf = RandomForestClassifier(n_estimators=100, n_jobs=2) 
    rf = RandomForestClassifier(n_estimators=100) 
    rf.fit(train, target) 
    predicted_probs = [x[1] for x in rf.predict_proba(test)] 

    savetxt('Data/submission.csv', predicted_probs, delimiter=',', fmt='%f') 

if __name__=="__main__": 
    main() 
+0

因爲你的代碼的第一行產生錯誤,你不應該發表任何更多。請參閱https://stackoverflow.com/help/mcve。 –

回答

3

你可能有numpy的1.12測試版(1.12.0b1)這就是爲什麼它抱怨STR和INT之間的比較(0B1和0)。

fixes.py的最後一個版本解決這個問題: https://github.com/scikit-learn/scikit-learn/commit/1f278e1c231e6b9b3cf813377819e25e87b6c8b6

+0

謝謝,我會看看它是否有效! –

+0

作品!感謝這件事!我對python/kaggle完全陌生,所以我不知道。 –

+0

它的工作原理!我從http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn py3.6 win32安裝了sklearn。希望它能儘快修復whl文件。 –