Sample application
Getting started using Pyreal to use and understand your ML model
All code for this quickstart guide can be found in the corresponding tutorial script.
Introduction to RealApps
In this tutorial, we will walk through getting an explanation using a pre-made RealApp
object on the Titanic dataset. We will explain why a specific passenger is predicted to have survived the sinking of the Titanic.
We start by loading in the pre-made RealApp
object.
We can get the model's prediction on a row of data using the .predict()
function:
We can generate explanations of model predictions using the .produce_[EXPLANATION_TYPE]
functions. Let's generate a local feature contribution object, which explains a model prediction for a passenger by explaining how much each feature (input) value contributed to the final prediction.
We can visualize the resulting explanation using the visualize
module.
We can see here that the fact that this passenger was female and in first class most significantly increased her predicted chance of survival.
Creating RealApps
To make a new RealApp for an application, you will need:
The training data and target values (or ground-truth values for the quantity your ML model predicts). We refer to input data as x and target values as y.
Any data transformers that prepare the data for predictions, and possibly additional transformers that make the data easier to understand. The Data Preparation and Modeling guides give more details on selecting these transformers.
A trained model. This can be any object with a .predict() function that takes an input and outputs a prediction, such as an sklearn estimator or a pytorch neural network.
Optionally, a dictionary of default feature names to more descriptive feature strings
Optionally, a function that formats model predictions into a readable format.
In the cell below we load in or create these five components for our sample Titanic application. See the Quickstart: Your Own Application tutorial for instructions on how to prepare these yourself.
With this information, we can create a RealApp object:
We can now generate and visualize explanations as above:
Last updated