The problem here is that you are calling (with argument average
) metrics.precision_score
instead of passing the function itself. An ad hoc method to remedy this is to create a function
def micro_average_precision_score(y_true, y_pred):
metrics.precision_score(y_true, y_pred, average="micro")
and then use it as your score_func
, ie score_func=micro_average_precision_score
.
On an important side note: score_func
is deprecated (since 0.13
if I am not mistaken). You are referring to scikit learn docs of version 0.10. Is that the version you use?
The new way of passing scorers is by using scorer objects. The associated keyword is scoring=
and not score_func=
. You can make a scorer object out of any scoring function, for example the one defined above, by using make_scorer
from sklearn.metrics.score import make_scorer
scorer = make_scorer(micro_average_precision_score, greater_is_better=True)
or, equivalently:
scorer = make_scorer(metrics.precision_score,
greater_is_better=True, average="micro")