forked from SeldonIO/seldon-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_anchor_tabular.py
More file actions
47 lines (37 loc) · 1.54 KB
/
test_anchor_tabular.py
File metadata and controls
47 lines (37 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Copyright 2020 kubeflow.org.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copied from https://github.com/kubeflow/kfserving/blob/master/python/alibiexplainer/
# tests/test_anchor_tabular.py
# and modified since
#
import json
import tempfile
import numpy as np
from alibi.saving import load_explainer
from alibiexplainer.anchor_tabular import AnchorTabular
from .make_test_models import make_anchor_tabular
from .utils import SKLearnServer
IRIS_MODEL_URI = "gs://seldon-models/v1.19.0-dev/sklearn/iris/*"
def test_anchor_tabular():
skmodel = SKLearnServer(IRIS_MODEL_URI)
skmodel.load()
with tempfile.TemporaryDirectory() as alibi_model_dir:
make_anchor_tabular(alibi_model_dir)
alibi_model = load_explainer(predictor=skmodel.predict, path=alibi_model_dir)
anchor_tabular = AnchorTabular(alibi_model)
test_data = np.array([[5.964, 4.006, 2.081, 1.031]])
explanation = anchor_tabular.explain(test_data)
explanation_json = json.loads(explanation.to_json())
assert explanation_json["meta"]["name"] == "AnchorTabular"