我试图从sklearn.grid_search
切换到sklearn.model_selection
。
为什么GridSearchCV
在scikit-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