FairSplitter#
- class FairSplitter(penalty: str = None, sensible_attribute: int = -1, penalization_weight: float = 0.3, ideal_distribution: dict = None, k_anonymity: int | float = 2, l_diversity: int | float = 2, t_closeness: float = 0.2, strict: bool = True, use_t: bool = True, criterion='squared_error')[source]#
Bases:
FlatMatrixRegressionSplitterSplitter for regression that maximizes the gain penalized by the unfairness of the split with respect to a sensitive attribute.
The candidates are the thresholds of the numerical features, the sensitive attribute excluded, evaluated together as in FlatMatrixRegressionSplitter; the gain of a candidate is
sigmoid(gain) * (1 - penalty * penalization_weight), where the penalty measures how unfair the children are.- Parameters:
penalty ({'balance', 'mfc', 'privacy'}, default=None) –
Fairness criterion, which penalizes the gain of the splits:
’balance’: the children should have the same distribution of the sensitive attribute (statistical parity);
’mfc’: maximum fairness cost with respect to
ideal_distribution;’privacy’: the children must satisfy k-anonymity, l-diversity and t-closeness on the sensitive attribute (with
strict=True, the splits that violate them are discarded).
sensible_attribute (int, default=-1) – Column of the data with the sensitive attribute. It is never used by the splits.
penalization_weight (float, default=0.3) – Weight of the penalty: the gain of a split is
sigmoid(gain) * (1 - penalty * weight).ideal_distribution (dict, default=None) – Value of the sensitive attribute -> ideal fraction, required by penalty=’mfc’.
k_anonymity (int or float, default=2) – Minimum number of instances in each child (penalty=’privacy’).
l_diversity (int or float, default=2) – Minimum number of distinct values of the sensitive attribute in each child (penalty=’privacy’).
t_closeness (float, default=0.2) – Maximum distance between the distribution of the sensitive attribute in a child and in the node (penalty=’privacy’).
strict (bool, default=True) – Whether the privacy constraints discard the splits that violate them, instead of only penalizing them.
use_t (bool, default=True) – Whether t-closeness is part of the privacy constraints.
criterion ({'squared_error', 'poisson'}, default='squared_error') – Impurity measure (see FlatMatrixRegressionSplitter).
- Variables:
feature (int) – Column of the feature matrix used by the split.
threshold (float) – Threshold of the split.
is_categorical (bool) – Whether the split is categorical (always False).
gain (float) – Penalized gain of the split.
impurity (list of float) – Impurity of the node, of the left child and of the right child.
See also
FairTreeStumpRegressorthe stump made of a MatrixTransformer and this splitter.
Examples
>>> import numpy as np >>> from sklearn.datasets import load_diabetes >>> from RuleTree import RuleTreeRegressor >>> from RuleTree.stumps.Stump import Stump >>> from RuleTree.stumps.splitters import FairSplitter >>> from RuleTree.stumps.transformers import MatrixTransformer >>> X, y = load_diabetes(return_X_y=True) >>> X = np.column_stack([X, X[:, 1] > 0]) # last column: the sensitive attribute >>> splitter = FairSplitter(penalty="balance", sensible_attribute=-1) >>> model = RuleTreeRegressor(max_depth=2, base_stumps=Stump(MatrixTransformer(), splitter)).fit(X, y)
- fit(X, y, numerical, categorical, sample_weight=None, check_input=True, *, context, node_id, cache)[source]#
Find the split with the highest penalized gain among the thresholds of the numerical features (the sensitive attribute excluded); see FlatMatrixSplitter.fit for the parameters.
- Returns:
self – The fitted splitter.
- Return type:
- Raises:
NoSplitFoundWarning – If no split is found, e.g. all of them violate the privacy constraints.
ValueError – If y has several targets.