ee.Classifier.libsvm

สร้างตัวแยกประเภท Support Vector Machine ที่ว่างเปล่า

การใช้งานการคืนสินค้า
ee.Classifier.libsvm(decisionProcedure, svmType, kernelType, shrinking, degree, gamma, coef0, cost, nu, terminationEpsilon, lossEpsilon, oneClass)ตัวแยกประเภท
อาร์กิวเมนต์ประเภทรายละเอียด
decisionProcedureสตริง ค่าเริ่มต้น: "การโหวต"กระบวนการตัดสินใจที่จะใช้สำหรับการจัดประเภท "การโหวต" หรือ "ขอบ" ไม่ได้ใช้สำหรับการถดถอย
svmTypeString, ค่าเริ่มต้น: "C_SVC"ประเภท SVM ค่าใดค่าหนึ่งต่อไปนี้ `C_SVC`, `NU_SVC`, `ONE_CLASS`, `EPSILON_SVR` หรือ `NU_SVR`
kernelTypeString, ค่าเริ่มต้น: "LINEAR"ประเภทเคอร์เนล LINEAR (u′×v), POLY ((γ×u′×v + coef₀)ᵈᵉᵍʳᵉᵉ), RBF (exp(-γ×|u-v|²)) หรือ SIGMOID (tanh(γ×u′×v + coef₀))
shrinkingบูลีน ค่าเริ่มต้น: จริงดูว่าจะใช้ฮิวริสติกการลดขนาดหรือไม่
degreeจำนวนเต็ม ค่าเริ่มต้น: nullดีกรีของพหุนาม ใช้ได้กับเคอร์เนล POLY
gammaลอย ค่าเริ่มต้น: nullค่าแกมมาในฟังก์ชันเคอร์เนล ค่าเริ่มต้นคือส่วนกลับของจำนวนฟีเจอร์ ใช้ได้กับเคอร์เนล POLY, RBF และ SIGMOID
coef0ลอย ค่าเริ่มต้น: nullค่า coef₀ ในฟังก์ชันเคอร์เนล ค่าเริ่มต้นคือ 0 ใช้ได้กับเคอร์เนล POLY และ SIGMOID
costลอย ค่าเริ่มต้น: nullพารามิเตอร์ต้นทุน (C) ค่าเริ่มต้นคือ 1 ใช้ได้กับ C-SVC, epsilon-SVR และ nu-SVR เท่านั้น
nuลอย ค่าเริ่มต้น: nullพารามิเตอร์ nu ค่าเริ่มต้นคือ 0.5 ใช้ได้กับ nu-SVC, SVM แบบคลาสเดียว และ nu-SVR เท่านั้น
terminationEpsilonลอย ค่าเริ่มต้น: nullค่าความคลาดเคลื่อนของเกณฑ์การสิ้นสุด (จ) ค่าเริ่มต้นคือ 0.001 ใช้ได้กับ epsilon-SVR เท่านั้น
lossEpsilonลอย ค่าเริ่มต้น: nullค่าเอปซิลอนในฟังก์ชันการสูญเสีย (p) ค่าเริ่มต้นคือ 0.1 ใช้ได้กับ epsilon-SVR เท่านั้น
oneClassจำนวนเต็ม ค่าเริ่มต้น: nullคลาสของข้อมูลการฝึกที่จะใช้ฝึกใน SVM แบบคลาสเดียว ค่าเริ่มต้นคือ 0 ใช้ได้กับ SVM แบบคลาสเดียวเท่านั้น ค่าที่เป็นไปได้คือ 0 และ 1 เอาต์พุตของตัวแยกประเภทเป็นแบบไบนารี (0/1) และจะตรงกับค่าของคลาสนี้สำหรับข้อมูลที่กำหนดให้อยู่ในคลาส

ตัวอย่าง

โปรแกรมแก้ไขโค้ด (JavaScript)

// A Sentinel-2 surface reflectance image, reflectance bands selected,
// serves as the source for training and prediction in this contrived example.
var img = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG')
              .select('B.*');

// ESA WorldCover land cover map, used as label source in classifier training.
var lc = ee.Image('ESA/WorldCover/v100/2020');

// Remap the land cover class values to a 0-based sequential series.
var classValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100];
var remapValues = ee.List.sequence(0, 10);
var label = 'lc';
lc = lc.remap(classValues, remapValues).rename(label).toByte();

// Add land cover as a band of the reflectance image and sample 100 pixels at
// 10 m scale from each land cover class within a region of interest.
var roi = ee.Geometry.Rectangle(-122.347, 37.743, -122.024, 37.838);
var sample = img.addBands(lc).stratifiedSample({
  numPoints: 100,
  classBand: label,
  region: roi,
  scale: 10,
  geometries: true
});

// Add a random value field to the sample and use it to approximately split 80%
// of the features into a training set and 20% into a validation set.
sample = sample.randomColumn();
var trainingSample = sample.filter('random <= 0.8');
var validationSample = sample.filter('random > 0.8');

// Train an SVM classifier (C-SVM classification, voting decision procedure,
// linear kernel) from the training sample.
var trainedClassifier = ee.Classifier.libsvm().train({
  features: trainingSample,
  classProperty: label,
  inputProperties: img.bandNames()
});

// Get information about the trained classifier.
print('Results of trained classifier', trainedClassifier.explain());

// Get a confusion matrix and overall accuracy for the training sample.
var trainAccuracy = trainedClassifier.confusionMatrix();
print('Training error matrix', trainAccuracy);
print('Training overall accuracy', trainAccuracy.accuracy());

// Get a confusion matrix and overall accuracy for the validation sample.
validationSample = validationSample.classify(trainedClassifier);
var validationAccuracy = validationSample.errorMatrix(label, 'classification');
print('Validation error matrix', validationAccuracy);
print('Validation accuracy', validationAccuracy.accuracy());

// Classify the reflectance image from the trained classifier.
var imgClassified = img.classify(trainedClassifier);

// Add the layers to the map.
var classVis = {
  min: 0,
  max: 10,
  palette: ['006400' ,'ffbb22', 'ffff4c', 'f096ff', 'fa0000', 'b4b4b4',
            'f0f0f0', '0064c8', '0096a0', '00cf75', 'fae6a0']
};
Map.setCenter(-122.184, 37.796, 12);
Map.addLayer(img, {bands: ['B11', 'B8', 'B3'], min: 100, max: 3500}, 'img');
Map.addLayer(lc, classVis, 'lc');
Map.addLayer(imgClassified, classVis, 'Classified');
Map.addLayer(roi, {color: 'white'}, 'ROI', false, 0.5);
Map.addLayer(trainingSample, {color: 'black'}, 'Training sample', false);
Map.addLayer(validationSample, {color: 'white'}, 'Validation sample', false);

การตั้งค่า Python

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

import ee
import geemap.core as geemap

Colab (Python)

# A Sentinel-2 surface reflectance image, reflectance bands selected,
# serves as the source for training and prediction in this contrived example.
img = ee.Image(
    'COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG'
).select('B.*')

# ESA WorldCover land cover map, used as label source in classifier training.
lc = ee.Image('ESA/WorldCover/v100/2020')

# Remap the land cover class values to a 0-based sequential series.
class_values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100]
remap_values = ee.List.sequence(0, 10)
label = 'lc'
lc = lc.remap(class_values, remap_values).rename(label).toByte()

# Add land cover as a band of the reflectance image and sample 100 pixels at
# 10 m scale from each land cover class within a region of interest.
roi = ee.Geometry.Rectangle(-122.347, 37.743, -122.024, 37.838)
sample = img.addBands(lc).stratifiedSample(
    numPoints=100, classBand=label, region=roi, scale=10, geometries=True
)

# Add a random value field to the sample and use it to approximately split 80%
# of the features into a training set and 20% into a validation set.
sample = sample.randomColumn()
training_sample = sample.filter('random <= 0.8')
validation_sample = sample.filter('random > 0.8')

# Train an SVM classifier (C-SVM classification, voting decision procedure,
# linear kernel) from the training sample.
trained_classifier = ee.Classifier.libsvm().train(
    features=training_sample,
    classProperty=label,
    inputProperties=img.bandNames(),
)

# Get information about the trained classifier.
display('Results of trained classifier', trained_classifier.explain())

# Get a confusion matrix and overall accuracy for the training sample.
train_accuracy = trained_classifier.confusionMatrix()
display('Training error matrix', train_accuracy)
display('Training overall accuracy', train_accuracy.accuracy())

# Get a confusion matrix and overall accuracy for the validation sample.
validation_sample = validation_sample.classify(trained_classifier)
validation_accuracy = validation_sample.errorMatrix(label, 'classification')
display('Validation error matrix', validation_accuracy)
display('Validation accuracy', validation_accuracy.accuracy())

# Classify the reflectance image from the trained classifier.
img_classified = img.classify(trained_classifier)

# Add the layers to the map.
class_vis = {
    'min': 0,
    'max': 10,
    'palette': [
        '006400',
        'ffbb22',
        'ffff4c',
        'f096ff',
        'fa0000',
        'b4b4b4',
        'f0f0f0',
        '0064c8',
        '0096a0',
        '00cf75',
        'fae6a0',
    ],
}
m = geemap.Map()
m.set_center(-122.184, 37.796, 12)
m.add_layer(
    img, {'bands': ['B11', 'B8', 'B3'], 'min': 100, 'max': 3500}, 'img'
)
m.add_layer(lc, class_vis, 'lc')
m.add_layer(img_classified, class_vis, 'Classified')
m.add_layer(roi, {'color': 'white'}, 'ROI', False, 0.5)
m.add_layer(training_sample, {'color': 'black'}, 'Training sample', False)
m.add_layer(
    validation_sample, {'color': 'white'}, 'Validation sample', False
)
m