eazyml-xai provides APIs for explainable AI (XAI), offering human-readable explanations, feature importance, and predictive reasoning.
Project description
EazyML Responsible-AI: XAI
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
-
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_xai-0.0.92.tar.gz.
File metadata
- Download URL: eazyml_xai-0.0.92.tar.gz
- Upload date:
- Size: 20.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
470a3c95e05f163daa5af7f9f47f4ce8ba9c14253d934544f33bf213aca905ff
|
|
| MD5 |
cab6a85ee8205e9b555177c5238b5f46
|
|
| BLAKE2b-256 |
bd491d485717bb4b9784950c3bc1c90e3f4172b3287183daffced00ef4eaa6a8
|
File details
Details for the file eazyml_xai-0.0.92-py2.py3-none-any.whl.
File metadata
- Download URL: eazyml_xai-0.0.92-py2.py3-none-any.whl
- Upload date:
- Size: 21.1 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
890bb5eeab14e9f3d35f00825295e04715a4ecef1d946fa0cb35e7d403618e40
|
|
| MD5 |
111f0963ad417e294b6dd95c71d26a97
|
|
| BLAKE2b-256 |
9f78dedba92bd3a763be88ab4c72327b58f71b10ca69af8a016b120bc8aa5cd2
|