Random forest trees and variable importance

SmileRandomForest puts a smile on your face

See the code snippet below and find a full example here.

var classifier = ee.Classifier.smileRandomForest(5).setOutputMode('PROBABILITY').train(trainingSample,"land_class",bandNames);

var dict = classifier.explain();

var variable_importance = ee.Feature(null, ee.Dictionary(dict).get('importance'));

var chart =
title: 'Random Forest Variable Importance',
legend: {position: 'none'},
hAxis: {title: 'Bands'},
vAxis: {title: 'Importance'}



  1. Hi, I have been trying this code out on a random forest classification I am running. I know the code works because I have tested it with the random forest example in the GEE docs. However, I can’t quite get it to work on my classification, which uses 11 inputs and a SNIC segmentation before going through the random forest classifier to produce a 3 class output. My classification works, I just can’t get the dictionary from classifier.explain() to work. I keep getting the error: “Dictionary (Error) Expected 2 classes for PROBABILITY, found 3”. Please contact me if you have any insight as to what might be going on.

    Thank you,


  2. You can calculate probabilty for each class in three primitives, where the classification is the corresponding class vs the rest classes.


  3. Hello,
I’m trying to run the script on my point sample and a big dataset for my study region in Armenia. However there is constantly showing an error (Property ‘Urban_Mask’ of feature ‘0’ is missing) when I try to run it. It seems the classifier faces problems when classifying the image with the sampled pixels. The binary point property ‘Urban_Mask’ should be free of null values meaning all the points have either a value of 0 for not urban or a value of 1 for urban. Nevertheless some of the sampled pixels of the image must lack of a property value. I also tried to filter out null values which also didn’t work.

    Heres is my script: https://code.earthengine.google.com/?scriptPath=users%2Fmarcellitomohr93%2FArmenia_LULCC%3ALULC_Classification2019%2FGoris2019_ClassificationIterations%2FFeatureImportance_GrasslandMask

    Thanks for any help or suggestions! 🙂


  4. Hello,
    thank you for your script, i think it’s work in any problems
    i’m trying to make mean decrease of accuracy from Random forest classification, because MDG and MDA is important to make a decision, but i can’t find a script to made it in GEE.
    thank you for any help orsuggestions


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s