To help with deploying trained models in production, the
interpretableai package offers a lightweight prediction API that can load saved models from JSON files and use these models to make predictions for new data without requiring a Julia installation.
This functionality is provided by the
interpretableai.Predictor object, and is accessible without first needing to import the
iai submodule, meaning it can be used without Julia installed on the machine.
from interpretableai import Predictor predictor = Predictor('lnr.json') pred = predictor.predict(X)
[22.2, 22.2, 22.2, 22.2, 17.26, 17.26, 13.414286, 22.2, 22.2, 17.26, 17.26, 17.26, 17.26, 17.26, 13.414286, 13.414286, 13.414286, 30.88, 30.88, 30.88, 22.2, 17.26, 17.26, 13.414286, 17.26, 30.88, 22.2, 30.88, 13.414286, 22.2, 13.414286, 22.2]
The new data can be supplied in the following formats:
dictfor each sample in the data, where the keys are the feature names and the values indicate the corresponding feature values (i.e. the features as they would be represented as JSON)
The applicable API depends on the type of learner. For each of the learner type below, we list the supported APIs:
An object that reads saved Interpretable AI models from JSON files and makes predictions.
filename: (str) path to the JSON file to be read in
Return the leaf index in the Optimal Trees model into which each point in the features
Return the predictions made by the model for each point in the features
Return the probabilities of class membership predicted by the model for each point in the features
The behavior of this function depends on the type of model.
For Optimal Prescriptive Trees, return the predicted outcome for each point in the features
X for each treatment made by the model. Equivalent to
For Optimal Policy Trees, return the outcome for each point in the features
rewards under the prescriptions made by the model. The
rewards can be a numpy matrix, a pandas dataframe, or a
dicts as it would be represented as JSON. Equivalent to
Return the estimated quality of each treatment in the trained Optimal Policy Tree model for each point in the features
Return the treatments in ranked order of effectiveness for each point in the features
X as predicted by the Optimal Policy Tree model.
Return the fitted hazard coefficient estimate made by the Optimal Survival Tree model for each point in the data
Return the expected survival time estimate made by the Optimal Survival Tree model for each point in the data