Outlier Detection with Combiner
The objective of this tutorial is to build a "loan approval" classifier equipped with the outlier detector from the alibi-detect package.
The diagram of this tutorial is as follows:

In this tutorial we will follow these steps:
Train and test model to predict loan approvals
Train and test outlier detector
Containerize and deploy your models
Test your new Seldon deployment
Before you start
Make sure you install the following dependencies, as they are critical for this example to work:
Helm v3.0.0+
A Kubernetes cluster running v1.13 or above (minikube / docker-for-windows work well if enough RAM)
kubectl v1.14+
ksonnet v0.13.1+
kfctl 0.5.1 - Please use this exact version as there are major changes every few months
Python 3.6+
Python DEV requirements (we'll install them below)
You can follow this notebook to setup your cluster.
Let's get started! 🚀🔥
Install Python dependencies
In the requirements-dev file you will find a set of Python dependencies required to run this notebook.
Install them with:
Train and test loanclassifier
We start with training the loanclassifier model by using a prepared Python script train_classifier:
Run the script:
This script creates two dill-serialized files preprocessor.dill and model.dill that are used by the Model class to make predictions:
You can test how it will work from the notebook:
precision
0.704545
recall
0.658497
specificity
0.913289
accuracy
0.852401
auc
0.785893
f1
0.680743
Train and test outliers detector
We will now train the outliers detector using another prepared script train_detector:
Run the script:
This will create dill-serialized objects used by the Detector class:
You can see how the detector works from this notebook:
Containerize your models
Before you can deploy classifier Model and outliers Detector as part of Seldon's graph you have to containerize them.
We will use s2i to do so with help of the provided Makefile:
Build the images:
or if using Minikube:
Deploy your models separately
Now, you can include your newly built containers as part of a Seldon deployment.
First, we will create two separate deployments: loanclassifier and outliersdetector. Each of them will have their own separate endpoint and can be queried independently depending on your needs.
Deploy separate loanclassifier

Apply the deployment:
Deploy separate outliers detector

Apply the deployment:
View newly deployed Kubernetes pods
Test deployed components
IMPORTANT: If you are using minikube (instead of Docker Desktop) you have to forward the port first with:
Example prediction:
Deploy loanclassifier and outliersdetector with combiner
Another possibility is to use a slightly more complicated graph with a combiner that will gather outputs from loanclassifier and outliersdetector.
Please note that loanclassifier and outliersdetector are part of the loanclassifier-combined graph and this deployment is independent from the previous two.
In this approach there is a single API endpoint that serves both functionalities.

Apply the deployment:
Check pods:
Example prediction:
Last updated
Was this helpful?