Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alibi deployment example - Anchor Tabular #629

Merged
merged 3 commits into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/examples/alibi_anchor_tabular.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../examples/explainers/alibi_anchor_tabular/alibi_anchor_tabular_seldon_deployment.ipynb"
}
2 changes: 2 additions & 0 deletions doc/source/examples/notebooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Notebooks
.. toctree::
:maxdepth: 1

Ambassador Canary <ambassador_canary>
Ambassador Canary <ambassador_canary>
Ambassador Shadow <ambassador_shadow>
Ambassador Headers <ambassador_headers>
Expand All @@ -15,6 +16,7 @@ Notebooks
Combiner Example <combiner>
Custom Endpoints <custom_endpoints>
Example Helm Deployments <helm_examples>
Explainer Alibi Anchor Tabular <alibi_anchor_tabular>
Go Model <go_example>
H2O Java MoJo <h2o_mojo>
Istio Canary <istio_canary>
Expand Down
1,376 changes: 1,376 additions & 0 deletions examples/explainers/alibi_anchor_tabular/README.md

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODEL_NAME=Explainer
API_TYPE=REST
SERVICE_TYPE=MODEL
PERSISTENCE=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import dill
import json
import numpy as np

class Explainer:
def __init__(self, *args, **kwargs):

with open("explainer.dill", "rb") as x_f:
self.explainer = dill.load(x_f)

def predict(self, X, feature_names=[]):
print("Received: " + str(X))
explanation = self.explainer.explain(X)
print("Predicted: " + str(explanation))
return json.dumps(explanation, cls=NumpyEncoder)

class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, (
np.int_, np.intc, np.intp, np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64)):
return int(obj)
elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)):
return float(obj)
elif isinstance(obj, (np.ndarray,)):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: machinelearning.seldon.io/v1alpha2
kind: SeldonDeployment
metadata:
labels:
app: seldon
name: loanclassifier-explainer
spec:
name: loanclassifier-explainer
predictors:
- componentSpecs:
- spec:
containers:
- image: loanclassifier-explainer:0.1
name: model-explainer
graph:
children: []
name: model-explainer
type: MODEL
endpoint:
type: REST
name: loanclassifier-explainer
replicas: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scikit-learn==0.20.1
dill==0.2.9
alibi==0.2.0
seldon-core==0.3.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODEL_NAME=Model
API_TYPE=REST
SERVICE_TYPE=MODEL
PERSISTENCE=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import dill

class Model:
def __init__(self, *args, **kwargs):

with open("preprocessor.dill", "rb") as prep_f:
self.preprocessor = dill.load(prep_f)
with open("model.dill", "rb") as model_f:
self.clf = dill.load(model_f)

def predict(self, X, feature_names=[]):
print("Received: " + str(X))
X_prep = self.preprocessor.transform(X)
proba = self.clf.predict_proba(X_prep)
print("Predicted: " + str(proba))
return proba
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: machinelearning.seldon.io/v1alpha2
kind: SeldonDeployment
metadata:
labels:
app: seldon
name: loanclassifier
spec:
name: loanclassifier
predictors:
- componentSpecs:
- spec:
containers:
- image: loanclassifier:0.1
name: model
graph:
children: []
name: model
type: MODEL
endpoint:
type: REST
name: loanclassifier
replicas: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scikit-learn==0.20.1
dill==0.2.9
7 changes: 7 additions & 0 deletions examples/explainers/alibi_anchor_tabular/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
xai==0.0.5
python-dateutil==2.8.0
seldon_core==0.3.0
alibi==0.2.0
jupyter==1.0.0
dill==0.2.9
scikit-learn==0.20.1