ranking_metrics#
- scikitplot.corpus.ranking_metrics(y_true, y_pred, *, metrics=('hit_rate@10', 'precision@10', 'recall@10', 'mrr@10', 'ndcg@10'), sample_weight=None, relevance_threshold=1, duplicates='raise', zero_division='warn', gain='linear', average='mean')[source]#
Compute several ranking metrics in one validated pass.
- Parameters:
- y_truesequence or mapping
Relevance judgments per query.
- y_predsequence or mapping
Rankings per query, best first.
- metricsiterable of str, optional
Default
("hit_rate@10", "precision@10", "recall@10", "mrr@10", "ndcg@10"). Names"<base>"or"<base>@<k>"; bases areprecision,recall,hit_rate,mrr,map,ndcgandr_precision(no cutoff). Without@kthe whole ranking is used.- sample_weightarray-like of shape (n_queries,), default=None
Per-query weights of the means.
- 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 of an undefined metric.
- gain{“linear”, “exponential”}, default=”linear”
nDCG gain.
- average{“mean”, None}, default=”mean”
Nonereturns per-query arrays.
- Returns:
- dict
Metric name to value (or array), in the order requested.
- Raises:
- TypeError, ValueError
For malformed inputs, an unknown name or a repeated name.
- Parameters:
- Return type:
Examples
>>> ranking_metrics([["a"]], [["x", "a"]], metrics=["recall@1", "mrr"]) {'recall@1': 0.0, 'mrr': 0.5}