2016-11-08 124 views
-1

我不明白什麼時候我必須使用scikit學習的擬合方法。我什麼時候必須使用scikit的fit方法學習?

在這個網頁:http://machinelearningmastery.com/automate-machine-learning-workflows-pipelines-python-scikit-learn/ 有一個管道+ StandardScaler的例子。不使用擬合方法。

但在這另一個:http://scikit-learn.org/stable/auto_examples/svm/plot_rbf_parameters.html 還有一個StandardScaler,並有一個適合的方法。

這是我的代碼:管道+ Robustscaler:

result_list = [] 

for name in ["AWA","Rem","S1","S2","SWS","SX", "ALL"]: 
    x=sio.loadmat('/home/{}_E.mat'.format(name))['x'] 
    s_y=sio.loadmat('/home/{}_E.mat'.format(name))['y'] 
    y=np.ravel(s_y) 

    print(name, x.shape, y.shape) 
    print("") 

    #Create a pipeline 
    clf = make_pipeline(preprocessing.RobustScaler(), SVC(cache_size=1000, kernel='rbf')) 


    ###################10x20 SSS################################## 
    print("10x20") 
    xSSSmean20 = [] 
    for i in range(10): 
     sss= StratifiedShuffleSplit(y, 20, test_size=0.1, random_state=i) 
     scoresSSS=cross_validation.cross_val_score(clf, x, y, cv=sss) 

     xSSSmean20.append(scoresSSS.mean()) 

    result_list.append(xSSSmean20) 

    print("") 
+0

爲什麼這是一個糟糕的問題? – Aizzaac

+1

因爲'沒有使用合適的方法.'是錯誤的陳述。它用在'cross_val_score'中。 – MMF

+0

好的。謝謝。我不知道。 – Aizzaac

回答

1

火車你的分類,你必須適合它到你的訓練數據集。

第一個環節做也行,不是因爲它不會在片段,它不這樣做明確出現:

的方法cross_val_score使用model這是估計到適合它的數據。

看看方法'cross_val_score'的實現,並試圖理解它是如何工作的,而不用理解它是如何工作的。

Here是功能的文檔和hereGitHub的實現來參考。

建議海賊王:

嘗試去挖掘代碼,當你不明白的東西。你會學到很多!

相關問題