Visualizing your Decision Tree in Weka

Dear all,

  • I would like to know if it’s possible to visualize the final decision tree create by Weka after a training.

  • How to create a publishing workflow with Weka?

Kind regards,

1 Like

Hey @Alex.h,

Great question!

I was diving into this some time ago. I didn’t find a clear answer to this btw. You can read out weka models and plot them, but a “nice visualisation” is challenging. Furthermore, typically Fijis Trainable Weka Segmentation builds up a forest of many trees. Thus, visualisation of a single tree might not be helpful. If you think of multiple decision trees, that’s a bunch of if-else statements computing sums of probabilities. Example of 200 trees (not sure if this helpful either :wink: ) :

If you find something more visual, I’d also be curious :slight_smile:



Dear @haesleinhuepf,
I see my error I thought Weka selected 1 or few trees but in reality the random forest do majority voting.
I will try your method, but could you tell me how to use it.

Thank you a lot

It’s a bit tricky. The code lives here:

Now the question is, how are your Java/Maven/Fiji-plugin- compilation skills?

1 Like

Sorry no.
Should I copy on eclipse the script and save .JAVA or .JAR ?

Thank you for your help

The problem is that this is a half-backed Fiji plugin. In order to play with the code, you should execute the main function here (from Eclipse for example):

As you can see some lines below, this little test-program saves the model to disc, together with an opencl-file. This opencl file contains code like shown above. You can also replace the variables ground_truth, measure1 and measure2 with actual images, and process them instead the given mini-images with 10 pixels.

And if you need some starting-help with Maven projects in Eclipse, this video might be useful:


Dear Robert,
I try the method in the video, I change the POM file with your name, url, organisation etc…
Then I opened the gaussian file and I copy and paste your code. But I still have a lot of errors.
all the import cannot be resolve.

import hr.irb.fastRandomForest_clij.FastRandomForest;
import ij.IJ;
import ij.ImagePlus;
import ij.Prefs;
import ij.process.FloatProcessor;
import net.haesleinhuepf.clij.clearcl.ClearCLBuffer;
import net.haesleinhuepf.clijx.CLIJx;
import net.imglib2.img.array.ArrayImgs;
import trainableSegmentation_clij.WekaSegmentation;
import weka.classifiers.AbstractClassifier;
import weka.classifiers.Evaluation;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instance;
import weka.core.Instances;

Should I install something else ? I can’t run in java or create a .jar
I click on import ij.IJ and the software ask me if I want to create a class. Now I can’t see an error for this particular line but I’m not sure of what I’m doing.

Sorry this for my lack of knowledge

Hey @Alex.h,

it’s hard to guess what’s going wrong without looking at code. Just suggesting: If you want to allow other to work on your code to figure out what’s going wrong, please put the code somewhere where it’s accessible, e.g. on github.

In your particular case dependencies are not found. Thus, please check the dependency section of your pom.xml file. Here is mine :wink:

Let us know how it goes!


1 Like

I really need more skill in informatics, because even the pom didn’t solve the errors.
Don’t spend too much time for that ^^. I’m curious and try to understand how the plugin works.
Thank you for your help.