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);
The script has some issues (this might be due to asset privacy settings)
LikeLike
find this line :
//var image = ee.Image(composites.filterDate(start,end).first()).divide(10000)
and change with below line
var image = composites.first().divide(10000)
LikeLike
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
LikeLike
you can only calculate probability with 2 classes…
LikeLike
This script gives errors…
LikeLike
You can calculate probabilty for each class in three primitives, where the classification is the corresponding class vs the rest classes.
LikeLike
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! 🙂
LikeLike
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
LikeLike
Great work! Thanks! It really helps!
LikeLike
Does anyone know how to interpret variable importance?
LikeLike