Skip to content

Explainability

Aporia allows you to investigate any prediction from production on-demand.

In order to use explainability, you'll need to log your training data and upload your model artifact to Aporia.

After basic setup, you'll be able to use the Explain button in the Data Points page, which will show you the contribution of each feature to the prediction.

DataPointExplainer

You can also change any feature value, click "Re-Explain" and see the effect on the prediction. This lets you debug your model for specific predictions.

ReExplain

Setup

The first step is to convert your model to ONNX: An open format for Machine Learning models.

Models from all popular ML libraries (XGBoost, Sklearn, Tensorflow, Pytorch, etc.) can be converted to ONNX.

import onnxmltools
from onnxmltools.convert.common.data_types import FloatTensorType

initial_types = [('features', FloatTensorType([None, X_train.shape[1]]))]

onnx_model = onnxmltools.convert_xgboost(xgb_model, initial_types=initial_types, target_opset=9)
import onnxmltools
from onnxmltools.convert.common.data_types import FloatTensorType

initial_types = [('features', FloatTensorType([None, X_train.shape[1]]))]

onnx_model = onnxmltools.convert_lightgbm(lgb_model, initial_types=initial_types, target_opset=9)
import onnxmltools
from onnxmltools.convert.common.data_types import FloatTensorType

initial_types = [('features', FloatTensorType([None, X_train.shape[1]]))]

onnx_model = onnxmltools.covnert_catboost(catboost_model, initial_types=initial_types, target_opset=9)
import onnxmltools
from onnxmltools.convert.common.data_types import FloatTensorType

initial_types = [('features', FloatTensorType([None, X_train.shape[1]]))]

onnx_model = onnxmltools.covnert_sklearn(skl_model, initial_types=initial_types, target_opset=9)
import onnxmltools

onnx_model = onnxmltools.convert_keras(keras_model, target_opset=9)
import onnxmltools

onnx_model = onnxmltools.convert_tensorflow(keras_model, target_opset=9)
# Please see https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html

If you created the model version as part of your training code, you can use the Model object returned by aporia.create_model_version:

import aporia

aporia.init(token="<>",
            environment="<>")

apr_model = aporia.create_model_version(...)

Otherwise, you can get a reference to the model object:

import aporia

aporia.init(token="<>",
            environment="<>")

apr_model = aporia.Model(model_id="my-model", model_version="v1")

Now, you can upload your ONNX model artifact:

apr_model.upload_model_artifact(artifact_type="onnx", model_artifact=onnx_model.SerializeToString())

For explainability to work, it's necessary to log aggregations of your training set as well.