Creating Machine learning Development and Production Environment in Power BI-Part2


In the last post, I have explained how we can create a function with the aim of parametrising the machine learning process. In this post, I am going to explain how we able to create a Development and Production environment.

Create Different Environment in Power Query

to create a new environment, In power query, I created two main groups one for “Develop” and the other one for “Production”. To create a different group, I just right-click in the Query window, then create two separate group.

Develop (Test and Train)

First, I create a function to train a model and get the result of the evaluation. In this post, I will show how I leverage “rpart” a decision tree algorithm and “knn” both for classification.

First, I write some R codes to train models and also to evaluate the algorithm.

for “rpart” I have :

Train model for rpart :


Test Model

Then I follow the steps in the last post, to create a function and pass the parameters such as “dataset” for training, split percentage, the column name for prediction.

the M code for having a function with parameters in Power query to train and show the test result of rpart algorithm would be as below:

so in Power Query, I create a new blank query (see figure),


Then, in Home tab -> Query part, click on the “Advanced Editor”.

Then, Just copy and bast the M code that we wrote in above to create a function with parameters.

Finally, just change the name of the function.

I tried to train two different dataset (titanic and cancer data) and see the evaluation result

As you can see in above figures, I invoke the function for different data set with the aim of classification.

as you can see I have created, an environment for development training for classification problem.

Leila Etaati
Dr. Leila Etaati is Principal Data Scientist, BI Consultant, and Speaker. She has over 10 years’ experience working with databases and software systems. She was involved in many large-scale projects for big sized companies. Leila has PhD of Information System department, University of Auckland, MS and BS in computer science. Leila is Microsoft Data Platform MVP.

Leave a Reply

Your email address will not be published. Required fields are marked *