anls_score#

scikitplot.corpus.anls_score(y_true, y_pred, *, threshold=0.5, normalize='basic', backend='auto', sample_weight=None, average='mean')[source]#

Average normalised Levenshtein similarity (ANLS).

Per item, s = 1 - NL when the normalised Levenshtein distance NL to a reference is below threshold and 0 otherwise; the best reference counts.

Parameters:
y_truesequence or mapping

Reference answers per item: a str or a sequence of str.

y_predsequence or mapping

Predicted answer per item (str), aligned with y_true.

thresholdfloat, default=0.5

In (0, 1]. Distances at or above it score 0, so an answer that is mostly wrong earns no partial credit.

normalize{“basic”, “squad”, None}, default=”basic”

Normalisation of both sides.

backend{“auto”, “python”}, default=”auto”

Edit-distance implementation (both exact).

sample_weightarray-like of shape (n_items,), default=None

Per-item weights of the mean.

average{“mean”, None}, default=”mean”

None returns per-item values.

Returns:
float or numpy.ndarray
Raises:
TypeError, ValueError

For malformed inputs or a threshold outside (0, 1].

Parameters:
  • y_true (Any)

  • y_pred (Any)

  • threshold (float)

  • normalize (str | None)

  • backend (str)

  • sample_weight (Any)

  • average (str | None)

Return type:

Any

Examples

>>> anls_score(["kitten", "kitten"], ["kitten", "dog"])
0.5