Explainable AI for Multi-Output Regression | by Cory Randolph | Feb, 2021 | Towards Data Science | Towards Data Science

Opening the “black box” of machine learning models is not only critical in understanding the models we create, but also in communicating to others the information brought to light by the machine learning model. I have seen several projects fail because they could not be explained well to others, which is why understanding the models we build is necessary in order to increase the successful implementation of machine learning projects.
Recently I was working on an ML project that required multi-output regression (predicting more than one output/label/target) and had a hard time finding solid examples or resources implementing explainability. Working though the challenges of how to explain multi-output regression models involved a lot of trial and error. Ultimately, I was able to break down my multi-output regression model, and I gained a few “lessons learned” along the way that are worth sharing.
The full code walk through can be found on GitHub at SHAP Values for Multi-Output Regression Models and can be run in the browser through Google Colab.
Creating the data model for multi-output regression to demonstrate explainability through SHAP.
The below code creates data with 1,000 samples to train on, 10 features, and only 7 of them are meaningfully tied with the output/label we are trying to predict. (Later we will see how SHAP values help us see the informative features.) Lastly we have 5 outputs/labels making this a multi-output regression problem.
X, y = make_regression(n_samples=1000, n_features=10, n_informative=7, n_targets=5, random_state=0)
To create a multi-output regression model, I use a Tensorflow/Keras model since it allows the user to easily set the number of outputs/labels equal to the number of labels they are trying to predict from the data.
model = Sequential()model.add(Dense(32, input_dim=10, activation=’relu’))model.add(Dense(5))model.compile(loss=’mae’, optimizer=’adam’)model.fit(X, y, verbose=0, epochs=100)
After importing SHAP and choosing the data to generate explanations for, we can now plot explanations for individual outputs/labels. See SHAP Values for Multi-Output Models Notebook for full code.
shap.force_plot(base_value = explainer.expected_value[current_label.value],shap_values = shap_value_single[current_label.value], features = X[list_of_labels].iloc[X_idx:X_idx+1,:])
The below plot shows how each feature/input influenced the over all prediction. (Red being higher values and blue being lower values.) Now we have a detailed explanation for an individual prediction from what was otherwise a “blackbox” model. By selecting a different label we can see how the same input features affected each output/label independently (see full code notebook for dynamic drop-downs).
As with many ML projects, it is hard to tell which of the inputs/features we used really effected the predictions, but we can again use SHAP and the built-in summary plots to show a model-level summary for each individual output/label.
From the data setup earlier, we know that there were 3 features that did not have any influence on the outputs, and we can now easily see that the bottom 3 features (03, 07, and 01) are those features.
Break the problem down into a simpler problem by trying to explain a single output/label of a model since there are more resources available. Then work back up to the original problem (this example used a dropdown to dynamically select any of the multiple outputs/labels to explore).
Creating a tutorial as a self-contained notebook that can run in the browser and select individual outputs/labels forced me to understand at a level beyond copying and pasting code to get a quick solution.
If you are trying to open the black box of a multi-output machine learning model, I hope this demonstrates the value of the SHAP and helps you in explaining your model.