公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.ConfusionMatrix
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
创建混淆矩阵。矩阵的轴 0(行)对应于实际值,轴 1(列)对应于预测值。
用法 | 返回 |
---|
ee.ConfusionMatrix(array, order) | ConfusionMatrix |
参数 | 类型 | 详细信息 |
---|
array | 对象 | 一个表示混淆矩阵的整数二维方阵。请注意,与 ee.Array 构造函数不同,此实参不能采用列表。 |
order | 列表,默认值:null | 非连续或非零基准矩阵的行和列大小及顺序。 |
示例
代码编辑器 (JavaScript)
// A confusion matrix. Rows correspond to actual values, columns to
// predicted values.
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]]);
print('Constructed confusion matrix',
ee.ConfusionMatrix(array));
// The "order" parameter refers to row and column class labels. When
// unspecified, the class labels are assumed to be a 0-based sequence
// incrementing by 1 with a length equal to row/column size.
print('Default row/column labels (unspecified "order" parameter)',
ee.ConfusionMatrix({array: array, order: null}).order());
// Set the "order" parameter when custom class label integers are required. The
// list of integer value labels should correspond to the matrix axes left to
// right / top to bottom.
var order = [11, 22, 42, 52, 71, 81];
print('Specified row/column labels (specified "order" parameter)',
ee.ConfusionMatrix({array: array, order: order}).order());
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
from pprint import pprint
# A confusion matrix. Rows correspond to actual values, columns to
# predicted values.
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]])
print('Constructed confusion matrix:')
pprint(ee.ConfusionMatrix(array).getInfo())
# The "order" parameter refers to row and column class labels. When
# unspecified, the class labels are assumed to be a 0-based sequence
# incrementing by 1 with a length equal to row/column size.
print('Default row/column labels (unspecified "order" parameter):',
ee.ConfusionMatrix(array, None).order().getInfo())
# Set the "order" parameter when custom class label integers are required. The
# list of integer value labels should correspond to the matrix axes left to
# right / top to bottom.
order = [11, 22, 42, 52, 71, 81]
print('Specified row/column labels (specified "order" parameter):',
ee.ConfusionMatrix(array, order).order().getInfo())
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eCreates a confusion matrix from a 2D array of integers, where rows represent actual values and columns represent predicted values.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eorder\u003c/code\u003e parameter can be used to specify custom class labels for the rows and columns of the matrix.\u003c/p\u003e\n"],["\u003cp\u003eIf \u003ccode\u003eorder\u003c/code\u003e is not specified, it defaults to a 0-based sequence incrementing by 1.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eee.ConfusionMatrix\u003c/code\u003e object provides methods for analyzing the confusion matrix.\u003c/p\u003e\n"]]],[],null,["# ee.ConfusionMatrix\n\nCreates a confusion matrix. Axis 0 (the rows) of the matrix correspond to the actual values, and Axis 1 (the columns) to the predicted values.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------|-----------------|\n| `ee.ConfusionMatrix(array, `*order*`)` | ConfusionMatrix |\n\n| Argument | Type | Details |\n|----------|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|\n| `array` | Object | A square, 2D array of integers, representing the confusion matrix. Note that unlike the ee.Array constructor, this argument cannot take a list. |\n| `order` | List, default: null | The row and column size and order, for non-contiguous or non-zero based matrices. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A confusion matrix. Rows correspond to actual values, columns to\n// predicted values.\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]]);\nprint('Constructed confusion matrix',\n ee.ConfusionMatrix(array));\n\n// The \"order\" parameter refers to row and column class labels. When\n// unspecified, the class labels are assumed to be a 0-based sequence\n// incrementing by 1 with a length equal to row/column size.\nprint('Default row/column labels (unspecified \"order\" parameter)',\n ee.ConfusionMatrix({array: array, order: null}).order());\n\n// Set the \"order\" parameter when custom class label integers are required. The\n// list of integer value labels should correspond to the matrix axes left to\n// right / top to bottom.\nvar order = [11, 22, 42, 52, 71, 81];\nprint('Specified row/column labels (specified \"order\" parameter)',\n ee.ConfusionMatrix({array: array, order: order}).order());\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# A confusion matrix. Rows correspond to actual values, columns to\n# predicted values.\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]])\nprint('Constructed confusion matrix:')\npprint(ee.ConfusionMatrix(array).getInfo())\n\n# The \"order\" parameter refers to row and column class labels. When\n# unspecified, the class labels are assumed to be a 0-based sequence\n# incrementing by 1 with a length equal to row/column size.\nprint('Default row/column labels (unspecified \"order\" parameter):',\n ee.ConfusionMatrix(array, None).order().getInfo())\n\n# Set the \"order\" parameter when custom class label integers are required. The\n# list of integer value labels should correspond to the matrix axes left to\n# right / top to bottom.\norder = [11, 22, 42, 52, 71, 81]\nprint('Specified row/column labels (specified \"order\" parameter):',\n ee.ConfusionMatrix(array, order).order().getInfo())\n```"]]