fair_forge.preprocessing¶
Classes
|
A transformation which is fitted with group information. |
|
A transformation which modifies both the dataset and the labels based on group information. |
|
A pipeline that applies a group-based data modification method followed by an estimator. |
|
|
|
- class fair_forge.preprocessing.GroupBasedTransform(*args, **kwargs)[source]¶
Bases:
_PreprocessorBase,ProtocolA 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 the transformation to the data with group information.
- class fair_forge.preprocessing.GroupDatasetModifier(*args, **kwargs)[source]¶
Bases:
_PreprocessorBase,ProtocolA 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]¶
Transform the data using the fitted preprocessing method. :param X: The data to transform. :param is_train: Whether the data is training data. This can be used to apply :param different transformations to training and test data.: :param is_x: Whether the data is features. This can be used to apply :param different transformations to features and labels.:
- Returns:
The transformed data.
- class fair_forge.preprocessing.GroupPipeline(group_data_modifier: GroupDatasetModifier, estimator: Method, random_state: int | None = None)[source]¶
Bases:
BaseEstimator,GroupMethodA pipeline that applies a group-based data modification method followed by an estimator.
- fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]], *, groups: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]¶
Fit the model to the data, taking group information into account.
- group_data_modifier: GroupDatasetModifier¶
A method to modify the dataset based on group information.
- predict(X: ndarray[tuple[Any, ...], dtype[float32]]) ndarray[tuple[Any, ...], dtype[int32]][source]¶
Predict the labels for the given data.
- set_fit_request(*, groups: bool | None | str = '$UNCHANGED$') GroupPipeline¶
Request metadata passed to the
fitmethod.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 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.
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.
- 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
- class fair_forge.preprocessing.Preprocessor(*args, **kwargs)[source]¶
Bases:
_PreprocessorBase,Protocol
- class fair_forge.preprocessing.Upsampler(strategy: UpsampleStrategy = '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.
- set_fit_request(*, groups: bool | None | str = '$UNCHANGED$') Upsampler¶
Request metadata passed to the
fitmethod.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 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.
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.
- set_transform_request(*, is_train: bool | None | str = '$UNCHANGED$', is_x: bool | None | str = '$UNCHANGED$') Upsampler¶
Request metadata passed to the
transformmethod.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 totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.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:
- Returns:
self – The updated object.
- Return type:
- strategy: UpsampleStrategy = 'uniform'¶
The strategy to use for upsampling. Options are ‘uniform’ and ‘naive’.
- transform(X: ndarray[tuple[Any, ...], dtype], *, is_train: bool = False, is_x: bool = True) ndarray[tuple[Any, ...], dtype][source]¶
Transform the data using the fitted preprocessing method. :param X: The data to transform. :param is_train: Whether the data is training data. This can be used to apply :param different transformations to training and test data.: :param is_x: Whether the data is features. This can be used to apply :param different transformations to features and labels.:
- Returns:
The transformed data.