I am trying to calculate the probability of variable importance each bands for classification. Basically, I have 3 class but when I try to implement the probability of variable importance, the error statement is "Expected 2 classes for PROBABILITY, found 3". Could you please inform the problem in the code?
var geometry = ee.FeatureCollection("users/seneralkan77/water_4326");
Map.addLayer(geometry)
var aquatic = /* color: #ff0000 */ee.FeatureCollection(
[ee.Feature(
ee.Geometry.Point([-11.15696644,7.00857888]),
{
"watercover": 0,
"system:index": "0"
}),
ee.Feature(
ee.Geometry.Point([-11.18116639,6.99607471]),
{
"watercover": 0,
"system:index": "1"
}),
ee.Feature(
ee.Geometry.Point([-11.19274503,6.98715114]),
{
"watercover": 0,
"system:index": "2"
}),
ee.Feature(
ee.Geometry.Point([-11.15285584 , 6.9951071]),
{
"watercover": 0,
"system:index": "3"
})]),
fish_middle_class = /* color: #3b8b00 */ee.FeatureCollection(
[ee.Feature(
ee.Geometry.Point([-11.17854238,6.99824484]),
{
"watercover": 1,
"system:index": "4"
}),
ee.Feature(
ee.Geometry.Point([-11.15719553,7.00526697]),
{
"watercover": 1,
"system:index": "5"
}),
ee.Feature(
ee.Geometry.Point([-11.15692738,7.00521914]),
{
"watercover": 1,
"system:index": "6"
}),
ee.Feature(
ee.Geometry.Point([-11.15856715,7.00432886]),
{
"watercover": 1,
"system:index": "7"
}),
ee.Feature(
ee.Geometry.Point([-11.1668752,7.00175725]),
{
"watercover": 1,
"system:index": "8"
}),
ee.Feature(
ee.Geometry.Point([-11.15510189,7.00024551]),
{
"watercover": 1,
"system:index": "9"
})]),
fish_low_class = /* color: #0300ff */ee.FeatureCollection(
[ee.Feature(
ee.Geometry.Point([-11.15520286,7.00077292]),
{
"watercover": 2,
"system:index": "10"
}),
ee.Feature(
ee.Geometry.Point([-11.14973369,6.9887299]),
{
"watercover": 2,
"system:index": "11"
}),
ee.Feature(
ee.Geometry.Point([-11.14880352,6.98930031]),
{
"watercover": 2,
"system:index": "12"
})]);
// Load the Sentinel-2
var sentinel2018 = ee.Image('COPERNICUS/S2/20180104T110431_20180104T111712_T29NKH')
// Merge the three geometry layers into a single FeatureCollection.
var newfc = aquatic.merge(fish_middle_class).merge(fish_low_class);
// Use these bands for classification.
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B11', 'B12'];
// The name of the property on the points storing the class label.
var classProperty = 'watercover'
// Sample the composite to generate training data. Note that the
// class label is stored in the 'watercover' property.
var training = sentinel2018.select(bands).sampleRegions({
collection: newfc,
properties: [classProperty],
scale: 30
});
// Train a RF classifier.
var classifier = ee.Classifier.smileRandomForest(10).setOutputMode('PROBABILITY').train(training,"watercover",bands);
// Print some info about the classifier (specific to RF).
//print('Random Forest, explained', classifier.explain());
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);