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();
print('Explain:',dict);

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

var chart =
ui.Chart.feature.byProperty(variable_importance)
.setChartType('ColumnChart')
.setOptions({
title: 'Random Forest Variable Importance',
legend: {position: 'none'},
hAxis: {title: 'Bands'},
vAxis: {title: 'Importance'}
});

print(chart);

5 comments

  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,
    Erica

    Like

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

    Like

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