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

Fairadapt inclusion in AIF360 #257

Merged
merged 15 commits into from
Jan 20, 2022
Merged

Conversation

dplecko
Copy link
Contributor

@dplecko dplecko commented Jul 28, 2021

Hi guys,

Here is a pull request adding three files we mentioned (fairadapt.py, test_fairadapt.py and demo_fairadapt.ipynb).

Most importantly: the installation of the necessary R-packages using rpy2 is currently done from the fairadapt class (check fairadapt.py line 54). I am guessing you would be looking for a better solution, i.e., that R-packages are installed together with AIF. Please just make sure, if this option is used, that we have installed:

  • ranger version 0.13.1
  • fairadapt version 0.2.0

Both of the above are now available via CRAN, which should make installing them using conda much easier!

Thank you in advance for attending to this!

Best,
Drago

@lgtm-com
Copy link

lgtm-com bot commented Jul 28, 2021

This pull request introduces 13 alerts when merging 3ff929e into fcda24e - view on LGTM.com

new alerts:

  • 12 for Unused import
  • 1 for Module is imported more than once

@nrkarthikeyan nrkarthikeyan self-requested a review October 29, 2021 15:34
@nrkarthikeyan
Copy link
Collaborator

Hi @dplecko - can you check the LGTM report above and remove unused imports?

Copy link
Collaborator

@nrkarthikeyan nrkarthikeyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Some changes requested. Thanks for the contribution.

please also modify README to include this method and setup.py (if needed). Can you also run sphinx and check if the documentation compiles properly?

# selectively install the missing packages
names_to_install = [x for x in packnames if not robjects.packages.isinstalled(x)]
if len(names_to_install) > 0:
utils.install_packages(StrVector(names_to_install))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you install this through modification of setup.py as a dependency of fairadapt? Best place is to do this in the extras block and define a new key for fairadapt. If that is not possible since these are r packages, its ok to have them here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this utils package BTW? I do not see a function install_packages in utils.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this the utils package from base R - I have renamed this now to avoid name clashing.

JMLR paper: https://www.jmlr.org/papers/volume21/19-966/19-966.pdf [1]
Github page: https://github.com/dplecko/fairadapt [2]
"""
def __init__(self,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add Attributes here. See https://github.com/Trusted-AI/AIF360/blob/master/aif360/sklearn/postprocessing/calibrated_equalized_odds.py for an example. Attributes are public attributes of the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added prot_attr_ and groups_ - those two seemed sensible.

from aif360.sklearn.utils import check_inputs, check_groups


class fairadapt(BaseEstimator):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the standard docstring formatting as given in https://github.com/Trusted-AI/AIF360/blob/master/aif360/sklearn/postprocessing/calibrated_equalized_odds.py to provide references. Also add may be one more sentence about fairadapt to provide more details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation should now be fixed.

# merge X_train and y_train
df_train = pd.concat([X_train, y_train], axis = 1)

Fairadapt_R = robjects.r(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to have the R object string here or can we define it down below somewhere and use it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the easiest solution... it could done slightly differently, but would not look much better I believe.

utils.install_packages(StrVector(names_to_install))


def fit_transform(self, X_train, y_train, X_test):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to pass X_train and X_test here? Typically we have a separate predict or transform function to process the test data. If this is how fairadapt works, its fine, just wanted to check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the fairadapt workflow does support separating the training and testing; however, when doing so, I would have to be attaching some S3 classes from R to a python object... and would make everything look more wild. I believe this is a good intermediate solution.

@@ -0,0 +1,424 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include a good preamble in the notebook that describes what fairadapt is, how it works, and also what are the steps in the notebook? The more information the better (to the extent possible). We like to keep the notebooks self-contained so that people can start their exploration here. Also, it is good to say what is unique about fairadapt compared to other preproc methods, and what it can do that other methods cannot. This will help users appreciate the novelty of the method.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment applies to individual cells. Please add more information on what each cell does to the extent possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is now expanded with much more detail.

FA = fairadapt.fairadapt(prot_attr = "sex", adj_mat = adj_mat, outcome = "annual-income")
Xf_train, yf_train, Xf_test = FA.fit_transform(X_train, y_train, X_test)

assert isinstance(Xf_train, pd.DataFrame)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some metric to test if fairadapt actually worked as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, no problem, I added a check to see that the metric improved.

@lgtm-com
Copy link

lgtm-com bot commented Nov 2, 2021

This pull request introduces 13 alerts when merging 6236e0f into a5dac73 - view on LGTM.com

new alerts:

  • 12 for Unused import
  • 1 for Module is imported more than once

@lgtm-com
Copy link

lgtm-com bot commented Nov 4, 2021

This pull request introduces 1 alert when merging 580a5a7 into a5dac73 - view on LGTM.com

new alerts:

  • 1 for Unused import

Drago Plecko and others added 5 commits November 5, 2021 17:40
Update component.yaml to kfp v2 compatible. In v2,
you need to declare the data type for all of the input/output
arguments.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>
Signed-off-by: Drago Plecko <www.plecko@gmail.com>
Signed-off-by: SSaishruthi <saishruthi.tn@ibm.com>
Signed-off-by: Drago Plecko <www.plecko@gmail.com>
@lgtm-com
Copy link

lgtm-com bot commented Nov 5, 2021

This pull request introduces 1 alert when merging 59257dd into a5dac73 - view on LGTM.com

new alerts:

  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Nov 17, 2021

This pull request introduces 1 alert when merging f3bf417 into a5dac73 - view on LGTM.com

new alerts:

  • 1 for Unused import

@nrkarthikeyan
Copy link
Collaborator

nrkarthikeyan commented Nov 24, 2021

CI workflows failing at the R interface

@dplecko's analysis:

Fixed several warnings, but the major thing to be solved is the following:
when trying to install fairadapt R-package using rpy2, I come across a problem because the default paths on the machine where the continuous integration is running are not writable
WARNING rpy2.rinterface_lib.callbacks:callbacks.py:123 R[write to console]: 'lib = "/usr/local/lib/R/site-library"' is not writable
for this reason, the installation tries to run interactively and ultimately fails. When running locally, I doubt that this would be a problem.
I was wondering if adding fairadapt to ci.yml would solve the problem? In particular, adding it here:
L81: run: install.packages(c("reticulate", "rstudioapi", "testthat"))
I am wondering if that would help? Not sure if the .libPaths() are shared between rpy2 and default R distribution on the machine.
Alternatively, the package installation could be moved somewhere else. Do you perhaps know how to specify a dependency to an rpy2-R-package directly in setup.py ?

@SSaishruthi @gdequeiroz @hoffmansc - Any thoughts on how to fix this?

@hoffmansc
Copy link
Collaborator

Maybe I'm missing something but do we not need to install R first in the build-py section of ci.yml? i.e.,

- name: Set up R
  uses: r-lib/actions/setup-r@v1

@lgtm-com
Copy link

lgtm-com bot commented Dec 13, 2021

This pull request introduces 1 alert when merging 2faa21e into 963df2e - view on LGTM.com

new alerts:

  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Jan 14, 2022

This pull request introduces 1 alert when merging c74d08f into 963df2e - view on LGTM.com

new alerts:

  • 1 for Unused import

Signed-off-by: Samuel Hoffman <hoffman.sc@gmail.com>
Signed-off-by: Samuel Hoffman <hoffman.sc@gmail.com>
@lgtm-com
Copy link

lgtm-com bot commented Jan 14, 2022

This pull request introduces 1 alert when merging a75a356 into 963df2e - view on LGTM.com

new alerts:

  • 1 for Unused import

added 'plotting' option to igraph

Signed-off-by: Samuel Hoffman <hoffman.sc@gmail.com>
Signed-off-by: Samuel Hoffman <hoffman.sc@gmail.com>
@lgtm-com
Copy link

lgtm-com bot commented Jan 14, 2022

This pull request introduces 1 alert when merging b8f809f into 963df2e - view on LGTM.com

new alerts:

  • 1 for Unused import

Signed-off-by: Samuel Hoffman <hoffman.sc@gmail.com>
Signed-off-by: Samuel Hoffman <hoffman.sc@gmail.com>
@lgtm-com
Copy link

lgtm-com bot commented Jan 20, 2022

This pull request introduces 2 alerts when merging 17183f3 into 963df2e - view on LGTM.com

new alerts:

  • 2 for Unused import

@hoffmansc hoffmansc merged commit bfd0161 into Trusted-AI:master Jan 20, 2022
Illia-Kryvoviaz pushed a commit to Illia-Kryvoviaz/AIF360 that referenced this pull request Jun 7, 2023
* Fairadapt code, demo and test
* remove numpy 1.19.5 pin
* deprecate python 3.6 and support 3.9

Co-authored-by: Drago Plecko <drago.plecko@stat.math.ethz.ch>
Co-authored-by: nrkarthikeyan <knatesan@asu.edu>
Co-authored-by: Samuel Hoffman <hoffman.sc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants