Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Kserve Kserve Alibi Helper

From Leeroopedia
Knowledge Sources
Domains Explainability, Visualization
Last Updated 2026-02-13 00:00 GMT

Overview

Concrete tool for querying KServe prediction and explanation endpoints and rendering interactive Alibi explainability visualizations provided by the KServe sample code.

Description

This module provides a collection of helper functions designed for use in Jupyter notebooks that demonstrate Alibi-based model explanations. It includes functions for: sending REST requests to KServe predict and explain endpoints (predict(), explain()), feature mapping (getFeatures()), and rendering interactive visualizations using Plotly bar charts (show_bar(), show_feature_coverage()) and IPython display utilities (show_anchors(), show_examples(), show_prediction(), show_row()).

Usage

Import these helper functions in a Jupyter notebook when running Alibi explanation demos against a deployed KServe model to make predictions, request explanations, and visualize anchor-based explanation results.

Code Reference

Source Location

Signature

def getFeatures(X, cmap):
    ...

def predict(X, name, ds, svc_hostname, cluster_ip):
    ...

def explain(X, name, svc_hostname, cluster_ip):
    ...

def show_bar(X, labels, title):
    ...

def show_feature_coverage(exp):
    ...

def show_anchors(names):
    ...

def show_examples(exp, fidx, ds, covered=True):
    ...

def show_prediction(prediction):
    ...

def show_row(X, ds):
    ...

Import

from alibi_helper import predict, explain, show_bar, show_anchors, show_examples

I/O Contract

Inputs

predict()

Name Type Required Description
X list Yes Input instances for prediction
name str Yes Name of the KServe model
ds object Yes Dataset object with target_names attribute
svc_hostname str Yes Service hostname for the Host header
cluster_ip str Yes Cluster IP address for the HTTP request

explain()

Name Type Required Description
X list Yes Input instances to explain
name str Yes Name of the KServe model
svc_hostname str Yes Service hostname for the Host header
cluster_ip str Yes Cluster IP address for the HTTP request

show_bar()

Name Type Required Description
X list Yes Bar chart x-axis values (e.g., precision scores)
labels list Yes Bar chart y-axis labels (e.g., feature names)
title str Yes Title for the bar chart

show_examples()

Name Type Required Description
exp dict Yes Explanation result containing anchor and raw example data
fidx int Yes Feature index for which to display examples
ds object Yes Dataset object, optionally with feature_names attribute
covered bool No If True, shows covered examples; if False, shows uncovered examples (default True)

Outputs

predict()

Name Type Description
prediction str or list The target name for the predicted class, or empty list on failure

explain()

Name Type Description
explanation dict or list JSON explanation response from the KServe explain endpoint, or empty list on failure

show_examples()

Name Type Description
examples pd.DataFrame DataFrame of covered or uncovered example rows

Usage Examples

Basic Usage

from alibi_helper import predict, explain, show_anchors, show_prediction

# Make a prediction
svc_hostname = "my-model.default.example.com"
cluster_ip = "10.0.0.1"
X = [[6.8, 2.8, 4.8, 1.4]]

prediction = predict(X, "iris-model", iris_dataset, svc_hostname, cluster_ip)
show_prediction(prediction)

# Get and display explanation
explanation = explain(X, "iris-model", svc_hostname, cluster_ip)
show_anchors(explanation["anchor"])

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment