PartialLabelRankerMixin#

class sklr.base.PartialLabelRankerMixin#

Mixin class for all partial label rankers in scikit-lr.

A partial label ranker predicts a ranking of the labels for each sample, where some labels may be tied, and learns from (possibly incomplete) rankings that may have ties. This mixin sets the estimator_type tag to "partial_label_ranker" and states through the target tags that fit requires a target y with several outputs, one per label, as described in Ranking representation. Its score() method computes the \(\tau_x\) coefficient between the predicted and the true rankings.

See also

LabelRankerMixin

Mixin class for all label rankers.

is_partial_label_ranker

Return whether an estimator is a partial label ranker.

Examples

>>> import numpy as np
>>> from sklearn.base import BaseEstimator
>>> from sklr.base import PartialLabelRankerMixin, is_partial_label_ranker
>>> # Mixin classes should always be on the left-hand side for a correct MRO
>>> class MyEstimator(PartialLabelRankerMixin, BaseEstimator):
...     def fit(self, X, y):
...         self.ranking_ = np.asarray(y)[0]
...         return self
...     def predict(self, X):
...         return np.tile(self.ranking_, (len(X), 1))
>>> estimator = MyEstimator()
>>> X = np.array([[1, 2], [2, 3], [3, 4]])
>>> y = np.array([[1, 1, 2], [2, 1, 3], [1, 2, 2]])
>>> estimator.fit(X, y).predict(X)
array([[1, 1, 2],
       [1, 1, 2],
       [1, 1, 2]])
>>> is_partial_label_ranker(estimator)
True
score(X: ArrayLike, y: ArrayLike, sample_weight: ArrayLike | None = None) → float#

Return the mean \(\tau_x\) coefficient on the given data.

It is computed with tau_x_score().

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples, n_labels)

True rankings for X, complete and possibly with ties.

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

Sample weights.

Returns:
scorefloat

Mean \(\tau_x\) of self.predict(X) with respect to y.