MLPE#
- class mlquantify.likelihood.MLPE(estimator=None, solver='slsqp', tau_0=0.0, tau_1=0.0, cv=None, stratified=True, shuffle=False, random_state=None)[source]#
Maximum Likelihood Prevalence Estimation (MLPE) quantifier.
The trivial quantification baseline. Under the assumption of no shift, the maximum-likelihood estimate of the test prevalence is exactly the observed training prevalence, so MLPE ignores the test set entirely and always returns the training class proportions. It is the reference lower bound that any genuine quantifier should beat; if a method cannot improve on MLPE, it is not exploiting the test data.
- Parameters:
- estimatorestimator, optional
Kept for API compatibility with the aggregative quantifiers; it does not influence the estimate, since MLPE returns the training prevalence regardless of the test input.
- solver, tau_0, tau_1optional
Retained for interface compatibility with the likelihood-composition framework; unused by this trivial baseline.
- cvint or None, default=None
Cross-validation folds used when fitting the (unused) estimator.
- stratifiedbool, default=True
Whether to stratify CV splits.
- shufflebool, default=False
Whether to shuffle data before splitting.
- random_stateint or None, default=None
Random seed for reproducibility.
- Attributes:
- classes_ndarray of shape (n_classes,)
Class labels seen during
fit.- train_priors_ndarray of shape (n_classes,)
Training class prevalences, returned for any test set.
See also
EMQNon-trivial maximum-likelihood quantifier (EM re-weighting).
CCClassify-and-count baseline that does use the test data.
Notes
MLPE makes no use of the test data; it is included only as a sanity-check baseline. Contrast with
EMQ, the non-trivial maximum-likelihood quantifier that re-weights the posteriors to the test set.References
References
[1]Saerens, M., Latinne, P., & Decaestecker, C. (2002). Adjusting the Outputs of a Classifier to New a Priori Probabilities. Neural Computation, 14(1), 2141–2156.
Examples
>>> from mlquantify.likelihood import MLPE >>> from sklearn.linear_model import LogisticRegression >>> import numpy as np >>> rng = np.random.default_rng(0) >>> X = rng.standard_normal((200, 4)) >>> y = (rng.random(200) < 0.3).astype(int) >>> q = MLPE(LogisticRegression()).fit(X, y) >>> q.predict(rng.standard_normal((50, 4))) # returns the training prevalence {0: ..., 1: ...}
- aggregate(test_representation, train_representation=None, train_labels=None, classes=None)[source]#
Return the training prevalence, ignoring the test representation.
If
train_labelsis provided its class prevalence is used; otherwise the prevalence observed atfittime (train_priors_) is returned.
- fit(X, y, estimator_fitted=False, sample_weight=None, cv_prediction='refit')[source]#
Fit the likelihood compose quantifier.
When
representationis provided the fitting is delegated to the parentBaseComposeQuantifier. Otherwise, only the estimator is trained (the likelihood is evaluated directly from posteriors at prediction time).- Parameters:
- Xarray-like of shape (n_samples, n_features)
Training feature matrix.
- yarray-like of shape (n_samples,)
Training class labels.
- estimator_fittedbool, default=False
Skip fitting the estimator if already fitted.
- sample_weightarray-like of shape (n_samples,) or None, default=None
Per-sample weights.
- cv_prediction{‘refit’, ‘ensemble’}, default=’refit’
Cross-validation strategy.
- Returns:
- selfLikelihoodComposeQuantifier
The fitted quantifier.
- get_metadata_routing()[source]#
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)[source]#
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)[source]#
Return the training prevalence, ignoring
X.MLPE is the trivial baseline: it estimates the test prevalence as the observed training prevalence, so the test features are not used.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Test feature matrix (ignored).
- Returns:
- prevalencesdict or ndarray of shape (n_classes,)
The training class prevalences.
- set_fit_request(*, cv_prediction: bool | None | str = '$UNCHANGED$', estimator_fitted: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$') MLPE[source]#
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:
- cv_predictionstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
cv_predictionparameter infit.- estimator_fittedstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
estimator_fittedparameter infit.- 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)[source]#
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.