Anúncio: todos os projetos não comerciais registrados para usar o Earth Engine antes de 
15 de abril de 2025 precisam 
verificar a qualificação não comercial para manter o acesso. Se você não fizer a verificação até 26 de setembro de 2025, seu acesso poderá ser suspenso.
  
        
 
       
     
  
  
  
    
  
  
  
    
      ee.FeatureCollection.errorMatrix
    
    
      
    
    
      
      Mantenha tudo organizado com as coleções
    
    
      
      Salve e categorize o conteúdo com base nas suas preferências.
    
  
  
      
    
  
  
  
  
  
    
  
  
    
    
    
  
  
Calcula uma matriz de erros 2D para uma coleção comparando duas colunas dela: uma com os valores reais e outra com os valores previstos. Os valores precisam ser números inteiros pequenos e contíguos, começando em 0. O eixo 0 (as linhas) da matriz corresponde aos valores reais, e o eixo 1 (as colunas) aos valores previstos.
| Uso | Retorna | 
|---|
| FeatureCollection.errorMatrix(actual, predicted, order) | ConfusionMatrix | 
| Argumento | Tipo | Detalhes | 
|---|
| isso: collection | FeatureCollection | A coleção de entrada. | 
| actual | String | O nome da propriedade que contém o valor real. | 
| predicted | String | O nome da propriedade que contém o valor previsto. | 
| order | Lista, padrão: nulo | Uma lista dos valores esperados. Se esse argumento não for especificado, os valores serão considerados contíguos e abrangerão o intervalo de 0 a maxValue. Se especificado, somente os valores correspondentes a essa lista serão usados, e a matriz terá dimensões e ordem correspondentes a essa lista. | 
  
  
  Exemplos
  
    
  
  
    
    
  
  
  
  
    
    
    
      Editor de código (JavaScript)
    
    
  /**
 * Classifies features in a FeatureCollection and computes an error matrix.
 */
// Combine Landsat and NLCD images using only the bands representing
// predictor variables (spectral reflectance) and target labels (land cover).
var spectral =
    ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_038032_20160820').select('SR_B[1-7]');
var landcover =
    ee.Image('USGS/NLCD_RELEASES/2016_REL/2016').select('landcover');
var sampleSource = spectral.addBands(landcover);
// Sample the combined images to generate a FeatureCollection.
var sample = sampleSource.sample({
  region: spectral.geometry(),  // sample only from within Landsat image extent
  scale: 30,
  numPixels: 2000,
  geometries: true
})
// Add a random value column with uniform distribution for hold-out
// training/validation splitting.
.randomColumn({distribution: 'uniform'});
print('Sample for classifier development', sample);
// Split out ~80% of the sample for training the classifier.
var training = sample.filter('random < 0.8');
print('Training set', training);
// Train a random forest classifier.
var classifier = ee.Classifier.smileRandomForest(10).train({
  features: training,
  classProperty: landcover.bandNames().get(0),
  inputProperties: spectral.bandNames()
});
// Classify the sample.
var predictions = sample.classify(
    {classifier: classifier, outputName: 'predicted_landcover'});
print('Predictions', predictions);
// Split out the validation feature set.
var validation = predictions.filter('random >= 0.8');
print('Validation set', validation);
// Get a list of possible class values to use for error matrix axis labels.
var order = sample.aggregate_array('landcover').distinct().sort();
print('Error matrix axis labels', order);
// Compute an error matrix that compares predicted vs. expected values.
var errorMatrix = validation.errorMatrix({
  actual: landcover.bandNames().get(0),
  predicted: 'predicted_landcover',
  order: order
});
print('Error matrix', errorMatrix);
// Compute accuracy metrics from the error matrix.
print("Overall accuracy", errorMatrix.accuracy());
print("Consumer's accuracy", errorMatrix.consumersAccuracy());
print("Producer's accuracy", errorMatrix.producersAccuracy());
print("Kappa", errorMatrix.kappa());
  
    
  
  
    
  
  
  
  
    
  
    
  Configuração do Python
  Consulte a página 
    Ambiente Python para informações sobre a API Python e como usar
    geemap para desenvolvimento interativo.
  import ee
import geemap.core as geemap
  
    
    
      Colab (Python)
    
    
  from pprint import pprint
# Classifies features in a FeatureCollection and computes an error matrix.
# Combine Landsat and NLCD images using only the bands representing
# predictor variables (spectral reflectance) and target labels (land cover).
spectral = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_038032_20160820').select(
    'SR_B[1-7]')
landcover = ee.Image('USGS/NLCD_RELEASES/2016_REL/2016').select('landcover')
sample_source = spectral.addBands(landcover)
# Sample the combined images to generate a FeatureCollection.
sample = sample_source.sample(**{
    # sample only from within Landsat image extent
    'region': spectral.geometry(),
    'scale': 30,
    'numPixels': 2000,
    'geometries': True
    })
# Add a random value column with uniform distribution for hold-out
# training/validation splitting.
sample = sample.randomColumn(**{'distribution': 'uniform'})
print('Sample for classifier development:', sample.getInfo())
# Split out ~80% of the sample for training the classifier.
training = sample.filter('random < 0.8')
print('Training set:', training.getInfo())
# Train a random forest classifier.
classifier = ee.Classifier.smileRandomForest(10).train(**{
    'features': training,
    'classProperty': landcover.bandNames().get(0),
    'inputProperties': spectral.bandNames()
    })
# Classify the sample.
predictions = sample.classify(
    **{'classifier': classifier, 'outputName': 'predicted_landcover'})
print('Predictions:', predictions.getInfo())
# Split out the validation feature set.
validation = predictions.filter('random >= 0.8')
print('Validation set:', validation.getInfo())
# Get a list of possible class values to use for error matrix axis labels.
order = sample.aggregate_array('landcover').distinct().sort()
print('Error matrix axis labels:')
pprint(order.getInfo())
# Compute an error matrix that compares predicted vs. expected values.
error_matrix = validation.errorMatrix(**{
    'actual': landcover.bandNames().get(0),
    'predicted': 'predicted_landcover',
    'order': order
    })
print('Error matrix:')
pprint(error_matrix.getInfo())
# Compute accuracy metrics from the error matrix.
print('Overall accuracy:', error_matrix.accuracy().getInfo())
print('Consumer\'s accuracy:')
pprint(error_matrix.consumersAccuracy().getInfo())
print('Producer\'s accuracy:')
pprint(error_matrix.producersAccuracy().getInfo())
print('Kappa:', error_matrix.kappa().getInfo())
  
  
  
  
  
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
  Última atualização 2025-07-26 UTC.
  
  
  
    
      [null,null,["Última atualização 2025-07-26 UTC."],[],["The `errorMatrix` method computes a 2D confusion matrix by comparing actual and predicted values from two columns within a FeatureCollection. It takes `actual` and `predicted` column names as inputs, and an optional `order` list to define the matrix's dimensions and included values. The function uses small contiguous integers starting from 0, and returns a `ConfusionMatrix` object that includes overall accuracy, consumer's accuracy, producer's accuracy and kappa.\n"]]