type_of_ranking#

sklr.utils.type_of_ranking(y: ArrayLike) → Literal['label_ranking', 'partial_label_ranking', 'unknown']#

Determine the type of rankings indicated by the target.

Each row of y is the ranking of a sample and each column a label, so that y[i, j] is the position of label j in ranking i, from 1 for the most preferred one. Tied labels share their position and the positions must be dense, without gaps between them. np.nan marks a label that is not ranked, and the positions of the ranked labels of each row must be dense from 1, whatever their number. See Ranking representation for the details.

Parameters:
yarray-like of shape (n_samples, n_labels)

The rankings, with at least one sample and two labels.

Returns:
target_type{“label_ranking”, “partial_label_ranking”, “unknown”}

"label_ranking" if no ranking has ties, "partial_label_ranking" if some ranking has ties, and "unknown" if y does not encode rankings, because it is not a two-dimensional array of numbers with at least one sample and two labels or because the positions of some ranking are not dense from 1.

See also

sklearn.utils.multiclass.type_of_target

Determine the type of data indicated by the target of a classifier or a regressor.

Notes

A label ranking, without ties, is also a valid partial label ranking.

Examples

>>> import numpy as np
>>> from sklr.utils import type_of_ranking
>>> type_of_ranking([[1, 2, 3], [3, 1, 2]])
'label_ranking'
>>> type_of_ranking([[1, 1, 2], [3, 1, 2]])
'partial_label_ranking'
>>> type_of_ranking([[2, np.nan, 1], [3, 1, 2]])
'label_ranking'
>>> type_of_ranking([[1, 1, 3], [3, 1, 2]])
'unknown'