ustunb / actionable-recourse

python tools to check recourse in linear classification
BSD 3-Clause "New" or "Revised" License
75 stars 19 forks source link

Issue in Example usage code #20

Open Dhananjana97 opened 4 years ago

Dhananjana97 commented 4 years ago

After setting up the library I executed the notebook in the usage section and it gives, AttributeError: 'ActionSet' object has no attribute 'align' how to fix this issue?

wangyongjie-ntu commented 3 years ago

@Dhananjana97

I found there is not align function in the action_set.py file. So I just comment this line.

The list operation on A is not supported. I modify it as

- A[['Age_lt_25', 'Age_in_25_to_40', 'Age_in_40_to_59', 'Age_geq_60']].mutable = False
+ A['Age_lt_25'].mutable = False                                                                                                                                                                                                               
+ A['Age_in_25_to_40'].mutable = False
+ A['Age_in_40_to_59'].mutable = False
+ A['Age_geq_60'].mutable = False

It works for me, at least can return some results.

iamthomaswin commented 11 months ago

Might be a bit late to the party, but you might want to install 0.1.1 version of actionable-recourse by doing: pip install actionable-recourse==0.1.1. This version has got the align method implemented. Hope this helps.

knaggita commented 9 months ago

Agree with @iamthomaswin, there is a function in def align in the action_set.py file that's included in actionable-recourse==0.1.1. but is not reflected in the version on this repo Instead of adding this function, you can instead use the similarly defined set_alignment function

def align(self, *args, **kwargs):
    """
    adjusts direction of recourse for each element in action set
    :param clf: scikit-learn classifier or vector of coefficients
    :return:
    """
    coefs, _ = parse_classifier_args(*args, **kwargs)
    assert len(coefs) == len(self)
    flips = np.sign(coefs)
    for n, j in self._indices.items():
        self._elements[n].flip_direction = flips[j]

Also, if you're using newer versions of pandas, append function nolonger works.

Edit this line the flipset.py self._df = self._df.append(row_data, ignore_index = True, sort = True)[self._df.columns.tolist()]

to this/better

     dfx = pd.DataFrame(row_data)         
     dfx2 = dfx[self._df.columns.tolist()]
     self._df = pd.concat([self._df, dfx2], ignore_index=True)