eazyml-counterfactual from EazyML family for counterfactual explanations, prescriptive analytics, and actionable insights to optimize predictive outcomes.
Project description
EazyML Responsible-AI: Counterfactual
eazyml-counterfactual is a python package that helps users optimize predictive outcomes by generating counterfactual explanations.
EazyML revolutionizes machine learning by introducing counterfactual inference, automating the process of identifying optimal changes to variables that shift outcomes from unfavorable to favorable. This approach overcomes the limitations of manual "what-if" analysis, enabling models to provide actionable, prescriptive insights alongside their predictions.
Designed for post-prediction analysis, this package answers questions like:
- "What minimal changes to input features can reverse an unfavorable prediction?"
- "How can I achieve a desired outcome by tweaking feature values?"
Features
- Prescriptive Insights: Automatically recommend actionable steps to achieve desired outcomes by identifying optimal feature modifications.
- Outcome Optimization: Calculates the likelihood of favorable outcomes and determines optimal adjustments to improve predictions while respecting user-defined constraints.
- Flexible Feature Selection: Allows users to manually specify relevant features from the training dataset for counterfactual inference.
- Custom Model Integration: Accepts pre-trained machine learning models and user-defined preprocessing steps for seamless inference.
- Classification and Regression Support: Handles both classification and regression problems.
eazyml-counterfactual is ideal for scenarios like loan approvals, customer churn prevention, and healthcare treatment planning.`
Installation
User installation
The easiest way to install counterfactual package is using pip:
pip install -U eazyml-counterfactual
Dependencies
EazyML Counterfactual requires :
- pandas
- eazyml-automl
- openpyxl
- scikit-learn
- scipy
Usage
Counterfactual inference can be applied by initializing the EazyML framework and obtaining actionable insights for new test data.
Imports
from eazyml_counterfactual import ez_init, ez_cf_inference
Initialize and Read Data
# Initialize the EazyML automl library.
_ = ez_init()
# Define training data (Replace with the correct data path).
train_data_path = "path_to_your_training_data.csv"
# Load test data (Replace with the correct data path).
# Test data should contain predicted probabilities.
test_data_path = "path_to_your_test_data.csv"
pred_df = pd.read_csv(test_data_path)
Counterfactual Inference
# Define the outcome (target variable)
outcome = "target" # Replace with your target variable name
# Define list of selected features
selected_features = ['feature1', 'feature2', 'feature3']
# Define trained model object
model_info = b"acacxaca"
# Define variants
variants = ['feature1', 'feature2']
# Select test record for inference
test_index_no = 0
test_data = pred_df.loc[[test_index_no]]
# Customize options for counterfactual inference
cf_options = {"variants": variants, "outcome_ordinality": "1", "train_data": train_data_path}
# Call the EazyML API for counterfactual inference
result, optimal_transition_df = ez_cf_inference(
test_data=test_data,
outcome=outcome,
selected_features=selected_features,
model_info=model_info,
options=cf_options
)
You can find more information in the documentation.
Useful links, other packages from EazyML family
-
If you have questions or would like to discuss a use case, please contact us here
-
Here are the other packages from EazyML suite:
- eazyml-automl: eazyml-automl provides a suite of APIs for training, optimizing and validating machine learning models with built-in AutoML capabilities, hyperparameter tuning, and cross-validation.
- eazyml-data-quality: eazyml-data-quality provides APIs for comprehensive data quality assessment, including bias detection, outlier identification, and drift analysis for both data and models.
- eazyml-counterfactual: eazyml-counterfactual provides APIs for optimal prescriptive analytics, counterfactual explanations, and actionable insights to optimize predictive outcomes to align with your objectives.
- eazyml-insight: eazyml-insight provides APIs to discover patterns, generate insights, and mine rules from your datasets.
- eazyml-xai: eazyml-xai provides APIs for explainable AI (XAI), offering human-readable explanations, feature importance, and predictive reasoning.
- eazyml-xai-image: eazyml-xai-image provides APIs for image explainable AI (XAI).
License
This project is licensed under the Proprietary License.
Maintained by EazyML
© 2025 EazyML. All rights reserved.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eazyml-counterfactual-0.0.67.tar.gz.
File metadata
- Download URL: eazyml-counterfactual-0.0.67.tar.gz
- Upload date:
- Size: 14.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb5b95c294c7e72e91209a605b787e1ddd2b65066a89ced2a371c77e88078783
|
|
| MD5 |
f94cc8d8799342155f8bc026ac74a171
|
|
| BLAKE2b-256 |
8c3566074e1cddd48f704900df66d01b2437f2a75ea7a722fd2cee7f3a41ce5b
|
File details
Details for the file eazyml_counterfactual-0.0.67-py2.py3-none-any.whl.
File metadata
- Download URL: eazyml_counterfactual-0.0.67-py2.py3-none-any.whl
- Upload date:
- Size: 14.7 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1183a7f9441471dbc2c11c7ffe392643017c6c97acbdebdd42a8c45dc27e724
|
|
| MD5 |
ba86c81a658c121a39c1cd67b37b6c90
|
|
| BLAKE2b-256 |
77f2539958e0dc0ed09a52eadf8038da4c71b15569a6973c703b805412d6477f
|