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()
. IfNone
, defaults toReweighing
.
Methods
Performs
self.reweigher_.fit_transform(X, y, sample_weight)
and thenself.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 class labels for the given samples using
self.estimator_
.Log of probability estimates from
self.estimator_
.Probability estimates from
self.estimator_
.Returns the output of the estimator's score function on the given test data and labels.
Request metadata passed to the
fit
method.set_params
Set the parameters of this estimator.
Request metadata passed to the
score
method.Attributes
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()
. IfNone
, defaults toReweighing
.
- 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 thenself.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:
float –
self.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
(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.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 infit
.- 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
(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 toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.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 inscore
.- Returns:
self (object) – The updated object.