aif360.sklearn.preprocessing.ReweighingMeta

class aif360.sklearn.preprocessing.ReweighingMeta(estimator, reweigher=None)[source]

A meta-estimator which wraps a given estimator with a reweighing preprocessing step.

This is necessary for use in a Pipeline, etc.

Variables:
  • estimator_ (sklearn.BaseEstimator) – The fitted underlying estimator.

  • reweigher_ – The fitted underlying reweigher.

  • classes_ (array, shape (n_classes,)) – Class labels from estimator_.

Parameters:
  • estimator (sklearn.BaseEstimator) – Estimator to be wrapped.

  • reweigher (optional) – Preprocessor which returns new sample weights from transform(). If None, defaults to Reweighing.

Methods

fit

Performs self.reweigher_.fit_transform(X, y, sample_weight) and then self.estimator_.fit(X, y, sample_weight) using the reweighed samples.

get_metadata_routing

Get metadata routing of this object.

get_params

Get parameters for this estimator.

predict

Predict class labels for the given samples using self.estimator_.

predict_log_proba

Log of probability estimates from self.estimator_.

predict_proba

Probability estimates from self.estimator_.

score

Returns the output of the estimator's score function on the given test data and labels.

set_fit_request

Request metadata passed to the fit method.

set_params

Set the parameters of this estimator.

set_score_request

Request metadata passed to the score method.

Attributes

classes_

Class labels from the base estimator.

__init__(estimator, reweigher=None)[source]
Parameters:
  • estimator (sklearn.BaseEstimator) – Estimator to be wrapped.

  • reweigher (optional) – Preprocessor which returns new sample weights from transform(). If None, defaults to Reweighing.

property classes_

Class labels from the base estimator.

fit(X, y, sample_weight=None)[source]

Performs self.reweigher_.fit_transform(X, y, sample_weight) and then self.estimator_.fit(X, y, sample_weight) using the reweighed samples.

Parameters:
  • X (pandas.DataFrame) – Training samples.

  • y (array-like) – Training labels.

  • sample_weight (array-like, optional) – Sample weights.

Returns:

self

predict(X)[source]

Predict class labels for the given samples using self.estimator_.

Parameters:

X (array-like) – Test samples.

Returns:

array – Predicted class label per sample.

predict_log_proba(X)[source]

Log of probability estimates from self.estimator_.

The returned estimates for all classes are ordered by the label of classes.

Parameters:

X (array-like) – Test samples.

Returns:

array – Returns the log-probability of the sample for each class in the model, where classes are ordered as they are in self.classes_.

predict_proba(X)[source]

Probability estimates from self.estimator_.

The returned estimates for all classes are ordered by the label of classes.

Parameters:

X (array-like) – Test samples.

Returns:

array – Returns the probability of the sample for each class in the model, where classes are ordered as they are in self.classes_.

score(X, y, sample_weight=None)[source]

Returns the output of the estimator’s score function on the given test data and labels.

Parameters:
  • X (array-like) – Test samples.

  • y (array-like) – True labels for X.

  • sample_weight (array-like, optional) – Sample weights.

Returns:

floatself.estimator.score(X, y, sample_weight)

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') ReweighingMeta[source]

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see 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.

New 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:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

Returns:

self (object) – The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') ReweighingMeta[source]

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score 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 score.

  • 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.

New 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:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self (object) – The updated object.