Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for the FACTS method #533

Merged
merged 6 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aif360/sklearn/detectors/facts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def fit(self, X: DataFrame, verbose: bool = True):
model=self.clf,
sensitive_attribute=self.prot_attr,
freqitem_minsupp=self.freq_itemset_min_supp,
drop_infeasible=False,
feats_not_allowed_to_change=list(feats_not_allowed_to_change),
verbose=verbose,
)
Expand All @@ -358,7 +359,7 @@ def fit(self, X: DataFrame, verbose: bool = True):
params=params,
verbose=verbose,
)
self.rules_by_if = calc_costs(rules_by_if)
self.rules_by_if = calc_costs(rules_by_if, params=params)

self.dataset = X.copy(deep=True)

Expand Down
14 changes: 1 addition & 13 deletions aif360/sklearn/detectors/facts/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pandas import DataFrame

from .parameters import *
from .predicate import Predicate, recIsValid, featureChangePred, drop_two_above
from .predicate import Predicate, recIsValid, featureChangePred
from .frequent_itemsets import run_fpgrowth, preprocessDataset, fpgrowth_out_to_predicate_list
from .metrics import (
incorrectRecoursesIfThen,
Expand Down Expand Up @@ -182,7 +182,6 @@ def valid_ifthens(
freqitem_minsupp: float = 0.01,
missing_subgroup_val: str = "N/A",
drop_infeasible: bool = True,
drop_above: bool = True,
feats_not_allowed_to_change: List[str] = [],
verbose: bool = True,
) -> List[Tuple[Predicate, Predicate, Dict[str, float], Dict[str, float]]]:
Expand All @@ -196,7 +195,6 @@ def valid_ifthens(
freqitem_minsupp (float): Minimum support threshold for frequent itemset mining.
missing_subgroup_val (str): Value indicating missing or unknown subgroup.
drop_infeasible (bool): Whether to drop infeasible if-then rules.
drop_above (bool): Whether to drop if-then rules with feature changes above a certain threshold.
feats_not_allowed_to_change (list[str]): optionally, the user can provide some features which are not allowed to change at all (e.g. sex).
verbose (bool): whether to print intermediate messages and progress bar. Defaults to True.

Expand Down Expand Up @@ -281,16 +279,6 @@ def valid_ifthens(
)
)

# keep ifs that have change on features of max value 2
if drop_above == True:
age = [val.left for val in X.age.unique()]
age.sort()
ifthens = [
(ifs, then, cov)
for ifs, then, cov in ifthens
if drop_two_above(ifs, then, age)
]

# Calculate correctness percentages
if verbose:
print("Computing percentages of individuals flipped by each action independently.", flush=True)
Expand Down
1 change: 0 additions & 1 deletion tests/sklearn/facts/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_rule_generation() -> None:
sensitive_attribute="sex",
freqitem_minsupp=0.5,
drop_infeasible=False,
drop_above=True
)
ifthens = rules2rulesbyif(ifthens)

Expand Down
Loading