是否可以将网格搜索与外部定义的评分函数一起使用?

时间:2016-11-28 17:35:12

标签: scikit-learn scoring grid-search

我定义了一个外部评分函数来确定手写数字的集群精度,但无法弄清楚如何将该函数与GridSearchCV结合使用。

s = GridSearchCV(estimator = pipe_cl, 
                 param_grid = param_distributions,
                 scoring = my_scorer,
                 n_jobs=-1)


gs.fit(X_train, y_train)


y_pred_km = gs.predict(X_test)

my_scorer = make_scorer(clustering_accuracy_score(y_test, y_pred_km))    

1 个答案:

答案 0 :(得分:0)

make_scorer返回一个新函数,它将一个函数作为参数。所以这应该有效:

my_scorer = make_scorer(clustering_accuracy_score)
gs = GridSearchCV(estimator = pipe_cl, 
                 param_grid = param_distributions,
                 scoring = my_scorer,
                 n_jobs=-1)
gs.fit(X_train, y_train)