Git Product home page Git Product logo

actionable-recourse's Introduction

actionable-recourse is a python library to check recourse in linear classification models.

Recourse?

Recourse is the ability to flip the prediction of a ML model by changing actionable input variables (e.g., income instead of age).

When should models provide recourse?

Recourse is an important element of human-facing applications of ML.

In tasks such as lending, ML models should provide all individuals with an actionable way to change their prediction.

In other tasks, models should let individuals flip their predictions based on specific types of changes. A recidivism prediction model that includes age, for example, should let a person who is predicted to recidivate with the ability to flip their prediction without having to alter age.

Highlights

The tools in this library let you check recourse without interfering in model development.

They can answer questions like:

  • What can a person do to obtain a favorable outcome from a model?
  • How many people can change their prediction?
  • How difficult for people to change their prediction?

Functionality

  • Specify a custom set of feasible actions for each input variable of an ML model.
  • Generate actionable changes for a person to flip the prediction of a linear classifier.
  • Determine the feasibility of recourse of a linear classifier on a population of interest.
  • Evaluate the difficulty of recourse for a linear classifier on a population of interest.

Usage

import recourse as rs
import sys; sys.path.append('examples/paper')
from initialize import *
data, scaler = load_data()

# train a classifier
clf = LogisticRegression().fit(data['X_train'], data['y'])
yhat = clf.predict(X = data['X_train'])
      
# customize the set of actions
A = rs.ActionSet(X = data['X'])                          ## matrix of features. ActionSet will learn default bounds and step-size.
A['Age'].mutable = False                                 ## forces "age" to be immutable
A['CriticalAccountOrLoansElsewhere'].step_direction = -1 ## force conditional immutability.
A['LoanDuration'].step_type ="absolute"                  ## discretize on absolute values of feature rather than percentile values
A['LoanDuration'].bounds = (1, 100)                      ## set bounds to a custom value.
A['LoanDuration'].step_size = 6                          ## set step-size to a custom value.

## get model coefficients and align
w, b = undo_coefficient_scaling(clf, scaler = data['scaler'])
action_set.align(w)                                     ## tells `ActionSet` which directions each feature should move in to produce positive change.

# Get one individual
predicted_neg = np.flatnonzero(yhat < 1)
U = data['X'].iloc[predicted_neg].values

# build a flipset for one individual
fs = rs.Flipset(x = U[0], action_set = A, coefficients = w, intercept = b)
fs.populate(enumeration_type = 'distinct_subsets', total_items = 10)
fs.to_latex()
fs.to_html()

# Run Recourse Audit on Training Data
auditor = rs.RecourseAuditor(action_set, coefficients = w, intercept = b)
audit_df = auditor.audit(X = data['X']) ## matrix of features over which we will perform the audit.

## print mean feasibility and cost of recourse
print(audit_df['feasible'].mean())
print(audit_df['cost'].mean())

Installation

The latest release can be installed via pip by running:

$ pip install actionable-recourse

Requirements

CPLEX

CPLEX is fast optimization solver with a Python API. It is commercial software, but free to download for students and faculty at accredited institutions. To obtain CPLEX:

  1. Register for IBM OnTheHub
  2. Download the IBM ILOG CPLEX Optimization Studio from the software catalog
  3. Install the CPLEX Optimization Studio.
  4. Setup the CPLEX Python API as described here.

If you have problems installing CPLEX, please check the CPLEX user manual or the CPLEX forums.

CBC + Pyomo

If you do not want to use CPLEX, you can also work with an open-source solver. In this case, complete the following steps before you install the library:

  1. Download and install CBC from Bintray
  2. Download and install pyomo and pyomo-extras (instructions)

Contributing

We're actively working to improve this package and make it more useful. If you come across bugs, have comments, or want to help, let us know. We welcome any and all contributions! For more info on how to contribute, check out these guidelines. Thank you community!

Roadmap

Reference

For more about recourse and these tools, check out our paper:

Actionable Recourse in Linear Classification

inproceedings{ustun2019recourse,
     title = {Actionable Recourse in Linear Classification},
     author = {Ustun, Berk and Spangher, Alexander and Liu, Yang},
     booktitle = {Proceedings of the Conference on Fairness, Accountability, and Transparency},
     series = {FAT* '19},
     year = {2019},
     isbn = {978-1-4503-6125-5},
     location = {Atlanta, GA, USA},
     pages = {10--19},
     numpages = {10},
     url = {http://doi.acm.org/10.1145/3287560.3287566},
     doi = {10.1145/3287560.3287566},
     publisher = {ACM},
}

actionable-recourse's People

Contributors

alex2awesome avatar aspanghe avatar ustunb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.