eazyml-cf 0.0.45
eazyml-cf provides APIs for counterfactual explanations, prescriptive analytics, and actionable insights to optimize predictive outcomes.
Requires Python: >=3.7
Keywords: counterfactuals, prescriptive-analytics, optimal-decision, what-if-analysis, actionable-insights, prediction-optimization, causal-inference, machine-learning, ml-api, explainable-ai

## Eazyml Counterfactual
![Python](https://img.shields.io/badge/python-3.7%20%7C%203.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.45-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-cf` 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, the 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
- **Counterfactual Explanations**: Identify feature changes required to alter predictions.
- **Prescriptive Analytics**: Generate actionable recommendations to achieve better outcomes.
- It performs feature selection from a training dataset by excluding specific columns and the target outcome column.
- This function builds a machine learning model using a specified training dataset.
- It provides platform to automates counterfactual inference for a test record by calculating the probability of an unfavorable outcome and determining the optimal adjustments to minimize it. It processes input datasets, configuration parameters, and model details to identify actionable changes in features while respecting constraints, enabling prescriptive insights for improved outcomes.

`eazyml-cf` is ideal for scenarios like fraud detection, loan approvals, and customer churn prevention.`

## Installation
### User installation
The easiest way to install counterfactual package is using pip:
```bash
pip install -U eazyml-cf
```
### Dependencies
Eazyml Augmented Intelligence requires :
- pandas
- matplotlib
- openpyxl
- scikit-learn
- scipy
- pyyaml

## Usage
Counterfactual can be used by initalizing EazyML and then getting insights for new test data.

```python
from eazyml_augi import ez_init, ez_augi
# Replace 'your_license_key' with your actual EazyML license key
ez_init(license_key="your_license_key")
selected_features = sk_feature_selection(
        train_file = 'train/file/path.csv',
        outcome = 'outcome column name',
        config= {
                "discard_columns" : ['id', 'unnamed'],
                }
        )
model_dict = sk_feature_selection(
        train_file = 'train/file/path.csv',
        test_file = 'test/file/path.csv',
        outcome = 'outcome column name',
        selected_columns = selected_features,
        config= {
            "unfavorable_outcome" : 1,
            "sklearn_classifier" : 'Gradient Boosting'
        }
    )
result = ez_cf_inference(
        train_file = 'train/file/path.csv',
        test_file = 'test/file/path.csv',
        outcome = 'outcome column name',
        config = {
            "unfavorable_outcome" : 1,
            "lower_quantile" : 0.01,
                "upper_quantile" : 0.99,
                "p" : 40,
                "M" : 2,
                "N" : 10000,
                "tolerable_error_threshold" : 0.1
            },
            selected_columns = selected_features,
            model_info = model_dict,
            test_record_idx = 'single or multiple testdata id or None'
        )
```
You can find more information in the [documentation](https://eazyml.readthedocs.io/en/latest/packages/eazyml_cf.html).

## Useful links and similar projects
- [Documentation](https://docs.eazyml.com)
- [Homepage](https://eazyml.com)
- If you have more questions or want to discuss a specific use case please book an appointment [here](https://eazyml.com/trust-in-ai)
- Here are some other EazyML's packages :

    - [eazyml](https://pypi.org/project/eazyml/): Eazyml provides a suite of APIs for training, testing and optimizing machine learning models with built-in AutoML capabilities, hyperparameter tuning, and cross-validation.
    - [eazyml-dq](https://pypi.org/project/eazyml-dq/): `eazyml-dq` provides APIs for comprehensive data quality assessment, including bias detection, outlier identification, and data drift analysis.
    - [eazyml-cf](https://pypi.org/project/eazyml-cf/): `eazyml-cf` provides APIs for counterfactual explanations, prescriptive analytics, and actionable insights to optimize predictive outcomes.
    - [eazyml-augi](https://pypi.org/project/eazyml-augi/): `eazyml-augi` provides APIs to uncover patterns, generate insights, and discover rules from training 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.*