Confusion Matrices
A confusion matrix is an Earth Engine variable object that represents what is sometimes called an “error matrix” or a “contingency table.” It is an array of two similar axes, one representing a set of known values and the other representing a corresponding set of predicted values. The array then records how often each of a set of predictions associates a particular known value with a particular predicted value. These predictions are usually those generated by a classifier or stored as a collection of trained features for multispectral satellite image classification. Confusion matrices can be processed by using operations of the types listed below.
Table of contents
- Creating Confusion Matrices
- Reproducing Confusion Matrices
- Describing Confusion Matrices
- Documenting Confusion Matrices
- Presenting Confusion Matrices
Creating Confusion Matrices
ee.ConfusionMatrix
Creates a new confusion matrix from a specified two-dimensional array whose
- horizontal rows (axis 1) represent known classes
- vertical columns (axis 0) represent predicted classes
- values indicate the number cases in which a given known value was classfified as a given predicted value
Syntax
Javascript
newConfusionMatrix = ee.ConfusionMatrix(array,order)
- newConfusionMatrix is the new confusion matrix.
- array is the specified array.
- order is the row and column size and order of a non-contiguous or non-zero matrix, given as a list.
Example
Javascript
var TheARRAY = ee.Array( [ [0,2,0,0],
[0,1,0,0],
[0,1,3,1],
[0,1,3,4] ] );
var TheCONFUSIONMATRIX = ee.ConfusionMatrix( TheARRAY );
print( TheCONFUSIONMATRIX );
Reproducing Confusion Matrices
confusionMatrix.array
- Creates a creates a new two-dimensional array from a specified confusion matrix.
Syntax
Javascript
newArray = oldConfusionMatrix.array()
- newArray is the new array.
- oldConfusionMatrix is the specified confusion matrix.
Example
Javascript
var TheARRAY = ee.Array( [ [0,2,0,0],
[0,1,0,0],
[0,1,3,1],
[0,1,3,4] ] );
var TheCONFUSIONMATRIX = ee.ConfusionMatrix( TheARRAY );
var NewARRAY = TheCONFUSIONMATRIX.array();
print( NewARRAY );
Describing Confusion Matrices
confusionMatrix.kappa
- Creates a new floating-point number indicating the Kappa statistic for a specified confusion matrix.
- This measures the agreement between two datasets on a scale that genereally ranges from 0 to 1.
Syntax
Javascript
newNumber = oldConfusionMatrix.kappa()
- newNumber is the new number.
- oldConfusionMatrix is the specified confusion matrix.
Example
Javascript
var TheARRAY = ee.Array( [ [0,2,0,0],
[0,1,0,0],
[0,1,3,1],
[0,1,3,4] ] );
var TheCONFUSIONMATRIX = ee.ConfusionMatrix( TheARRAY );
var NewNumber = TheCONFUSIONMATRIX.kappa();
print( TheCONFUSIONMATRIX );
print( NewNumber );
confusionMatrix.accuracy
- Creates a new floating-point number indicating the accuracy of a specified confusion matrix.
- Computed as the number of correct classifications divided by the total number of classifications.
Syntax
JavaScript
newNumber = oldConfusionMatrix.accuracy()
- newNumber is the new number.
- oldConfusionMatrix is the specified confusion matrix.
Example
############## JavaScript
var TheARRAY = ee.Array( [ [0,2,0,0],
[0,1,0,0],
[0,1,3,1],
[0,1,3,4] ] );
var TheCONFUSIONMATRIX = ee.ConfusionMatrix( TheARRAY );
var NewNumber = TheCONFUSIONMATRIX.accuracy();
print(TheCONFUSIONMATRIX);
print( NewNumber );
confusionMatrix.producersAccuracy
- creates a new array indicating the consumer’s accuracy(reliability) of a specified confusion matrix.
- computed as the number of correct classifications divided by the the total number of classifications for each column.
Syntax
Javascript
newArray = oldConfusionMatrix.producersAccuracy()
- newArray is the new array.
- oldConfusionMatrix is the specified confusion matrix.
Example
Javascript
var TheARRAY = ee.Array( [ [0,2,0,0],
[0,1,0,0],
[0,1,3,1],
[0,1,3,4] ] );
var TheCONFUSIONMATRIX = ee.ConfusionMatrix( TheARRAY );
var NewARRAY = TheCONFUSIONMATRIX.producersAccuracy();
print (TheCONFUSIONMATRIX);
print( NewARRAY );
confusionMatrix.consumersAccuracy
- Creates a new array indicating the consumer’s accuracy(reliability) of a specified confusion matrix.
- Computed as the number of correct classifications divided by the the total number of classifications for each row.
Syntax
Javascript
newArray = oldConfusionMatrix.consumersAccuracy()
- newNumber is the new number.
- oldConfusionMatrix is the specified confusion matrix.
Example
Javascript
var TheARRAY = ee.Array( [ [0,2,0,0],
[0,1,0,0],
[0,1,3,1],
[0,1,3,4] ] );
var TheCONFUSIONMATRIX = ee.ConfusionMatrix( TheARRAY );
var NewARRAY = TheCONFUSIONMATRIX.consumersAccuracy();
print (TheCONFUSIONMATRIX);
print( NewARRAY );
confusionMatrix.order
- Creates a new list indicating the name and order of the rows and columns of a specified confusion matrix.
Syntax
Javascript
newList = oldConfusionMatrix.order()
- newList is the new list of name and order of rows and columns.
- oldConfusionMatrix is the specified confusion matrix.
Example
Javascript
var TheARRAY = ee.Array( [ [0,2,0,0],
[0,1,0,0],
[0,1,3,1],
[0,1,3,4] ] );
var TheCONFUSIONMATRIX = ee.ConfusionMatrix( TheARRAY, [3,2,1,0] );
var NewLIST = TheCONFUSIONMATRIX.order();
print( TheCONFUSIONMATRIX );
print( NewLIST );
confusionMatrix.getInfo
- Creates a JSON-compatible text object representing a specified confusion matrix.
Syntax
Javascript
newObject = oldConfusionMatrix.getInfo()
- newObject is the new text object.
- oldConfusionMatrix is the specified confusion matrix.
- alternatively, you could also use ee.Algorithms.Describe(oldConfusionMatrix) to achieve the same results
Example
Javascript
var TheARRAY = ee.Array( [ [0,2,0,0],
[0,1,0,0],
[0,1,3,1],
[0,1,3,4] ] );
var TheCONFUSIONMATRIX = ee.ConfusionMatrix( TheARRAY );
print( TheCONFUSIONMATRIX.getInfo( ) );
//alternatively
print( ee.Algorithms.Describe( TheCONFUSIONMATRIX ) );
Documenting Confusion Matrices
confusionMatrix.getInfo
Contribute!
confusionMatrix.toString
Contribute!
ee.Algorithms.Describe
Contribute!
confusionMatrix.serialize
Contribute!