# tensorflow + dalex = :)

--

I will showcase how straightforward and convenient it is to explain a t*ensorflow** *predictive model using the *dalex** *Python package. The introduction to this topic can be found in Explanatory Model Analysis: Explore, Explain, and Examine Predictive Models. For any inquiries, please contact me on LinkedIn or GitHub.

For this example, we will use the data from the **World Happiness Report** and predict the happiness scored according to economic production, social support, etc. for any given country.

Let’s first train the basic *tensorflow *model incorporating the experimental normalization layer for a better fit.

The next step is to create a *dalex *Explainer object, which takes model and data as input.

Now, we are ready to explain the model using various methods: model level methods explain the global behavior, while predict level methods focus locally on a single observation from the data. We can start by evaluating model performance.

Which features are the most important? Let’s compare the two methods, one of which is implemented in the *shap** *package.

What are the continuous relationships between variables and predictions? We use Partial Dependence profiles which point out that not always the more, the better.

What about the residuals? These plots are useful to visualize where the model is wrong.

One can be more curious about the variable attributions for a specific country,

or several countries to compare the results.

Should you be interested in surrogate approximation, there is a possibility to produce the *lime** *package explanations using the unified interface.

Finally, if an interpretable model is needed, we can approximate the black-box with an easy-to-understand decision tree.

I hope that this journey brought you some happiness as it is accessible and user-friendly to explain predictive models nowadays. Of course, there are more explanations, results, and plots in the *dalex *toolkit. We prepared various resources listed in the package README .

The code for this piece is available at http://dalex.drwhy.ai/python-dalex-tensorflow.html.

`pip install tensorflow dalex shap statsmodels lime scikit-learn`

:)