DummyPartialLabelRanker#

class sklr.dummy.DummyPartialLabelRanker(*, strategy: Literal['consensus', 'constant'] = 'consensus', constant: ArrayLike | None = None)#

Partial label ranker that predicts the same bucket order for every sample.

It ignores the input features and predicts the consensus of the training rankings or a ranking given by the user. With strategy="consensus", it is the Zero-R baseline of [alfaro_learning_2021]. It is useful as a simple baseline to compare with other partial label rankers, and should not be used for real problems.

Read more in the User Guide.

Parameters:
strategy{“consensus”, “constant”}, default=”consensus”

Strategy to choose the predicted ranking. With "consensus", it is the consensus bucket order of the training rankings, found by the Bucket Pivot Algorithm of [aledo_utopia_2017] as in [alfaro_learning_2021], with the labels that no ranking of positive weight ranks together with another label tied in a last bucket. With "constant", it is the ranking given by constant.

constantarray-like of shape (n_labels,), default=None

Ranking predicted with strategy="constant", complete and possibly with ties. Ignored with strategy="consensus".

Attributes:
ranking_ndarray of shape (n_labels,)

Ranking predicted for every sample, as the positions of the labels.

n_features_in_int

Number of features seen during fit.

feature_names_in_ndarray of shape (n_features_in_,)

Names of features seen during fit. Defined only when X has feature names that are all strings.

See also

DummyLabelRanker

Label ranker that predicts the same ranking for every sample.

sklearn.dummy.DummyClassifier

Classifier that makes predictions using simple rules.

References

[aledo_utopia_2017]

J. A. Aledo, J. A. Gámez and A. Rosete, “Utopia in the solution of the Bucket Order Problem”, Decision Support Systems, vol. 97, pp. 69-80, 2017.

[alfaro_learning_2021] (1,2)

J. C. Alfaro, J. A. Aledo and J. A. Gámez, “Learning decision trees for the partial label ranking problem”, International Journal of Intelligent Systems, vol. 36, no. 2, pp. 890-918, 2021.

Examples

>>> from sklr.dummy import DummyPartialLabelRanker
>>> X = [[0], [1], [2], [3]]
>>> y = [[1, 2, 2], [2, 1, 3], [1, 1, 2], [3, 1, 2]]
>>> ranker = DummyPartialLabelRanker()
>>> ranker.fit(X, y)
DummyPartialLabelRanker()
>>> ranker.predict([[1.1], [2.2]])
array([[1, 1, 2],
       [1, 1, 2]])
fit(X: ArrayLike, y: ArrayLike, sample_weight: ArrayLike | None = None) → Self#

Fit the dummy ranker.

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

Training data. Only its number of samples, its number of features and the names of its features are used.

yarray-like of shape (n_samples, n_labels)

Training rankings, as described in Ranking representation, possibly incomplete, and with ties only for a partial label ranker.

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

Sample weights, non-negative and not all zero. None means that all the samples weigh the same.

Returns:
selfobject

Fitted estimator.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

predict(X: ArrayLike) → ndarray#

Predict the same ranking for every sample.

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

Test data. It is only used to count its samples.

Returns:
yndarray of shape (n_samples, n_labels)

The ranking in ranking_, repeated for every sample.

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.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') → DummyPartialLabelRanker#

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') → DummyPartialLabelRanker#

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.