下面是當我嘗試運行我的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()
因爲你的代碼的第一行產生錯誤,你不應該發表任何更多。請參閱https://stackoverflow.com/help/mcve。 –