I want to perform an binary Accuracy Assessment (ErrorMatrix) for two FeatureCollections containing lakes as polygons. One collection contains the results of a classification (needed to convert raster to vectors to calculate area size and to remove smaller objects) and the other one with validation data representing reality. A polygon represents a lake with landcover 1 as property. How can I merge both collections to have the specific columns needed to perform ErrorMatrix()? I tried using the method descriped here https://developers.google.com/earth-engine/guides/joins_spatial but didn't seem to work for an ErrorMatrix(). Might there be any other way to create a Confusion Matrix for two FeatureCollections?
Asked
Active
Viewed 67 times
0
-
If you found a solution yourself then congratulation. Please create an answer below to share it. – Yunnosch Aug 30 '20 at 12:40
1 Answers
0
I've found the following solution to my problem: I can use the methods of the ROC-Analysis to calculate the true and false classified areas. Here's my function for that:
var validateLakes = function(classified, truth){
//clip classified lakes to sampleareas
classified = classified.filterBounds(sampleareas);
//convert required FeatureCollections to single multipolygon Feature
var classified_union = ee.Feature(classified.union().first());
truth = ee.Feature(truth.union().first());
var area = ee.Feature(sampleareas.union().first());
//calculate tp, tf, fp & fn areas
var tp = classified_union.intersection(truth);
var tn = area.difference(classified_union.union(truth));
var fp = classified_union.difference(truth);
var fn = truth.difference(classified_union);
/*
//check results
Map.addLayer(tp, {palette: 'FF0000'}, 'tp');
Map.addLayer(tn, {palette: 'FF0000'}, 'tn');
Map.addLayer(fp, {palette: 'FF0000'}, 'fp');
Map.addLayer(fn, {palette: 'FF0000'}, 'fn');
*/
//calculate size of areas
var tp_area = ee.Number(tp.area());
var tn_area = ee.Number(tn.area());
var fp_area = ee.Number(fp.area());
var fn_area = ee.Number(fn.area());
//calculate tpr, fdr and accuracy
//tpr = tp / (tp + fn)
var tpr = tp_area.divide(tp_area.add(fn_area));
//fdr = tp / (fp + tp)
var fdr = fp_area.divide(fp_area.add(tp_area));
//accuracy = (tp + tn) / (tp + tn + fp + fn)
var numerator = tp_area.add(tn_area);
var denominator = tp_area.add(tn_area.add(fp_area.add(fn_area)));
var accuracy = numerator.divide(denominator);
//function for adding values to classfied FeatureCollection
var addProps = function(feature){
feature = feature.set('TPR', tpr);
feature = feature.set('FDR', fdr);
feature = feature.set('ACCURACY', accuracy);
return feature;
};
//return classified Collection with new properties
return classified.map(addProps);
};

Lares525
- 1
- 1