fair_forge.preprocessing

Classes

GroupBasedTransform(…)

A transformation which is fitted with group information.

GroupDatasetModifier(…)

A transformation which modifies both the dataset and the labels based on group information.

GroupPipeline(…)

Preprocessor(…)

UpsampleStrategy(…)

Strategy for upsampling.

Upsampler(…)

class fair_forge.preprocessing.GroupBasedTransform(*args, **kwargs)[source]

Bases: _PreprocessorBase, Protocol

A transformation which is fitted with group information.

fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]], *, groups: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]
fit_transform(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]], *, groups: ndarray[tuple[Any, ...], dtype[int32]]) ndarray[tuple[Any, ...], dtype[float32]][source]
transform(X: ndarray[tuple[Any, ...], dtype[float32]]) ndarray[tuple[Any, ...], dtype[float32]][source]
class fair_forge.preprocessing.GroupDatasetModifier(*args, **kwargs)[source]

Bases: _PreprocessorBase, Protocol

A transformation which modifies both the dataset and the labels based on group information.

fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]], *, groups: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]

Fit the preprocessing method to the data with group information.

transform(X: ndarray[tuple[Any, ...], dtype], *, is_train: bool = False, is_x: bool = False) ndarray[tuple[Any, ...], dtype][source]
class fair_forge.preprocessing.GroupPipeline(group_data_modifier: fair_forge.preprocessing.definitions.GroupDatasetModifier, estimator: fair_forge.methods.Method, random_state: int | None = None)[source]

Bases: BaseEstimator, GroupMethod

estimator: Method
fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]], *, groups: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]
group_data_modifier: GroupDatasetModifier
predict(X: ndarray[tuple[Any, ...], dtype[float32]]) ndarray[tuple[Any, ...], dtype[int32]][source]
random_state: int | None = None
set_fit_request(*, groups: bool | None | str = '$UNCHANGED$') GroupPipeline

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.

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:

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

Returns:

self – The updated object.

Return type:

object

set_params(**params: Any) Self[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:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

update_random_state() None[source]
class fair_forge.preprocessing.Preprocessor(*args, **kwargs)[source]

Bases: _PreprocessorBase, Protocol

fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]

Fit the preprocessor to the data.

transform(X: ndarray[tuple[Any, ...], dtype[float32]]) ndarray[tuple[Any, ...], dtype[float32]][source]

Transform the data using the fitted preprocessor.

class fair_forge.preprocessing.UpsampleStrategy(*values)[source]

Bases: Enum

Strategy for upsampling.

NAIVE = 'naive'
UNIFORM = 'uniform'
class fair_forge.preprocessing.Upsampler(strategy: fair_forge.preprocessing.group_pre_method.UpsampleStrategy = <UpsampleStrategy.UNIFORM: 'uniform'>, random_state: int = 0)[source]

Bases: BaseEstimator, GroupDatasetModifier

fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]], *, groups: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]

Fit the preprocessing method to the data with group information.

random_state: int = 0
set_fit_request(*, groups: bool | None | str = '$UNCHANGED$') Upsampler

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.

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:

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

Returns:

self – The updated object.

Return type:

object

set_transform_request(*, is_train: bool | None | str = '$UNCHANGED$', is_x: bool | None | str = '$UNCHANGED$') Upsampler

Request metadata passed to the transform 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 transform 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 transform.

  • 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:
  • is_train (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for is_train parameter in transform.

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

Returns:

self – The updated object.

Return type:

object

strategy: UpsampleStrategy = 'uniform'
transform(X: ndarray[tuple[Any, ...], dtype], *, is_train: bool = False, is_x: bool = True) ndarray[tuple[Any, ...], dtype][source]