公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.ConfusionMatrix.accuracy
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
计算混淆矩阵的总体准确率,定义为“正确数 / 总数”。
用法 | 返回 |
---|
ConfusionMatrix.accuracy() | 浮点数 |
参数 | 类型 | 详细信息 |
---|
此:confusionMatrix | ConfusionMatrix | |
示例
代码编辑器 (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 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
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())
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eConfusionMatrix.accuracy()\u003c/code\u003e computes the overall accuracy of a confusion matrix, which is defined as the ratio of correct predictions to the total number of predictions.\u003c/p\u003e\n"],["\u003cp\u003eIt takes a \u003ccode\u003eConfusionMatrix\u003c/code\u003e object as input and returns the accuracy as a float.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for evaluating the performance of classification models by providing a single metric summarizing the overall correctness of predictions.\u003c/p\u003e\n"],["\u003cp\u003eExample code snippets demonstrate how to create a confusion matrix and calculate its overall accuracy using the Earth Engine API in both JavaScript and Python.\u003c/p\u003e\n"]]],["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"],null,["# ee.ConfusionMatrix.accuracy\n\nComputes the overall accuracy of a confusion matrix defined as correct / total.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|------------------------------|---------|\n| ConfusionMatrix.accuracy`()` | Float |\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```"]]