GridSearchCV来自scikit的k-fold不一致 - 学习0.18.1也是0.19.0

时间:2017-10-20 16:27:29

标签: python-2.7 scikit-learn

我试图从sklearn.grid_search切换到sklearn.model_selection

为什么GridSearchCVscikit-learn==0.18.1中产生的k倍数与scikit-learn==0.19.0中的k倍数完全不同?

all_estimator_scores = []

def custom_multi_class_scorer(estimator, X, y_truth):

    y_pred = estimator.predict(X)

    # Collect scores
    acc = accuracy_score(y_truth, y_pred)
    estimator_score = []
    estimator_score.append(acc)
    estimator_score.append(f1_score(y_truth, y_pred, average='macro'))
    estimator_score.append(precision_score(y_truth, y_pred, average='macro'))
    estimator_score.append(recall_score(y_truth, y_pred, average='macro'))
    estimator_score.append(f1_score(y_truth, y_pred, average='micro'))
    estimator_score.append(precision_score(y_truth, y_pred, average='micro'))
    estimator_score.append(recall_score(y_truth, y_pred, average='micro'))

    # Save scores
    all_estimator_scores.append(estimator_score)

    # Return number between 0.0 and 1.0 (score)
    return acc

def run_experiment(clf, tuned_parameters, X, y):
    gscv = GridSearchCV(clf, tuned_parameters, cv=10, scoring=custom_multi_class_scorer)
    gscv.fit(X, y)
    print len(all_estimator_scores)

tuned_parameters = [{'alpha': [0.0001, .001, .01, .1, 1.0]}]
experimentor.run_experiment(MultinomialNB(), tuned_parameters, X, y)

输出scikit-learn==0.18.1

50

输出scikit-learn==0.19.0

100

0 个答案:

没有答案
相关问题