Decision Trees

Moderator
6411 Views
Highlighted
Moderator
Posts: 17
Registered: ‎09-29-2015

Decision Trees

[ Edited ]

 
report_DTs.JPG

Description

With decision trees, you can visualize the probability of something you want to estimate, based on decision criteria from the historic data.

The decision tree classifier automatically finds the important decision criteria to consider.

 

Prerequisites (The sample .pbix files will not work without these prerequites completed)

1. Install R Engine

Power BI Desktop does not include, deploy or install the R engine. To run R scripts in Power BI Desktop, you must separately installR on your local computer. You can download and install R for free from many locations, including the Revolution Open download page, and the CRAN Repository.

 

2. Install the required R packages.

Download the R script attached to this message and run it to install all required packages on your local machine. 

 

Required R packages:

rpart, rpart.plot, RColorBrewer

 

Tested on:

CRAN 3.3.1 R, MRO 3.3.0, , powerbi.com

 

Legal Disclaimers:

Terms of Service and Third Party Programs.

 

 

Attachment
Attachment
Attachment
Frequent Visitor
Posts: 9
Registered: ‎03-08-2017

Re: Decision Trees

Dear Sharon

 

This is really excellent - my only question is whether there is a way to format (i) the colors, to make the output better fit in with the existing report and (ii) the formating of numbers in nodes? I am working on a loan portfolio to estimate the likelihood of default - but the loan amounts are presented in ln (XeY) format - it would be really helpful to amend these.

 

Regardless, this is an excellent contribution!

 

Gratefully,

 

Tim

Member
Posts: 65
Registered: ‎10-05-2016

Re: Decision Trees

[ Edited ]

This visual is excellent. 

  1. How can I convert the row counts from scientific notation to numeric? 
  2. How can I convert my dataset to method="Class"? 
  3. Is it possible to add Tooltips to these nodes using R-script?

 

Most of my code is from your sample PBIX file. 

Here is my screenshot.

decision tree2.jpg

Moderator
Posts: 48
Registered: ‎08-10-2016

Re: Decision Trees

[ Edited ]

Hi TimKroemer ,

Sorry for the delay in reply: 

(i)the colors.

Answer: look for "default.palettes"  in R script and change it as you like 

 

(ii) the formating of numbers in nodes?
Answer:  prp {rpart.plot}  function has plenty of parameters. 
https://www.rdocumentation.org/packages/rpart.plot/versions/2.1.0/topics/prp

 

Moderator
Posts: 48
Registered: ‎08-10-2016

Re: Decision Trees

Hi ironryan77

1) Format it via parameters of prp function, may be you will need to reload "format" function 

2) Option 1: use characters instead of "numbers" for 1st column , Option 2: specify it explicitely as rpart(..., method ="class",...)

3) This visual is image, so tooltips are not possible. (We suport such functionality in  HTML-based R-powered Custom Visuals)

Frequent Visitor
Posts: 2
Registered: Monday

Re: Decision Trees

Hello Sharon,

 

I am just starting in the power bi world and I am trying to build a decision tree, my problem is the one in the file attached. The tree doesnt appear, it says "The tree depth is zero".

 

Am I doing something wrong?

 

Thanks in advance,

 

Eli

Attachment
Frequent Visitor
Posts: 2
Registered: Monday

Re: Decision Trees

Hello Sharon,

 

I am having some troubles on trying to build a decision tree on power bi, I am quite new here so I think it should be something easy...

 

The error says : "The tree depth is zero"

 

Thanks in advance for your help,

Moderator
Posts: 48
Registered: ‎08-10-2016

Re: Decision Trees

Hi @Elizabeth24

 

Sometimes algorithm "decides" that adding branches to root of the tree is not useful.

For example, if you have 90% negatives 10% positives in your data. The accuracy of root node is 0.9 and adding branches may not improve it much.  

 

You may try to disable cross validation. 

You may try to make changes in data. 

You may try to change some parameters, for example:

 

complexity   =  1e-05 #change  to 1e-10

minBucket = 2# change to 1

minRows  =  10 # change to 5

maxNumAttempts  =  10   #change to 50