ee.FeatureCollection.errorMatrix

यह फ़ंक्शन, किसी कलेक्शन के लिए 2D गड़बड़ी मैट्रिक्स का हिसाब लगाता है. इसके लिए, यह कलेक्शन के दो कॉलम की तुलना करता है. इनमें से एक कॉलम में असल वैल्यू होती हैं और दूसरे में अनुमानित वैल्यू होती हैं. वैल्यू, 0 से शुरू होने वाले छोटे पूर्णांक होने चाहिए. मैट्रिक्स का ऐक्सिस 0 (लाइनें), असल वैल्यू से मेल खाता है. वहीं, ऐक्सिस 1 (कॉलम), अनुमानित वैल्यू से मेल खाता है.

इस्तेमालरिटर्न
FeatureCollection.errorMatrix(actual, predicted, order)ConfusionMatrix
आर्ग्यूमेंटटाइपविवरण
यह: collectionFeatureCollectionइनपुट कलेक्शन.
actualस्ट्रिंगउस प्रॉपर्टी का नाम जिसमें असल वैल्यू मौजूद है.
predictedस्ट्रिंगउस प्रॉपर्टी का नाम जिसमें अनुमानित वैल्यू शामिल है.
orderसूची, डिफ़ॉल्ट: nullअनुमानित वैल्यू की सूची. अगर इस आर्ग्युमेंट को तय नहीं किया जाता है, तो वैल्यू को लगातार माना जाता है. साथ ही, यह माना जाता है कि वैल्यू 0 से लेकर maxValue तक है. अगर इस सूची को तय किया जाता है, तो सिर्फ़ इससे मेल खाने वाली वैल्यू का इस्तेमाल किया जाता है. साथ ही, मैट्रिक्स में डाइमेंशन और क्रम, इस सूची से मेल खाएंगे.

उदाहरण

कोड एडिटर (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());

Python सेटअप करना

Python API और इंटरैक्टिव डेवलपमेंट के लिए geemap का इस्तेमाल करने के बारे में जानकारी पाने के लिए, Python एनवायरमेंट पेज देखें.

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())