Metadata-Version: 2.1
Name: eazyml-counterfactual
Version: 0.0.60
Summary: eazyml-counterfactual from EazyML family for counterfactual explanations, prescriptive analytics, and actionable insights to optimize predictive outcomes.
Home-page: https://eazyml.com/
Author: EazyML
Author-email: admin@eazyml.com
Project-URL: Documentation, https://docs.eazyml.com/
Project-URL: Homepage, https://eazyml.com/
Project-URL: Contact Us, https://eazyml.com/trust-in-ai
Project-URL: eazyml-automl, https://pypi.org/project/eazyml-automl/
Project-URL: eazyml-counterfactual, https://pypi.org/project/eazyml-counterfactual/
Project-URL: eazyml-xai, https://pypi.org/project/eazyml-xai/
Project-URL: eazyml-xai-image, https://pypi.org/project/eazyml-xai-image/
Project-URL: eazyml-insight, https://pypi.org/project/eazyml-insight/
Project-URL: eazyml-data-quality, https://pypi.org/project/eazyml-data-quality/
Keywords: counterfactuals,prescriptive-analytics,optimal-decision,what-if-analysis,actionable-insights,prediction-optimization,causal-inference,machine-learning,ml-api,explainable-ai
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: Other/Proprietary License
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Information Technology
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE

## EazyML Responsible-AI: Counterfactual
![Python](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)  ![PyPI package](https://img.shields.io/badge/pypi%20package-0.0.60-brightgreen) ![Code Style](https://img.shields.io/badge/code%20style-black-black)

![EazyML](https://github.com/EazyML/eazyml-docs/raw/refs/heads/master/EazyML_logo.png)

`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:
```bash
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
```python
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](https://eazyml.readthedocs.io/en/latest/packages/eazyml_cf.html).

## Useful links, other packages from EazyML family
- [Documentation](https://docs.eazyml.com)
- [Homepage](https://eazyml.com)
- If you have questions or would like to discuss a use case, please contact us [here](https://eazyml.com/trust-in-ai)
- Here are the other packages from EazyML suite:

    - [eazyml-automl](https://pypi.org/project/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](https://pypi.org/project/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](https://pypi.org/project/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](https://pypi.org/project/eazyml-insight/): eazyml-insight provides APIs to discover patterns, generate insights, and mine rules from your datasets.
    - [eazyml-xai](https://pypi.org/project/eazyml-xai/): eazyml-xai provides APIs for explainable AI (XAI), offering human-readable explanations, feature importance, and predictive reasoning.
    - [eazyml-xai-image](https://pypi.org/project/eazyml-xai-image/): eazyml-xai-image provides APIs for image explainable AI (XAI).

## License
This project is licensed under the [Proprietary License](https://github.com/EazyML/eazyml-docs/blob/master/LICENSE).

---

Maintained by [EazyML](https://eazyml.com)  
Â© 2025 EazyML. All rights reserved.
