Loading ANN ( Artificial Neural Network ) model in PowerBI for Prediction

P J Athul
3 min readFeb 3, 2023

--

Image Courtesy: Google images, Credit goes to the original creators

Never heard about using Deep Learning models in PowerBI before. Then you are reading the right article.

Prerequisite

  • PowerBi Desktop
  • Anaconda
  • Python
  • Tensorflow

Let's assume that you are building an ML/DL model. Save your ANN model in ‘.h5 format’.

model.save(“ModelName.h5”)

Open PowerBi and load your dataset. Then click on the transform data

This will take you to the Power Query Editor and on the power query editor click on Run Python Script

It will throw you a prompt where you can write the code to load the Artificial Neural Network ( ANN ) model which you have saved.

dataset[‘prediction’] will contain the predicted values by the model. For prediction, the columns considered for predicting the output from the data loaded to PowerBi are passed to the model.

For example;

import tensorflow as tf
import pandas

#Replace with your Path of the model & your model name
model = tf.keras.models.load_model(r“path\ModelName.h5")

dataset[‘prediction’] = model.predict(dataset[[“ColumnName1”, “ColumnName2”, “ColumnName3”]])

Once you have written your code, click on OK and after executing the code you’ll get an output similar to the picture below.

Then click on expand

Then you will see something like this

It will contain the list of columns ( I can’t expose the data which I have used, so I have erased the column names ). At the end you will able to see the column name called “prediction”, it contains the values predicted by your ann model. Then click ok after selecting the required columns

It will give you the transformed table with a prediction column.

Here I have used a dataset that falls under the Binary Classification category. The ‘prediction’ column is of type ABC123, change the column type to fixed decimal or decimal by right-clicking the column “prediction”. Then you can create a custom column from the prediction column.

0.5 is the threshold according to which the values of the new column StatusPredicted are generated.

In this example, for the records for which the ‘prediction’ column has values greater than 0.5, then the column StatusPredicted will contain value ‘Value 1’ or else ‘Value 2’

Hope this article helped you 🙂

Follow me on LinkedIn

linkedin.com/in/pjathul

--

--