FairTreeStumpRegressor#
- class FairTreeStumpRegressor(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:
DecisionTreeStumpRegressorFair stump for regression: the threshold on a numerical feature with the highest gain, penalized by how unfair the split is with respect to a sensitive attribute.
The sensitive attribute is a column of the data (
sensible_attribute), never used by the splits. The fairness criterion (penalty) is statistical parity of the children, a maximum fairness cost with respect to an ideal distribution, or privacy constraints (k-anonymity, l-diversity, t-closeness). It is aStumpmade of a MatrixTransformer and a FairSplitter; it supports only tabular data.- 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:
transformer (MatrixTransformer) – The fitted transformer.
splitter (FairSplitter) – The fitted splitter (feature, threshold, gain and impurity of the split).
data_type (str) – Data type the stump was fitted on.
feature_original (int) – Column of the data used by the split.
threshold_original (float) – Threshold of the split.
See also
FairSplitterthe splitter, usable with other transformers (e.g. pivots).
Examples
>>> import numpy as np >>> from sklearn.datasets import load_diabetes >>> from RuleTree.stumps.regression import FairTreeStumpRegressor >>> X, y = load_diabetes(return_X_y=True) >>> X = np.column_stack([X, X[:, 1] > 0]) # last column: the sensitive attribute >>> stump = FairTreeStumpRegressor(penalty="balance", sensible_attribute=-1) >>> stump = stump.fit(X, y, context=None, node_id=None, cache=None) >>> stump.get_rule()["textual_rule"] 'X_4 <= -0.03'
- supported_data_types = ('tabular',)#