- Franco Arda

# Deep Learning in Tableau

How can we deploy a Deep Learning model in Tableau?
The focus of this post is to deploy a Deep Learning model in Tableau - not how to create a Deep Learning model (there are many __resources __for that).
In the example, below, I create a super simple Deep Learning model using __Google's TensorFlow 2.0__ in Python. I use a synthetic "Money Laundering" dataset, but it could be any classification problem such as cancer prediction, customer churn prediction, predictive maintenance ...

An important part is scaling: (1) your Deep Learning model would not work without scaling such as 0-1 with MinMaxScaler and (2) it's a bit of a challenge to pickle the scaler and make it work with Tableau (see later).

Again, a super simple model with the focus on integrating it in Tableau.

In order to deploy the Deep Learning model, we need to store it. With Deep Learning models.

This is probably the hardest part. After saving the scaler we need to write a function that deploys the Deep Learning model in Tableau. The calculations are based on the row level, which might make it slow. An alternative is to integrate the Deep Learning model in Tableau Prep with Python. Integrating the Deep Learning model with Tableau Prep would make the user experience fast. This works if we don't have parameters (i.e. the probabilities are static). If we want to use Parameters (i.e. dynamic), then the Tableau Prep solution does not work.

Now, if we had categorical data in the dataset such as countries (e.g. Germany, USA, Switzerland..), we would have had to encode the categorical data. One possible way is to use a __one-hot encoding__ with Scikit-Learn. This would result in a reverse mapping and another pickle (just in the second line of the function).

Last but not least, we need to connect our Python code with Tableau through TabPy.

Now in Tableau Desktop, we can integrate a Calculated Field that connects to our Deep Learning model (e.g. Money_Laundering_DL). In return, we get the probability (make sure you calculate by cell and not by table down).

Conclusion: Combining TensorFlow 2.0 with Tableau opens up incredible opportunities, in particular for large datasets with complex nonlinear relationships where a Deep Learning excels. It's not for every situation, of course. If you need explainability, Deep Learning is a black box, a Logistic Regression might be a better solution - Logistic Regression is explainable. But if you have complex nonlinear relationships in your data and require the highest accuracy possible, integrating a Deep Learning model in Tableau might be the solution.