GAC#
- class mlquantify.adjust_counting.GAC(learner=None)[source]#
Generalized Adjusted Count method.
This class implements the Generalized Adjusted Count (GAC) algorithm for quantification adjustment as described in Firat (2016) [1]. The method adjusts the estimated class prevalences by normalizing the confusion matrix based on prevalence estimates, providing a correction for bias caused by distribution differences between training and test data.
The confusion matrix is normalized by dividing each column by the prevalence estimate of the corresponding class. For classes with zero estimated prevalence, the diagonal element is set to 1 to avoid division by zero.
This normalization ensures that the matrix best reflects the classifier’s behavior relative to the estimated class distributions, improving quantification accuracy.
- Parameters:
- learnerestimator, optional
Base classifier with
fitandpredictmethods.
- Attributes:
- CMndarray of shape (n_classes, n_classes)
Normalized confusion matrix used for adjusting predicted prevalences.
- classes_ndarray
Array of class labels observed during training.
References
[1]Firat, A. (2016). “Unified Framework for Quantification”, Proceedings of AAAI Conference on Artificial Intelligence, pp. 1-8.
Examples
>>> from sklearn.linear_model import LogisticRegression >>> from mlquantify.adjust_counting import GAC >>> import numpy as np >>> gac = GAC(learner=LogisticRegression()) >>> X = np.random.randn(50, 4) >>> y = np.random.randint(0, 2, 50) >>> gac.fit(X, y) >>> gac.predict(X) {0: 0.5, 1: 0.5}
- aggregate(predictions, train_predictions, y_train_values)[source]#
Aggregate predictions and apply matrix- or rate-based bias correction.
- fit(X, y, learner_fitted=False, cv=10, stratified=True, random_state=None, shuffle=True)[source]#
Fit the quantifier using the provided data and learner.
- 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: bool | None | str = '$UNCHANGED$', learner_fitted: bool | None | str = '$UNCHANGED$', random_state: bool | None | str = '$UNCHANGED$', shuffle: bool | None | str = '$UNCHANGED$', stratified: bool | None | str = '$UNCHANGED$') GAC[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:
- cvstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
cvparameter infit.- learner_fittedstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
learner_fittedparameter infit.- random_statestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
random_stateparameter infit.- shufflestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
shuffleparameter infit.- stratifiedstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
stratifiedparameter 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.