fair_forge.methods

Protocols and implementations of methods for fairness-aware machine learning.

Classes

Blind(…)

A Random classifier.

FairnessType(…)

GroupMethod(…)

Majority(…)

Simply returns the majority label from the train set.

Method(…)

Reweighting(…)

An implementation of the Reweighing method from Kamiran&Calders, 2012.

SampleWeightMethod(…)

class fair_forge.methods.Blind(random_state: int = 0)[source]

Bases: BaseEstimator, Method

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

get_params(deep: bool = True) dict[str, object][source]

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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

Predict a random label for all samples.

random_state: int = 0
class fair_forge.methods.FairnessType(*values)[source]

Bases: Enum

DP = 'dp'

Demographic Parity (DP)

EQ_ODDS = 'eq_odds'

Equalized Odds (EQ_ODDS)

EQ_OPP = 'eq_opp'

Equal Opportunity (EQ_OPP)

class fair_forge.methods.GroupMethod(*args, **kwargs)[source]

Bases: _MethodBase, Protocol

fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]], *, groups: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]
class fair_forge.methods.Majority(random_state: None = None)[source]

Bases: BaseEstimator, Method

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

get_params(deep: bool = True) dict[str, object][source]

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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

Predict the majority class for all samples.

random_state: None = None
class fair_forge.methods.Method(*args, **kwargs)[source]

Bases: _MethodBase, Protocol

fit(X: ndarray[tuple[Any, ...], dtype[float32]], y: ndarray[tuple[Any, ...], dtype[int32]]) Self[source]
class fair_forge.methods.Reweighting(base_method: SampleWeightMethod)[source]

Bases: BaseEstimator, GroupMethod

An implementation of the Reweighing method from Kamiran&Calders, 2012.

Parameters:

base_method – The method to use for fitting and predicting. It should implement the SampleWeightMethod protocol.

base_method: SampleWeightMethod
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.

get_params(deep: bool = True) dict[str, object][source]

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

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

class fair_forge.methods.SampleWeightMethod(*args, **kwargs)[source]

Bases: _MethodBase, Protocol

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