make_corpus_scorer#
- scikitplot.corpus.make_corpus_scorer(score_func, *, response_method='predict', greater_is_better=True, id_getter=None, on_degraded='raise', **kwargs)[source]#
Make a scikit-learn compatible scorer from a corpus metric.
- Parameters:
- score_funccallable
score_func(y_true, y_pred, **kwargs) -> float, for examplerecall_at_kortoken_f1_score.- response_method{“predict”, “search”}, default=”predict”
How predictions are obtained (see the module documentation).
- greater_is_betterbool, default=True
Falsefor a loss; the scorer then negates it, as scikit-learn does.- id_gettercallable or None, default=None
response_method="search"only:id_getter(result)maps a search result to the identifier used byy_true(for example a chunk to its source document).Noneapplies the rule ofranked_ids.- on_degraded{“raise”, “ignore”}, default=”raise”
response_method="search"only: what a response whose requested leg did not run does.- **kwargsdict
Passed to
score_funcon every call, such ask=10.
- Returns:
- scorer
A
_BaseScorersubclass instance (scikit-learn’s, or the vendored copy; seescorer_backend_info). It pickles.
- Raises:
- TypeError
If
score_funcorid_getteris not callable, orkwargsdo not fit the signature ofscore_func.- ValueError
For an unknown
response_methodoron_degraded, orid_getterwithresponse_method="predict".
- Parameters:
- Return type:
See also
get_corpus_scorerThe same from a name such as
"ndcg@10".sklearn.metrics.make_scorerThe scikit-learn original.
Examples
>>> from scikitplot.corpus import make_corpus_scorer, recall_at_k >>> scorer = make_corpus_scorer(recall_at_k, response_method="search", k=2) >>> class Index: ... def search(self, query): ... return [("d1", 0.9), ("d2", 0.5)] >>> scorer(Index(), ["first query", "second query"], [["d2"], ["d3"]]) 0.5