Skip to main content

eazyml-xai provides APIs for explainable AI (XAI), offering human-readable explanations, feature importance, and predictive reasoning.

Project description

EazyML Responsible-AI: XAI

Python PyPI package Code Style

EazyML

eazyml-xai is a python package designed to make machine learning predictions more transparent and interpretable. It provides human-readable explanations for predictions.

Features

  • Local Feature Importance: Get insights into the most impactful features influencing the predicted target variable.
  • Explanations: Explains the reason behind the predicted target variable.
  • Explainability Score: Enhance the reliability of explanations with an explainability score.

eazyml-xai is a key tool for building trust in AI systems by providing clear, actionable explanations.

Installation

To use the explainable ai, ensure you have Python installed on your system.

User installation

The easiest way to install EazyML Explainable AI is using pip:

pip install -U eazyml-xai

Dependencies

This package requires:

  • pandas
  • scikit-learn
  • werkzeug
  • Unidecode
  • pydot
  • numpy
  • pyyaml
  • xgboost

Usage

Example 1 - Fetching explanations with the EazyML model.

Imports

from eazyml_xai import ez_init, ez_explain

Initialize and Read Data

# Initialize the EazyML automl library.
_ = ez_init()

# Load training data (Replace with the correct data path).
train_data_path = "path_to_your_training_data.csv"
train = pd.read_csv(train_data_path)

# Load test data (Replace with the correct data path).
test_data_path = "path_to_your_test_data.csv"
test = pd.read_csv(test_data_path)

Fetch Explanations

# Define the outcome (target variable)
outcome = "target"  # Replace with your target variable name

# Build EazyML predictive models
build_options = {'model_type': 'predictive'}
build_resp = ez_build_model(train, outcome=outcome, options=build_options)

# Use model_info from ez_build_model response
model_info = build_resp["model_info"]

# Customize options for fetching explanations
xai_options = {"record_number": [1, 2, 3]}

# To fetch the explanations
xai_response = ez_explain(train, outcome, test_data_path, model_info, options=xai_options)

# xai_response is a dictionary object with following keys.
# print (xai_response.keys())
# dict_keys(['success', 'message', 'explanations'])

# reponse object contains a dictionary with explanations for the user specified record numbers. 

Example 2 - Fetching explanations with your model and EazyML preprocessing.

Imports

from eazyml_xai import ez_init, ez_explain, create_onehot_encoded_features, ez_get_data_type

Initialize and Read Data

# Initialize the EazyML automl library.
_ = ez_init()

# Load training data (Replace with the correct data path).
train_data_path = "path_to_your_training_data.csv"
train = pd.read_csv(train_data_path)

# Define input features (X) and target variable (y)
y = train[outcome]
X = train.drop(outcome, axis=1)

# Load test data (Replace with the correct data path).
test_data_path = "path_to_your_test_data.csv"
test = pd.read_csv(test_data_path)

Fetch Explanations

# Define the outcome (target variable)
outcome = "target"  # Replace with your target variable name

# Get data type of features
type_df = ez_get_data_type(train, outcome)

# List of categorical columns
cat_list = type_df[type_df['Data Type'] == 'categorical']['Variable Name'].tolist()
cat_list = [ele for ele in cat_list if ele != outcome]

# Create one-hot encoded features
train = create_onehot_encoded_features(train, cat_list)

# Define your model object (replace with any model of your choice)
model_info = <YourModelClass>(<parameters>)  # e.g., RandomForestClassifier(), LogisticRegression(), etc.

# Train your model object
model_info.fit(X, y)

# Customize options for fetching explanations
xai_options = {"record_number": [1, 2, 3]}

# To fetch the explanations
xai_response = ez_explain(train, outcome, test_data_path, model_info, options=xai_options)

# xai_response is a dictionary object with following keys.
# print (xai_response.keys())
# dict_keys(['success', 'message', 'explanations'])

# reponse object contains a dictionary with explanations for the user specified record numbers. 

Example 3 - Fetching explanations with your model and preprocessing.

Imports

from eazyml_xai import ez_init, ez_explain

Initialize and Read Data

# Initialize the EazyML automl library.
_ = ez_init()

# Load training data (Replace with the correct data path).
train_data_path = "path_to_your_training_data.csv"
train = pd.read_csv(train_data_path)

# Define input features (X) and target variable (y)
y = train[outcome]
X = train.drop(outcome, axis=1)

# Load test data (Replace with the correct data path).
test_data_path = "path_to_your_test_data.csv"
test = pd.read_csv(test_data_path)

Fetch Explanations

# Define the outcome (target variable)
outcome = "target"  # Replace with your target variable name

# Implement your preprocessing steps within a custom preprocessor class and define it
# (Replace <YourPreprocessorClass> with the specific preprocessor class you're using)
preprocessor = <YourPreprocessorClass>(<parameters>)  # Example: StandardScaler(), CustomPreprocessor()

# Fit the preprocessor on your dataset
preprocessor.fit(X, y)

# Define your model object (replace with any model of your choice)
model_info = <YourModelClass>(<parameters>)  # e.g., RandomForestClassifier(), LogisticRegression(), etc.

# Train your model object
model_info.fit(X, y)

# Customize options for fetching explanations
xai_options = {"record_number": [1, 2, 3], "preprocessor", preprocessor}

# To fetch the explanations
xai_response = ez_explain(train_data_path, outcome, test_data_path, model_info, options=xai_options)

# xai_response is a dictionary object with following keys.
# print (xai_response.keys())
# dict_keys(['success', 'message', 'explanations'])

# reponse object contains a dictionary with explanations for the user specified record numbers. 

You can find more information in the documentation.

Useful links, other packages from EazyML family

  • Documentation

  • Homepage

  • 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


Download files

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

Source Distribution

eazyml_xai-0.0.86.tar.gz (18.4 MB view details)

Uploaded Source

Built Distribution

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

eazyml_xai-0.0.86-py2.py3-none-any.whl (18.7 MB view details)

Uploaded Python 2Python 3

File details

Details for the file eazyml_xai-0.0.86.tar.gz.

File metadata

  • Download URL: eazyml_xai-0.0.86.tar.gz
  • Upload date:
  • Size: 18.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for eazyml_xai-0.0.86.tar.gz
Algorithm Hash digest
SHA256 a5fbac8621e9904d137f08ce41c4486af29de86a44fe85e3e04625bd77f8507a
MD5 595d7c36695297cd7ff88321e5b81a9b
BLAKE2b-256 ae9f419356a83db2b9af767bfc77b6082bbf94b8fd44826ed244585c97379e12

See more details on using hashes here.

File details

Details for the file eazyml_xai-0.0.86-py2.py3-none-any.whl.

File metadata

  • Download URL: eazyml_xai-0.0.86-py2.py3-none-any.whl
  • Upload date:
  • Size: 18.7 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for eazyml_xai-0.0.86-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e670f68b458e6736afced05bd490315e1a5f8465d23eec963587d58fbfaded56
MD5 ac3450680a8ef19005a54e73eb5fa2a1
BLAKE2b-256 880d524a7e42750adb7a6c1c09ff6f00cb8b206641833fa2f50b12e892819bf6

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