fair_forge.methods¶
Protocols and implementations of methods for fairness-aware machine learning.
Classes
|
A Random classifier. |
|
|
|
Simply returns the majority label from the train set. |
|
|
|
An implementation of the Reweighing method from Kamiran&Calders, 2012. |
|
- class fair_forge.methods.Blind(random_state: int = 0)[source]¶
Bases:
BaseEstimator,MethodA Random classifier.
This is useful as a baseline method and operates a ‘coin flip’ to assign a label. Returns a random label.
- fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]¶
Fit the model by storing the classes.
- class fair_forge.methods.Majority(random_state: None = None)[source]¶
Bases:
BaseEstimator,MethodSimply returns the majority label from the train set.
- fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]¶
Fit the model by storing the majority class.
- class fair_forge.methods.Reweighting(base_method: SampleWeightMethod)[source]¶
Bases:
BaseEstimator,GroupMethodAn implementation of the Reweighing method from Kamiran&Calders, 2012.
- base_method: SampleWeightMethod¶
The method to use for fitting and predicting.
It should implement the SampleWeightMethod protocol.
- fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]], *, groups: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]¶
Fit the model with reweighting based on group information.
- predict(X: ndarray[tuple[Any, ...], dtype[float32]]) ndarray[tuple[Any, ...], dtype[int32]][source]¶
Predict using the fitted model.
- set_fit_request(*, groups: bool | None | str = '$UNCHANGED$') Reweighting¶
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.