Multi-Output Calibrated Classifier

class snapml.MultiOutputCalibratedClassifier(estimator, *, n_jobs=None)

Multi Output Calibrated Classifier used for multi-target classification.

This model fits one classifier per target. It can be used for classifiers that do not have native support for multi-target classification.

Parameters:
estimatorestimator object

A scikit-learn CalibratedClassifierCV object.

n_jobsint or None, optional (default=None)

The number of jobs to run in parallel. fit() and predict() will be parallelized for each target. When individual estimators are fast to train or predict, using n_jobs > 1 can result in slower performance due to the parallelism overhead. None means 1 unless in a joblib.parallel_backend context. -1 means using all available processes / threads.

Attributes:
classes_ndarray of shape (n_classes,)

Class labels.

estimators_list of n_output estimators

Estimators used for predictions.

n_features_in_int

Number of features seen during fit. Only defined if the underlying base_estimator of the CalibratedClassifierCV estimator exposes such an attribute when fit.

feature_names_in_ndarray of shape (n_features_in_,)

Names of features seen during fit. Only defined if the underlying base_estimator of the CalibratedClassifierCV estimator exposes such an attribute when fit.

fit(X, Y, sample_weight=None, optimize_for_inference=True, **fit_params)

Fit the model to the feature matrix X and labels Y.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

The train data.

Yarray-like of shape (n_samples, n_classes)

The train labels.

sample_weightarray-like of shape (n_samples,), default=None

The sample weights. If None, all samples have the same weight. Only supported if the underlying classifier supports sample weights.

optimize_for_inferencebool, default=True

If True, save the model and calibration coefficients as attributes to be used at predict_proba time. It is recommended to use the default setting for performance-optimized inference.

**fit_paramsdict of string -> object

Parameters passed to the estimator.fit method of each step.

Returns:
selfobject

Returns a fitted instance.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Added in version 1.3.

Returns:
routingMetadataRouter

A MetadataRouter encapsulating routing information.

get_params(deep=True)

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.

partial_fit(X, y, classes=None, sample_weight=None, **partial_fit_params)

Incrementally fit a separate model for each class output.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

The input data.

y{array-like, sparse matrix} of shape (n_samples, n_outputs)

Multi-output targets.

classeslist of ndarray of shape (n_outputs,), default=None

Each array is unique classes for one output in str/int. Can be obtained via [np.unique(y[:, i]) for i in range(y.shape[1])], where y is the target matrix of the entire dataset. This argument is required for the first call to partial_fit and can be omitted in the subsequent calls. Note that y doesn’t need to contain all labels in classes.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.

**partial_fit_paramsdict of str -> object

Parameters passed to the estimator.partial_fit method of each sub-estimator.

Only available if enable_metadata_routing=True. See the User Guide.

Added in version 1.3.

Returns:
selfobject

Returns a fitted instance.

predict(X)

Predict multi-output variable using model for each target variable.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

The input data.

Returns:
y{array-like, sparse matrix} of shape (n_samples, n_outputs)

Multi-output targets predicted across multiple predictors. Note: Separate models are generated for each predictor.

predict_proba(X)

Predict class probabilities for each output.

Parameters:
Xarray-like of shape (n_samples, n_features)

The input data.

Returns:
parray of shape (n_samples, n_classes)

The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

score(X, y)

Return the mean accuracy on the given test data and labels.

Parameters:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples, n_outputs)

True values for X.

Returns:
scoresfloat

Mean accuracy of predicted target versus true target.

set_fit_request(*, optimize_for_inference: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$') MultiOutputCalibratedClassifier

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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:
optimize_for_inferencestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for optimize_for_inference parameter in fit.

sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns:
selfobject

The updated object.

set_params(**params)

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.

set_partial_fit_request(*, classes: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$') MultiOutputCalibratedClassifier

Configure whether metadata should be requested to be passed to the partial_fit method.

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 (see sklearn.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 to partial_fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to partial_fit.

  • 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:
classesstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for classes parameter in partial_fit.

sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in partial_fit.

Returns:
selfobject

The updated object.