AggregativeBootstrap#
- class mlquantify.meta.AggregativeBootstrap(quantifier, n_train_bootstraps=1, n_test_bootstraps=1, random_state=None, region_type='intervals', confidence_level=0.95)[source]#
Aggregative Bootstrap Quantifier to compute prevalence confidence regions.
This metaquantifier applies bootstrapping to both training and test data predictions to generate multiple bootstrap prevalence estimates. These bootstrapped estimates are used to construct confidence intervals or elliptical confidence regions for prevalence predictions, improving uncertainty quantification.
- Parameters:
- quantifierBaseQuantifier
The base quantifier model, which must be aggregative.
- n_train_bootstrapsint, default=1
Number of bootstrap samples to generate from training predictions.
- n_test_bootstrapsint, default=1
Number of bootstrap samples to generate from test predictions.
- random_stateint or None, optional
Random seed for reproducibility.
- region_type{‘intervals’, ‘ellipse’, ‘ellipse-clr’}, default=’intervals’
Type of confidence region to construct.
- confidence_levelfloat between 0 and 1, default=0.95
Confidence level for intervals or regions.
Examples
>>> from mlquantify.ensemble import AggregativeBootstrap >>> from mlquantify.neighbors import EMQ >>> from sklearn.ensemble import RandomForestClassifier >>> agg_boot = AggregativeBootstrap( ... quantifier=EMQ(RandomForestClassifier()), ... n_train_bootstraps=100, ... n_test_bootstraps=100 ... ) >>> agg_boot.fit(X_train, y_train) >>> prevalence, conf_region = agg_boot.predict(X_test)
- aggregate(predictions, train_predictions, train_y_values)[source]#
Aggregates the predictions using bootstrap resampling.
- Parameters:
- predictionsarray-like of shape (n_samples, n_classes)
The input data.
- train_predictionsarray-like of shape (n_samples, n_classes)
The training predictions.
- train_y_valuesarray-like of shape (n_samples,)
The training target values.
- Returns:
- prevalencesarray-like of shape (n_samples, n_classes)
The predicted class prevalences.
- fit(X, y, val_split=None)[source]#
Fits the aggregative bootstrap model to the given training data.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
The input data.
- yarray-like of shape (n_samples,)
The target values.
- Returns:
- selfAggregativeBootstrap
The fitted aggregative bootstrap model.
- Raises:
- ValueError
If the provided quantifier is not an aggregative 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]#
Predicts the class prevalences for the given test data.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
The input data.
- Returns:
- prevalencesarray-like of shape (n_samples, n_classes)
The predicted class prevalences.
- set_fit_request(*, val_split: bool | None | str = '$UNCHANGED$') AggregativeBootstrap[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:
- val_splitstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
val_splitparameter 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.