precision_at_k#
- scikitplot.corpus.precision_at_k(y_true, y_pred, *, k=10, sample_weight=None, relevance_threshold=1, duplicates='raise', zero_division='warn', average='mean')[source]#
Fraction of the first
kranked identifiers that are relevant.- Parameters:
- y_truesequence or mapping
Relevance judgments per query (see
_ranking).- y_predsequence or mapping
Rankings per query, best first.
- kint or None, default=10
Cutoff. The denominator is
keven when fewer are ranked.Nonedivides by the ranking length instead.- sample_weightarray-like of shape (n_queries,), default=None
Per-query weights of the mean.
- relevance_thresholdfloat, default=1
Grade from which a judged identifier is relevant.
- duplicates{“raise”, “first”}, default=”raise”
What a repeated identifier in a ranking does.
- zero_division{“warn”, 0.0, 1.0, np.nan}, default=”warn”
Value when the metric is undefined (only without a cutoff, for an empty ranking).
- average{“mean”, None}, default=”mean”
Nonereturns the per-query values.
- Returns:
- float or numpy.ndarray
- Raises:
- TypeError, ValueError
For malformed inputs; the message names the query.
- Parameters:
- Return type:
See also
Examples
>>> precision_at_k([{"a", "b"}], [["a", "x", "b", "y"]], k=2) 0.5