Thông báo: Tất cả dự án phi thương mại đã đăng ký sử dụng Earth Engine trước 
ngày 15 tháng 4 năm 2025 phải 
xác minh điều kiện sử dụng phi thương mại để duy trì quyền truy cập. Nếu bạn chưa xác minh trước ngày 26 tháng 9 năm 2025, quyền truy cập của bạn có thể bị tạm ngưng.
  
        
 
       
     
  
  
  
    
  
  
  
    
      ee.FeatureCollection.errorMatrix
    
    
      
    
    
      
      Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
    
    
      
      Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
    
  
  
      
    
  
  
  
  
  
    
  
  
    
    
    
  
  
Tính toán ma trận lỗi 2D cho một tập hợp bằng cách so sánh hai cột của một tập hợp: một cột chứa các giá trị thực tế và một cột chứa các giá trị dự đoán. Các giá trị dự kiến là các số nguyên nhỏ liên tiếp, bắt đầu từ 0. Trục 0 (các hàng) của ma trận tương ứng với các giá trị thực tế và Trục 1 (các cột) tương ứng với các giá trị dự đoán.
| Cách sử dụng | Giá trị trả về | 
|---|
| FeatureCollection.errorMatrix(actual, predicted, order) | ConfusionMatrix | 
| Đối số | Loại | Thông tin chi tiết | 
|---|
| this: collection | FeatureCollection | Tập hợp đầu vào. | 
| actual | Chuỗi | Tên của thuộc tính chứa giá trị thực tế. | 
| predicted | Chuỗi | Tên của thuộc tính chứa giá trị được dự đoán. | 
| order | Danh sách, mặc định: null | Danh sách các giá trị dự kiến. Nếu bạn không chỉ định đối số này, các giá trị được giả định là liền kề và trải dài trong phạm vi từ 0 đến maxValue. Nếu được chỉ định, chỉ những giá trị khớp với danh sách này mới được dùng và ma trận sẽ có các phương diện và thứ tự khớp với danh sách này. | 
  
  
  Ví dụ
  
    
  
  
    
    
  
  
  
  
    
    
    
      Trình soạn thảo mã (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());
  
    
  
  
    
  
  
  
  
    
  
    
  Thiết lập Python
  Hãy xem trang 
    Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.
  import ee
import geemap.core as geemap
  
    
    
      Colab (Python)
    
    
  # 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'})
display('Sample for classifier development:', sample)
# Split out ~80% of the sample for training the classifier.
training = sample.filter('random < 0.8')
display('Training set:', training)
# 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'})
display('Predictions:', predictions)
# Split out the validation feature set.
validation = predictions.filter('random >= 0.8')
display('Validation set:', validation)
# Get a list of possible class values to use for error matrix axis labels.
order = sample.aggregate_array('landcover').distinct().sort()
display('Error matrix axis labels:', order)
# Compute an error matrix that compares predicted vs. expected values.
error_matrix = validation.errorMatrix(**{
    'actual': landcover.bandNames().get(0),
    'predicted': 'predicted_landcover',
    'order': order
    })
display('Error matrix:', error_matrix)
# Compute accuracy metrics from the error matrix.
display('Overall accuracy:', error_matrix.accuracy())
display('Consumer\'s accuracy:', error_matrix.consumersAccuracy())
display('Producer\'s accuracy:', error_matrix.producersAccuracy())
display('Kappa:', error_matrix.kappa())
  
  
  
  
  
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
  Cập nhật lần gần đây nhất: 2025-10-30 UTC.
  
  
  
    
      [null,null,["Cập nhật lần gần đây nhất: 2025-10-30 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"]]