DummyLabelRanker#
- class sklr.dummy.DummyLabelRanker(*, strategy: Literal['consensus', 'constant'] = 'consensus', constant: ArrayLike | None = None, model: Literal['mallows', 'plackett_luce'] = 'mallows', max_iter: int | None = None, tol: float = 1e-06)#
Label ranker that predicts the same ranking for every sample.
It ignores the input features and predicts the consensus of the training rankings or a ranking given by the user. It is useful as a simple baseline to compare with other 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 of the training rankings according tomodel, and with"constant", the ranking given byconstant.- constantarray-like of shape (n_labels,), default=None
Ranking predicted with
strategy="constant", complete and without ties. Ignored withstrategy="consensus".- model{“mallows”, “plackett_luce”}, default=”mallows”
Probability model of the training rankings, used with
strategy="consensus". With"mallows", the consensus is the center ranking of the Mallows model, found by the weighted Borda count, and by Algorithm 1 of [cheng_decision_2009] when some rankings are incomplete. With"plackett_luce", the consensus sorts the labels by decreasing parameter of the Plackett-Luce model, whose maximum likelihood estimate is found by the MM algorithm of [hunter_mm_2004]. In both cases, ties between labels go to the one with the smaller index.- max_iterint, default=None
Maximum number of iterations of the estimation of the model.
Nonemeans100withmodel="mallows"and1000withmodel="plackett_luce". Withmodel="mallows", the estimation only iterates when some ranking is incomplete. AConvergenceWarningis issued if the estimation does not converge, which is common withmodel="plackett_luce"when the training rankings agree, because the maximum likelihood estimate does not exist.- tolfloat, default=1e-6
Tolerance of the estimation of the Plackett-Luce model, which stops when no parameter changes by more than
tol. Ignored withmodel="mallows".
- 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
Xhas feature names that are all strings.
See also
DummyPartialLabelRankerPartial label ranker that predicts the same bucket order for every sample.
sklearn.dummy.DummyClassifierClassifier that makes predictions using simple rules.
References
[cheng_decision_2009]W. Cheng, J. Hühn and E. Hüllermeier, “Decision tree and instance-based learning for label ranking”, in Proceedings of the 26th International Conference on Machine Learning, Montreal, Canada, pp. 161-168, 2009.
[hunter_mm_2004]D. R. Hunter, “MM algorithms for generalized Bradley-Terry models”, The Annals of Statistics, vol. 32, no. 1, pp. 384-406, 2004.
Examples
>>> from sklr.dummy import DummyLabelRanker >>> X = [[0], [1], [2], [3]] >>> y = [[1, 2, 3], [2, 1, 3], [1, 2, 3], [3, 1, 2]] >>> ranker = DummyLabelRanker() >>> ranker.fit(X, y) DummyLabelRanker() >>> ranker.predict([[1.1], [2.2]]) array([[2, 1, 3], [2, 1, 3]]) >>> round(ranker.score(X, y), 2) 0.5
- 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.
Nonemeans 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
MetadataRequestencapsulating 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 Kendall’s \(\tau\) on the given data.
It is computed with
kendall_tau_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 without ties.- sample_weightarray-like of shape (n_samples,), default=None
Sample weights.
- Returns:
- scorefloat
Mean Kendall’s \(\tau\) of
self.predict(X)with respect toy.
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') DummyLabelRanker#
Configure whether metadata should be requested to be passed to the
fitmethod.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(seesklearn.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 tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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_weightparameter infit.
- 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$') DummyLabelRanker#
Configure whether metadata should be requested to be passed to the
scoremethod.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(seesklearn.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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_weightparameter inscore.
- Returns:
- selfobject
The updated object.