公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.ConfusionMatrix
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
建立混淆矩陣。矩陣的軸 0 (資料列) 對應實際值,軸 1 (資料欄) 則對應預測值。
用量 | 傳回 |
---|
ee.ConfusionMatrix(array, order) | ConfusionMatrix |
引數 | 類型 | 詳細資料 |
---|
array | 物件 | 代表混淆矩陣的整數 2D 方陣。請注意,與 ee.Array 建構函式不同,這個引數無法接受清單。 |
order | 清單,預設值為空值 | 非連續或非以零為基礎的矩陣,其資料列和資料欄的大小和順序。 |
範例
程式碼編輯器 (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 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
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())
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間: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```"]]