Production income classifier with drift, outlier and explanations

To run this notebook you need the inference data. This can be acquired in two ways:

  • Run make train or,

  • gsutil cp -R gs://seldon-models/scv2/examples/income/infer-data .

import numpy as np
import json
import requests
with open('./infer-data/test.npy', 'rb') as f:
    x_ref = np.load(f)
    x_h1 = np.load(f)
    y_ref = np.load(f)
    x_outlier = np.load(f)
reqJson = json.loads('{"inputs":[{"name":"input_1","data":[],"datatype":"FP32","shape":[]}]}')
url = "http://0.0.0.0:9000/v2/models/model/infer"
def infer(resourceName: str, batchSz: int, requestType: str):
    if requestType == "outlier":
        rows = x_outlier[0:0+batchSz]
    elif requestType == "drift":
        rows = x_h1[0:0+batchSz]
    else:
        rows = x_ref[0:0+batchSz]
    reqJson["inputs"][0]["data"] = rows.flatten().tolist()
    reqJson["inputs"][0]["shape"] = [batchSz, rows.shape[1]]
    headers = {"Content-Type": "application/json", "seldon-model":resourceName}
    response_raw = requests.post(url, json=reqJson, headers=headers)
    print(response_raw)
    print(response_raw.json())

Pipeline with model, drift detector and outlier detector

Show predictions from reference set. Should not be drift or outliers.

Show predictions from drift data. Should be drift and probably not outliers.

Show predictions from outlier data. Should be outliers and probably not drift.

Explanations

Cleanup

Last updated

Was this helpful?