Announcement: All noncommercial projects registered to use Earth Engine before
April 15, 2025 must
verify noncommercial eligibility to maintain Earth Engine access.
ee.ConfusionMatrix.consumersAccuracy
Stay organized with collections
Save and categorize content based on your preferences.
Computes the consumer's accuracy (reliability) of a confusion matrix defined as (correct / total) for each row.
Usage | Returns | ConfusionMatrix.consumersAccuracy() | Array |
Argument | Type | Details | this: confusionMatrix | ConfusionMatrix | |
Examples
Code Editor (JavaScript)
// 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
Colab (Python)
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."],[[["\u003cp\u003e\u003ccode\u003econsumersAccuracy()\u003c/code\u003e computes the consumer's accuracy for each class in a confusion matrix.\u003c/p\u003e\n"],["\u003cp\u003eConsumer's accuracy, also known as user's accuracy or specificity, represents the reliability of the classification for each class.\u003c/p\u003e\n"],["\u003cp\u003eIt is calculated as the ratio of correctly classified instances to the total number of instances predicted for that class (correct / total for each row).\u003c/p\u003e\n"],["\u003cp\u003eThe result is returned as an \u003ccode\u003eArray\u003c/code\u003e where each element represents the consumer's accuracy for the corresponding class.\u003c/p\u003e\n"]]],[],null,["# ee.ConfusionMatrix.consumersAccuracy\n\nComputes the consumer's accuracy (reliability) of a confusion matrix defined as (correct / total) for each row.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------------------|---------|\n| ConfusionMatrix.consumersAccuracy`()` | Array |\n\n| Argument | Type | Details |\n|-------------------------|-----------------|---------|\n| this: `confusionMatrix` | ConfusionMatrix | |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Construct a confusion matrix from an array (rows are actual values,\n// columns are predicted values). We construct a confusion matrix here for\n// brevity and clear visualization, in most applications the confusion matrix\n// will be generated from ee.Classifier.confusionMatrix.\nvar array = ee.Array([[32, 0, 0, 0, 1, 0],\n [ 0, 5, 0, 0, 1, 0],\n [ 0, 0, 1, 3, 0, 0],\n [ 0, 1, 4, 26, 8, 0],\n [ 0, 0, 0, 7, 15, 0],\n [ 0, 0, 0, 1, 0, 5]]);\nvar confusionMatrix = ee.ConfusionMatrix(array);\nprint(\"Constructed confusion matrix\", confusionMatrix);\n\n// Calculate overall accuracy.\nprint(\"Overall accuracy\", confusionMatrix.accuracy());\n\n// Calculate consumer's accuracy, also known as user's accuracy or\n// specificity and the complement of commission error (1 − commission error).\nprint(\"Consumer's accuracy\", confusionMatrix.consumersAccuracy());\n\n// Calculate producer's accuracy, also known as sensitivity and the\n// compliment of omission error (1 − omission error).\nprint(\"Producer's accuracy\", confusionMatrix.producersAccuracy());\n\n// Calculate kappa statistic.\nprint('Kappa statistic', confusionMatrix.kappa());\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\nfrom pprint import pprint\n\n# Construct a confusion matrix from an array (rows are actual values,\n# columns are predicted values). We construct a confusion matrix here for\n# brevity and clear visualization, in most applications the confusion matrix\n# will be generated from ee.Classifier.confusionMatrix.\narray = ee.Array([[32, 0, 0, 0, 1, 0],\n [ 0, 5, 0, 0, 1, 0],\n [ 0, 0, 1, 3, 0, 0],\n [ 0, 1, 4, 26, 8, 0],\n [ 0, 0, 0, 7, 15, 0],\n [ 0, 0, 0, 1, 0, 5]])\nconfusion_matrix = ee.ConfusionMatrix(array)\nprint(\"Constructed confusion matrix:\")\npprint(confusion_matrix.getInfo())\n\n# Calculate overall accuracy.\nprint(\"Overall accuracy:\", confusion_matrix.accuracy().getInfo())\n\n# Calculate consumer's accuracy, also known as user's accuracy or\n# specificity and the complement of commission error (1 − commission error).\nprint(\"Consumer's accuracy:\")\npprint(confusion_matrix.consumersAccuracy().getInfo())\n\n# Calculate producer's accuracy, also known as sensitivity and the\n# compliment of omission error (1 − omission error).\nprint(\"Producer's accuracy:\")\npprint(confusion_matrix.producersAccuracy().getInfo())\n\n# Calculate kappa statistic.\nprint(\"Kappa statistic:\", confusion_matrix.kappa().getInfo())\n```"]]