Skip to main content

Tests flake8,mypy Documentation Status

CFEC

This is a specialized programming library which contains three different counterfactual generation methods for tabular data, supporting various constraints, and to construct a tool for comparing their results.

Requirements

Tha package has been tested under python 3.7 up to 3.9, on both Windows and Ubuntu platforms. Its main dependency is tensorflow, which all the methods use, and typical scientific stack (numpy, scipy, pandas). Requirements include:

  • tensorflow~=2.7.0
  • pandas==1.3.4
  • numpy==1.21.4
  • scikit-learn==1.0.1

Installation

This package can be installed using pip

pip install cfec

Implemented algorithms

Our package includes implementation of algorithms, such as:

Example usage

from cfec.explainers import Fimap
from cfec.constraints import ValueMonotonicity, ValueNominal
from data import AdultData
from sklearn.ensemble import RandomForestClassifier

adult_data = AdultData('data/datasets/adult.csv')

rf = RandomForestClassifier()
rf.fit(adult_data.X_train, adult_data.y_train)

predictions = rf.predict(adult_data.X_train)

constraints = [
    OneHot('workclass', 2, 8),
    OneHot('martial.status', 9, 15),
    OneHot('occupation', 16, 29),
    OneHot('race', 30, 34),
    OneHot('sex', 35, 36),
]

fimap = Fimap(constraints=constraints)

fimap.fit(adult_data.X_train, predictions)

x = adult_data.X_train.iloc[0]
cf = fimap.generate(x)
from cfec.explainers import Cadex
from cfec.constraints import ValueMonotonicity, ValueNominal
from data import GermanData
from tensorflow import keras

german_data = GermanData('data/datasets/input_german.csv', 'data/datasets/labels_german.csv')

# simple model consisting of one dense layer with 2 units and a softmax activation
german_model = keras.models.load_model('models/model_german')

predictions = german_model.predict(german_data.X_train)

constraints = [
    OneHot("account_status", 7, 10), 
    OneHot("credit_history", 11, 15),
    OneHot("purpose", 16, 25), 
    OneHot("savings", 26, 30), 
    OneHot("sex_status", 31, 34),
    OneHot("debtors", 35, 37), 
    OneHot("property", 38, 41),
    OneHot("other_installment_plans", 42, 44), 
    OneHot("housing", 45, 47), 
    OneHot("job", 48, 51),
    OneHot("phone", 52, 53), 
    OneHot("foreign", 54, 55), 
    OneHot("employment", 56, 60)
]

cadex = Cadex(german_model, constraints=constraints)

x = german_data.X_train.iloc[0]
cf = cadex.generate(x) # cadex method does not need to fit before generate

Metadata

Release files for CFEC 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CFEC 0.0.5
File Size Uploaded
CFEC-0.0.5.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CFEC 0.0.5
File Interpreter ABI Platform
CFEC-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 33.4 kB

Release files / CFEC-0.0.5.tar.gz

Download URL CFEC-0.0.5.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
343d7e2d7f0ccb3b47545087ddc80388fd599702dfb36199942e1b1094b631f6
BLAKE2b-256 checksum
How to use checksums
dd0ed5e934ab74d0f3f504a360d885d798aa119519eec403a5eba2986dcfd5a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release files / CFEC-0.0.5-py3-none-any.whl

Download URL CFEC-0.0.5-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d0897bbf364c111838aa34e965bc82c391abf6919efd0255c53572cf4021e53
BLAKE2b-256 checksum
How to use checksums
fcde759e33b651621235af59cdd7b4e238482c87614274be7e0f5d220abd9729
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page