Why in Google Earth engine after SVM classification, despite that the overall accuracy is close to 80%, but the kappa coefficient shows zero? Where is the mistake?
My code is following:
var image = ee.Image(ee.ImageCollection('COPERNICUS/S2')
.filterBounds(roi)
.filterDate('2020-07-01', '2020-09-01')
.sort('CLOUD_COVER')
.first()
.clip(roi));
Map.addLayer(image, {bands: ['B8', 'B4', 'B2'],min:0, max: 3000}, 'False colour image');
print(image);
Map.addLayer(roi);
Map.centerObject(roi);
Map.addLayer(table);
// Compute the Normalized Difference Vegetation Index (NDVI).
var nir = image.select('B8');
var red = image.select('B4');
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('ndvi');
// Display the result.
Map.centerObject(image, 9);
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(ndvi, ndviParams, 'ndvi');
// Compute the EVI using an expression.
var evi = image.expression(
'2.5 * ((NIR-RED) / (NIR + 6 * RED - 7.5* BLUE +1))', {
NIR:image.select('B4'),
RED:image.select('B3'),
BLUE:image.select('B1')
})
.rename('evi');
Map.centerObject(image, 9);
var eviParams = {min: -1, max: 1, palette: ['FF0000', '00FF00']};
Map.addLayer(evi, eviParams, 'evi');
// Compute OSAVI.
var nir = image.select('B8');
var red = image.select('B4');
var osavi = nir.subtract(red).divide(nir.add(red).add(0.16)).rename('osavi');
Map.centerObject(image, 9);
var osaviParams = {min: -1, max: 1, palette: ['red', 'white', 'blue']};
Map.addLayer(osavi, osaviParams, 'osavi');
// Compute SR index
var nir = image.select('B8');
var red = image.select('B4');
var sr = nir.divide(red).rename('sr');
image = ee.Image([image, ndvi, evi, osavi, sr]);
print(image.bandNames());
var classNames = tNO.merge(tO);
print(classNames);
var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'B9', 'B10', 'B11', 'B12', 'QA10', 'QA20', 'QA60', 'ndvi', 'evi', 'osavi', 'sr'];
var training = image.select(bands).sampleRegions({
collection: classNames,
properties: ['landcover'],
scale: 30
});
print(training);
// Create an SVM classifier with custom parameters.
var classifier = ee.Classifier.libsvm({
kernelType: 'RBF',
gamma: 0.5,
cost: 10
});
// Train the classifier.
var trained = classifier.train(training, 'landcover', bands);
// Classify the image.
var classified = image.classify(trained);
//Display classification
Map.centerObject(classNames);
Map.addLayer(classified,
{min: 0, max: 1, palette: ['fffd0c', '2b8908']},
'classification');
//Merge into one FeatureCollection
var valNames = NO.merge(O);
var validation = classified.sampleRegions({
collection: valNames,
properties: ['landcover'],
scale: 30,
});
print(validation);
//Compare the landcover of your validation data against the classification result
var testAccuracy = validation.errorMatrix('landcover', 'classification');
//Print the error matrix to the console
print('Validation error matrix: ', testAccuracy);
//Print the overall accuracy to the console
print('Validation overall accuracy: ', testAccuracy.accuracy());
var Kappa = testAccuracy.kappa();
print(Kappa, 'kappa');