ee.ConfusionMatrix.accuracy
Computes the overall accuracy of a confusion matrix defined as correct / total.
Usage | Returns |
---|
ConfusionMatrix.accuracy() | Float |
Argument | Type | Details |
---|
this: confusionMatrix | ConfusionMatrix | |
Examples
// Construct a confusion matrix from an array (rows are actual values,
// columns are predicted values). We construct a confusion matrix here for
// brevity and clear visualization, in most applications the confusion matrix
// will be generated from ee.Classifier.confusionMatrix.
var array = ee.Array([[32, 0, 0, 0, 1, 0],
[ 0, 5, 0, 0, 1, 0],
[ 0, 0, 1, 3, 0, 0],
[ 0, 1, 4, 26, 8, 0],
[ 0, 0, 0, 7, 15, 0],
[ 0, 0, 0, 1, 0, 5]]);
var confusionMatrix = ee.ConfusionMatrix(array);
print("Constructed confusion matrix", confusionMatrix);
// Calculate overall accuracy.
print("Overall accuracy", confusionMatrix.accuracy());
// Calculate consumer's accuracy, also known as user's accuracy or
// specificity and the complement of commission error (1 − commission error).
print("Consumer's accuracy", confusionMatrix.consumersAccuracy());
// Calculate producer's accuracy, also known as sensitivity and the
// compliment of omission error (1 − omission error).
print("Producer's accuracy", confusionMatrix.producersAccuracy());
// Calculate kappa statistic.
print('Kappa statistic', confusionMatrix.kappa());
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
from pprint import pprint
# Construct a confusion matrix from an array (rows are actual values,
# columns are predicted values). We construct a confusion matrix here for
# brevity and clear visualization, in most applications the confusion matrix
# will be generated from ee.Classifier.confusionMatrix.
array = ee.Array([[32, 0, 0, 0, 1, 0],
[ 0, 5, 0, 0, 1, 0],
[ 0, 0, 1, 3, 0, 0],
[ 0, 1, 4, 26, 8, 0],
[ 0, 0, 0, 7, 15, 0],
[ 0, 0, 0, 1, 0, 5]])
confusion_matrix = ee.ConfusionMatrix(array)
print("Constructed confusion matrix:")
pprint(confusion_matrix.getInfo())
# Calculate overall accuracy.
print("Overall accuracy:", confusion_matrix.accuracy().getInfo())
# Calculate consumer's accuracy, also known as user's accuracy or
# specificity and the complement of commission error (1 − commission error).
print("Consumer's accuracy:")
pprint(confusion_matrix.consumersAccuracy().getInfo())
# Calculate producer's accuracy, also known as sensitivity and the
# compliment of omission error (1 − omission error).
print("Producer's accuracy:")
pprint(confusion_matrix.producersAccuracy().getInfo())
# Calculate kappa statistic.
print("Kappa statistic:", confusion_matrix.kappa().getInfo())
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["`ConfusionMatrix.accuracy()` computes the overall accuracy of a confusion matrix, which is defined as the ratio of correct predictions to the total number of predictions."],["It takes a `ConfusionMatrix` object as input and returns the accuracy as a float."],["This function is useful for evaluating the performance of classification models by providing a single metric summarizing the overall correctness of predictions."],["Example code snippets demonstrate how to create a confusion matrix and calculate its overall accuracy using the Earth Engine API in both JavaScript and Python."]]],["The content details the computation of a confusion matrix's overall accuracy, calculated as correct predictions divided by the total. It demonstrates how to construct a `ConfusionMatrix` object from an array, representing actual vs. predicted values. The `accuracy()` method returns a float representing this overall accuracy. Other methods shown include calculating consumer's and producer's accuracy, and the kappa statistic using a `ConfusionMatrix`. Both JavaScript and Python examples are provided.\n"]]