NonAggregativeQuantifier#
- class mlquantify.base.NonAggregativeQuantifier[source]#
Abstract base class for non-aggregative quantifiers.
Non-aggregative quantifiers differ from aggregative quantifiers as they do not use an underlying classifier or specific learner for their predictions.
This class defines the general structure and behavior for non-aggregative quantifiers, including support for multiclass data and dynamic handling of binary and multiclass problems.
Notes
This class requires implementing the
_fit_method
and_predict_method
in subclasses to define how the quantification is performed. These methods handle the core logic for fitting and predicting class prevalences.Examples
>>> from myquantify.base import NonAggregativeQuantifier >>> import numpy as np >>> class MyNonAggregativeQuantifier(NonAggregativeQuantifier): ... def _fit_method(self, X, y): ... # Custom logic for fitting ... pass ... def _predict_method(self, X): ... # Custom logic for predicting ... return {0: 0.5, 1: 0.5} >>> quantifier = MyNonAggregativeQuantifier() >>> X = np.random.rand(10, 2) >>> y = np.array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1]) >>> quantifier.fit(X, y) <MyNonAggregativeQuantifier> >>> quantifier.predict(X) {0: 0.5, 1: 0.5}
- 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$') NonAggregativeQuantifier [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.