#ConfusionMatrix
📊Friday AI Fact: What is a Confusion Matrix?

A confusion matrix is a table that helps you understand how well your classification model is performing.

Same time next Friday - new AI fact coming your way!

#ELOQUENCE #AI #MachineLearning #ConfusionMatrix
August 8, 2025 at 10:46 AM
The question is whether 70% sensitivity, 90% precision is good enough (maybe, for some applications). To play at home (in R): `tab <- matrix(c(229, 327-229, 27, 173-27), nrow=2, dimnames = list("Predicted" = c("Event", "No Event"), "Reference" = c("Event", "No Event")))
caret::confusionMatrix(tab)`
January 28, 2025 at 9:55 PM
Fastest way to count pixels per class in GEE
I’m working with a classified rasters in Google Earth Engine, where the pixel values are 0, 1, 2 and 3. I need to efficiently count how many times each value occurs in every image (pixel count per class). Right now, I’m using reduceRegion() with frequencyHistogram(), but I’m wondering if there’s a faster and more optimized method. Here’s the code for calculating the F1-score and confusion matrix: // F1-score calculation function calculateF1Score(binaryImage) { var confusionMatrix = maskImage .add(binaryImage.byte().multiply(2)) .reduceRegion({ reducer: ee.Reducer.frequencyHistogram().unweighted(), maxPixels: 1e13 }); var matrix = ee.Dictionary(confusionMatrix.get('b1')); var TP = ee.Number(matrix.get("3")); // True Positives (TP) var FP = ee.Number(matrix.get("2")); // False Positives (FP) var FN = ee.Number(matrix.get("1")); // False Negatives (FN) var precision = TP.divide(TP.add(FP)); var recall = TP.divide(TP.add(FN)); var f1Score = precision.multiply(recall).multiply(2).divide(precision.add(recall)); return { 'f1Score': f1Score }; } Classes in Confusion Matrix: * TP: Correctly classified positives (value = 3) * FP: False positives (value = 2) * FN: False negatives (value = 1) Is there a more efficient way to count pixel values and speed up this process, given that I have many rasters to process?
gis.stackexchange.com
July 13, 2026 at 9:07 PM
December 11, 2024 at 12:20 PM
December 8, 2024 at 4:04 AM
Fastest way to count pixels per class in GEE
I’m working with a classified rasters in Google Earth Engine, where the pixel values are 0, 1, 2 and 3. I need to efficiently count how many times each value occurs in every image (pixel count per class). Right now, I’m using reduceRegion() with frequencyHistogram(), but I’m wondering if there’s a faster and more optimized method. Here’s the code for calculating the F1-score and confusion matrix: // F1-score calculation function calculateF1Score(binaryImage) { var confusionMatrix = maskImage .add(binaryImage.byte().multiply(2)) .reduceRegion({ reducer: ee.Reducer.frequencyHistogram().unweighted(), maxPixels: 1e13 }); var matrix = ee.Dictionary(confusionMatrix.get('b1')); var TP = ee.Number(matrix.get("3")); // True Positives (TP) var FP = ee.Number(matrix.get("2")); // False Positives (FP) var FN = ee.Number(matrix.get("1")); // False Negatives (FN) var precision = TP.divide(TP.add(FP)); var recall = TP.divide(TP.add(FN)); var f1Score = precision.multiply(recall).multiply(2).divide(precision.add(recall)); return { 'f1Score': f1Score }; } Classes in Confusion Matrix: * TP: Correctly classified positives (value = 3) * FP: False positives (value = 2) * FN: False negatives (value = 1) Is there a more efficient way to count pixel values and speed up this process, given that I have many rasters to process?
gis.stackexchange.com
February 28, 2026 at 8:11 AM