Docs and guides

From a fitted estimator to a monitored model.

A ten-minute quickstart, five runnable notebooks that take one dataset all the way to production, and the reference for every call.

Quickstart

Your first explanation in three steps.

  1. Create an API keySign up on the free plan, then create a key under API keys in the dashboard. Keys look like km_live_… and cannot create other keys.
  2. Install the clientPython 3.9 or newer. Add kaimei[models] to upload fitted estimators from your training stack.
  3. Explain a predictionSet KAIMEI_API_KEY in your environment, or pass it to the client, then explain any input. The same call is POST /v1/explanations.
# the client
pip install kaimei

# plus NumPy and your training stack, to upload fitted estimators
pip install "kaimei[models]"

# optional: charts in the dashboard's colours, image helpers
pip install matplotlib "kaimei[images]"

# your key, read automatically by the client
export KAIMEI_API_KEY=km_live_...
from kaimei import Kaimei
from kaimei.tabular import explanation_summary, plot_explanation

client = Kaimei()  # KAIMEI_API_KEY from the environment

model = client.models.retrieve("titanic-forest")
explanation = client.explanations.create(
    model=model.slug, input=passenger, method="shap",
    options={"counterfactual": True, "frozen_features": ["Sex", "Age"]},
)

print(explanation_summary(explanation, model=model))
# The model predicts died: P(survived) = 7.4%, against 41.1% on average.
# Pulling P(survived) down: Sex = male (−12.1 pts), Title = Mr (−11.0 pts) ...
plot_explanation(explanation, model=model)
from kaimei import Kaimei

client = Kaimei()

model = client.models.upload(
    clf,                               # a fitted estimator
    name="Churn net",
    feature_names=["tenure", "spend", "tickets"],
    X=X_train, y=y_train,              # reference rows, capped at 5,000
)

# a model Kaimei cannot run itself: point it at your endpoint
client.models.upload(
    large_forest,
    name="Churn forest",
    inference={"type": "remote", "url": "https://scoring.example.com/predict"},
)

Guides

One dataset, the whole workflow.

Five notebooks take the Titanic passenger list from a Kaggle starting point to monitored, versioned models. Each runs in about a minute. Notebooks 01 to 04 need a free Kaimei account; 00 needs nothing.

00no account needed

Titanic EDA and models

The starting point: data cleaning, feature engineering and eight classifiers compared by accuracy.

01start here

Explain a model

Why one passenger died, which ticket would have saved him, two models that disagree, and what the forest learned overall.

uploadSHAPcounterfactualsfull analysis
02

Monitor in production

Two weeks of traffic with a shadow model, then a feed that sends fares in pence, caught by drift detection and named by an explanation.

hosted predictionsshadow modelsdrift
03

Improve and version

Error analysis with explanations, better features, then v2 shipped as a new version and compared with v1.

batch explanationsversionscompare insights
04

Bring your own model

XGBoost, explained with its own TreeSHAP values and through a scoring endpoint that Kaimei calls.

pre-computed attributionsremote inferenceprivate weights
imagesGrad-CAM · occlusion · LIME

Cats and dogs

A MobileNetV2 classifier uploaded with its photos attached, then asked why on new pictures. Each answer is drawn exactly as the dashboard draws it.

Reference

Every resource, in the client and on the wire.

The Python client mirrors the REST API one for one. Errors raise typed KaimeiError subclasses with a code, a type and a status. 429 responses are retried with the server's Retry-After, and GET requests also retry on 502, 503 and 504.

ClientEndpointDoes
client.models/v1/modelsRegister, upload, version and list models
client.predictions/v1/predictionsLog predictions, or have Kaimei predict
client.explanations/v1/explanationsExplain one input by any method
client.analyses/v1/analysesStudy a whole model
client.insights/v1/insightsRead what an analysis found
client.projects/v1/projectsGroup models, with summaries
client.api_keys/v1/api-keysManage keys
client.organization/v1/organizationYour organisation and its limits
client.health()/healthIs the API up

Stuck, or found a bug?

Open an issue on GitHub and we will read it. The notebooks' README also has a troubleshooting section for the common cases.