KDEyCS#
- class mlquantify.matching.KDEyCS(estimator=None, bandwidth=0.1, kernel='gaussian', solver='slsqp', cv=None, stratified=True, shuffle=False, random_state=None)[source]#
KDEy Cauchy-Schwarz (KDEy-CS) quantifier.
Targets prior probability shift. A multiclass distribution-matching method that models each class with a Gaussian KDE over the posterior vectors and selects the prevalence minimising the Cauchy-Schwarz divergence, which has a closed form. The most efficient KDEy variant, since the expensive train-train kernel terms are precomputed once at fit time.
- Parameters:
- estimatorestimator, optional
A probabilistic classifier with
fitandpredict_probamethods.- bandwidthfloat, default=0.1
Bandwidth of the Gaussian kernel density estimator; controls smoothness.
- kernelstr, default=’gaussian’
Must be
'gaussian'; the closed-form divergence is Gaussian-specific.- solverstr, default=’slsqp’
Constrained optimizer over the simplex (see
mlquantify.solvers).- cvint or None, default=None
Cross-validation folds for computing training scores.
- 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:
- estimator_estimator
The fitted underlying classifier.
- classes_ndarray of shape (n_classes,)
Class labels seen during
fit.
Notes
The closed form makes KDEy-CS the fastest KDEy variant: the train-train kernel matrices are computed once at training time and reused for any test bag.
References
References
[1]Moreo, A., González, P., & del Coz, J. J. (2024). Kernel Density Estimation for Multiclass Quantification. Machine Learning, 113, 3075–3107.
Examples
>>> from mlquantify.matching import KDEyCS >>> from sklearn.linear_model import LogisticRegression >>> from sklearn.datasets import make_classification >>> X, y = make_classification(n_samples=200, random_state=42) >>> q = KDEyCS(estimator=LogisticRegression()).fit(X, y) >>> q.predict(X) {0: ..., 1: ...}
- get_distance(dist_train, dist_test, distance='hellinger')[source]#
Compute a distance between two normalized representations.
- 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.
- set_fit_request(*, cv_prediction: bool | None | str = '$UNCHANGED$', estimator_fitted: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$') KDEyCS[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.