Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.

ee.ConfusionMatrix

  • A ConfusionMatrix is created from a square, 2D array of integers where rows represent actual values and columns represent predicted values.

  • Theorder parameter can be used to specify custom class labels for the rows and columns.

  • If theorder parameter is not specified, the class labels are assumed to be a 0-based sequence.

Creates a confusion matrix. Axis 0 (the rows) of the matrix correspond to the actual values, and Axis 1 (the columns) to the predicted values.

UsageReturns
ee.ConfusionMatrix(array,order)ConfusionMatrix
ArgumentTypeDetails
arrayObjectA square, 2D array of integers, representing the confusion matrix. Note that unlike the ee.Array constructor, this argument cannot take a list.
orderList, default: nullThe row and column size and order, for non-contiguous or non-zero based matrices.

Examples

Code Editor (JavaScript)

// A confusion matrix. Rows correspond to actual values, columns to// predicted values.vararray=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.varorder=[11,22,42,52,71,81];print('Specified row/column labels (specified "order" parameter)',ee.ConfusionMatrix({array:array,order:order}).order());

Python setup

See the Python Environment page for information on the Python API and usinggeemap for interactive development.

importeeimportgeemap.coreasgeemap

Colab (Python)

# 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]])display('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.display('Default row/column labels (unspecified "order" parameter):',ee.ConfusionMatrix(array,None).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.order=[11,22,42,52,71,81]display('Specified row/column labels (specified "order" parameter):',ee.ConfusionMatrix(array,order).order())

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-09-19 UTC.