2013-02-18 43 views
3

它是如何possbile這個演示代碼(從這裏取:http://scikit-learn.org/dev/auto_examples/grid_search_digits.html
TypeError: __init__() got an unexpected keyword argument 'scoring'時obviuodly得分是一個參數(http://scikit-learn.org/dev/modules/generated/sklearn.grid_search.GridSearchCV.html#sklearn.grid_search.GridSearchCV)?類型錯誤:__init __()得到了一個意想不到的關鍵字參數「得分」

from __future__ import print_function 

from sklearn import datasets 
from sklearn.cross_validation import train_test_split 
from sklearn.grid_search import GridSearchCV 
from sklearn.metrics import classification_report 
from sklearn.svm import SVC 

print(__doc__) 

# Loading the Digits dataset 
digits = datasets.load_digits() 

# To apply an classifier on this data, we need to flatten the image, to 
# turn the data in a (samples, feature) matrix: 
n_samples = len(digits.images) 
X = digits.images.reshape((n_samples, -1)) 
y = digits.target 

# Split the dataset in two equal parts 
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.5, random_state=0) 

# Set the parameters by cross-validation 
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4], 
       'C': [1, 10, 100, 1000]}, 
       {'kernel': ['linear'], 'C': [1, 10, 100, 1000]}] 

scores = ['precision', 'recall'] 

for score in scores: 
    print("# Tuning hyper-parameters for %s" % score) 
    print() 

    clf = GridSearchCV(SVC(C=1), tuned_parameters, scoring=score) 
    clf.fit(X_train, y_train, cv=5) 

    print("Best parameters set found on development set:") 
    print() 
    print(clf.best_estimator_) 
    print() 
    print("Grid scores on development set:") 
    print() 
    for params, mean_score, scores in clf.grid_scores_: 
     print("%0.3f (+/-%0.03f) for %r" 
      % (mean_score, scores.std()/2, params)) 
    print() 

    print("Detailed classification report:") 
    print() 
    print("The model is trained on the full development set.") 
    print("The scores are computed on the full evaluation set.") 
    print() 
    y_true, y_pred = y_test, clf.predict(X_test) 
    print(classification_report(y_true, y_pred)) 
    print() 

# Note the problem is too easy: the hyperparameter plateau is too flat and the 
# output model is the same for precision and recall with ties in quality. 
+0

支持你可以給scikit的完整追蹤和版本號? – 2013-02-18 01:06:00

回答

7

參數scoring在0.14版本的發展是新的示例代碼是該版本。您已經安裝了scikit可能是0.13或更早的版本,它沒有得分參數。

+0

對於Windows我發現只有0.13:http://sourceforge.net/projects/scikit-learn/files/。如果我沒有在示例代碼中使用的得分參數怎樣的結果發生大的變化? – postgres 2013-02-18 01:48:19

+5

@postgres:有[對0.13文檔對應示例]一(http://scikit-learn.org/0.13/auto_examples/grid_search_digits.html)。 – 2013-02-18 07:12:54

+0

當前版本是0.13。版本0.14是開發版本烈瑞恩指出,沒有任何的二進制文件或任何東西,因爲它每天都在變化。 – 2013-02-18 11:00:14

1

你運行開發版本?

例如,參數不0.12

相關問題