Skip to main content

Python wrappers around the R 'dsld' package via rpy2

Project description

dsldPy — Python Interface to DSLD

Statistical and graphical tools for detecting and measuring discrimination and bias in datasets, Python interfaces available via rpy2. dsldPy wraps the R package dsld with a Python-friendly API using the same underlying R implementations.

Relevant links:

  • Quarto Book: Paper - Important statistical principles and applications.
  • Research Paper: Paper - Package implementation details.

Overview

DSLD addresses two main types of bias analysis:

  • Estimation analysis: quantify possible discrimination by estimating effects of a sensitive variable S on an outcome Y, while adjusting for confounders C.

  • Prediction analysis (fair ML): build predictive models that limit the influence of S and its proxies O, trading off fairness and utility.

dsldPy provides wrappers for all 24 R functions.

Prerequisites

  • R installed and on PATH (R 4.x recommended)
  • R package dsld installed (CRAN or GitHub)
  • Python 3.8+

Install dsld in R:

install.packages("dsld")

## or latest development version
# install.packages("remotes")
remotes::install_github("matloff/dsld", force = TRUE)

Tip: Ensure rpy2 can find R. From a terminal: R RHOME should print your R home. If Python cannot find R, set R_HOME in your environment per rpy2’s documentation.

Installation

Install the Python package from this repository (subdirectory inst):

pip install dsldPy

This will install dsldPy and its Python dependencies (pandas, numpy, rpy2, etc.). The user still needs to manually download R and the dsld package, as noted above.

Quickstart

Please refer to the instructional jupyter notebooks provided under examples/ folder. These illustrate examples of all 24 dsldPy functions.

Jupyter notebooks are available in this repository:

  • inst/examples/graphical.ipynb
  • inst/examples/tabular.ipynb
  • inst/examples/machine_learning.ipynb

Available Wrappers

  • Analytical: dsldPyLinear, dsldPyLogit, dsldPyML, dsldPyMatchedATE, dsldPyTakeALookAround, dsldPyConfounders, dsldPyCHunting, dsldPyOHunting

  • Fair ML: dsldPyFrrm, dsldPyFgrrm, dsldPyNclm, dsldPyZlm, dsldPyZlrm, dsldPyQeFairKNN, dsldPyQeFairRF, dsldPyQeFairRidgeLin, dsldPyQeFairRidgeLog, , dsldPyFairUtils

  • Graphical: dsldPyFreqPCoord, dsldPyScatterPlot3D, dsldPyConditDisparity, dsldPyDensitybyS, dsldPyFrequencybyS, dsldPyIamb

Function names mirror the R package. Arguments use standard Python types (pandas.DataFrame, dict, bool, etc.) with the same call forms as the R functions.

Troubleshooting

  • rpy2 cannot find R: confirm R RHOME works; if not, add R to PATH or set R_HOME. See rpy2 docs for your OS.
  • dsld not installed in R: run install.packages("dsld") in an R session.

Authors

  • Norm Matloff
  • Aditya Mittal
  • Taha Abdullah
  • Arjun Ashok
  • Shubhada Martha
  • Billy Ouattara
  • Jonathan Tran
  • Brandon Zarate

For issues, contact Aditya Mittal at mittalaa@uci.edu

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dsldpy-0.0.3.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dsldpy-0.0.3-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file dsldpy-0.0.3.tar.gz.

File metadata

  • Download URL: dsldpy-0.0.3.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for dsldpy-0.0.3.tar.gz
Algorithm Hash digest
SHA256 d24fe36f8a86a2ad40ec8cb810138d7e33651c669736563b017040892700b0a8
MD5 d88f7821b167c4798928d4fc9a1ea99e
BLAKE2b-256 8f853a6e493c113ef2daef66a54ef0a41ae330af1244d3741cb633eb0fe80823

See more details on using hashes here.

File details

Details for the file dsldpy-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: dsldpy-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for dsldpy-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e266d2c3632353313efbe0fa652fcb6f03f21068af32b0726317e781da26561e
MD5 06ae0be76fd0fce530bf2cd1c25a8e98
BLAKE2b-256 aa9f059705cc218f8094d9754eab1188ab0b9f2db835524011e2a931c87cc5dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page