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 GermanCredit AIFModel

From Leeroopedia
Knowledge Sources
Domains Model Serving, Fairness and Bias Detection
Last Updated 2026-02-13 00:00 GMT

Overview

Concrete tool for serving a logistic regression classifier on the German Credit dataset with AIF360 integration provided by the KServe sample code.

Description

KServeSampleModel is a custom KServe model server class that extends kserve.Model. During load(), it loads the preprocessed German Credit dataset from AIF360 (filtered by age), fits a scikit-learn StandardScaler and LogisticRegression model using instance weights from the dataset, and stores the trained model. The predict() method accepts input instances, applies standard scaling, and returns class predictions as a dictionary. The module also includes a __main__ block that starts the KServe model server with the trained model.

Usage

Use this class when you need to deploy a fairness-aware logistic regression model on the German Credit dataset as a KServe inference service, particularly as the predictor component in a bias detection pipeline with AIF360.

Code Reference

Source Location

Signature

class KServeSampleModel(kserve.Model):
    def __init__(self, name: str):
        ...

    def load(self):
        ...

    def predict(
        self,
        payload: Union[Dict, InferRequest, ModelInferRequest],
        headers: Dict[str, str] = None,
    ) -> Union[Dict, InferResponse, ModelInferResponse]:
        ...

Import

from model import KServeSampleModel

I/O Contract

Inputs

Constructor

Name Type Required Description
name str Yes The name of the model, used for KServe routing

predict()

Name Type Required Description
payload Union[Dict, InferRequest, ModelInferRequest] Yes Dictionary containing an "instances" key with a list of feature arrays
headers Dict[str, str] No Optional HTTP headers from the request

Outputs

load()

Name Type Description
(none) None Sets self.model and self.ready as side effects

predict()

Name Type Description
predictions Dict Dictionary with key "predictions" containing a list of predicted class labels

Usage Examples

Basic Usage

from model import KServeSampleModel
import kserve

# Create and load the model
model = KServeSampleModel("german-credit")
model.load()

# Make a prediction
payload = {"instances": [[1.0, 0.5, 0.3, 0.7, 1.2, 0.8, 0.1, 0.9, 0.4]]}
result = model.predict(payload)
print(result)  # {"predictions": [1]}

Server Startup

import kserve
from model import KServeSampleModel

model = KServeSampleModel("german-credit")
model.load()
kserve.ModelServer(workers=1).start([model])

Related Pages

Page Connections

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