HDx#
- class mlquantify.methods.non_aggregative.HDx(bins_size: ndarray | None = None)[source]#
Hellinger Distance Minimization (HDx).
This method estimates class prevalence by calculating the Hellinger distance for each feature in the dataset, as opposed to HDy, which computes the distance for classifier-generated scores.
- Parameters:
- bins_sizenp.ndarray, optional
An array of bin sizes for histogram calculations. Defaults to an array combining linearly spaced values between 2 and 20 with an additional bin size of 30.
- Attributes:
- bins_sizenp.ndarray
An array of bin sizes for histogram calculations.
- neg_featuresnp.ndarray
Features from the negative class.
- pos_featuresnp.ndarray
Features from the positive class.
References
[1]GONZÁLEZ-CASTRO, Víctor; ALAIZ-RODRÍGUEZ, Rocío; ALEGRE, Enrique. Class distribution estimation based on the Hellinger distance. Information Sciences, v. 218, p. 146-164, 2013. Avaliable at https://www.sciencedirect.com/science/article/abs/pii/S0020025512004069?casa_token=W6UksOigmp4AAAAA:ap8FK5mtpAzG-s8k2ygfRVgdIBYDGWjEi70ueJ546coP9F-VNaCKE5W_gsAv0bWQiwzt2QoAuLjP
Examples
>>> from mlquantify.methods.non_aggregative import HDx >>> from mlquantify.utils.general import get_real_prev >>> from sklearn.datasets import load_breast_cancer >>> from sklearn.model_selection import train_test_split >>> >>> features, target = load_breast_cancer(return_X_y=True) >>> >>> X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.3, random_state=42) >>> >>> model = HDx() >>> model.fit(X_train, y_train) >>> >>> predictions = model.predict(X_test) >>> predictions {0: 0.39, 1: 0.61} >>> get_real_prev(y_test) {0: 0.3684210526315789, 1: 0.631578947368421}
- fit(X, y, n_jobs: int = 1)[source]#
Fit the quantifier model to the training data.
- Parameters:
- Xarray-like
Training features.
- yarray-like
Training labels.
- n_jobsint, default=1
Number of parallel jobs to run.
- Returns:
- selfNonAggregativeQuantifier
The fitted quantifier instance.
Notes
For binary or inherently multiclass data, the model directly calls
_fit_method
to process the data.For other cases, it creates one quantifier per class using a one-vs-all strategy and fits each quantifier independently in parallel.
- get_metadata_routing()[source]#
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)[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) dict [source]#
Predict class prevalences for the given data.
- Parameters:
- Xarray-like
Test features.
- Returns:
- dict
A dictionary where keys are class labels and values are their predicted prevalences.
Notes
For binary or inherently multiclass data, the model directly calls
_predict_method
.For other cases, it performs one-vs-all prediction, combining the results into a normalized dictionary of class prevalences.
- set_fit_request(*, n_jobs: bool | None | str = '$UNCHANGED$') HDx [source]#
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if 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.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
- n_jobsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
n_jobs
parameter 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.