Announcement : All noncommercial projects registered to use Earth Engine before
April 15, 2025 must
verify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.
Send feedback
ee.Classifier.smileGradientTreeBoost
Stay organized with collections
Save and categorize content based on your preferences.
Creates an empty Gradient Tree Boost classifier.
Usage Returns ee.Classifier.smileGradientTreeBoost(numberOfTrees, shrinkage , samplingRate , maxNodes , loss , seed )
Classifier
Argument Type Details numberOfTrees
Integer The number of decision trees to create. shrinkage
Float, default: 0.005 The shrinkage parameter in (0, 1] controls the learning rate of procedure. samplingRate
Float, default: 0.7 The sampling rate for stochastic tree boosting. maxNodes
Integer, default: null The maximum number of leaf nodes in each tree. If unspecified, defaults to no limit. loss
String, default: "LeastAbsoluteDeviation" Loss function for regression. One of: LeastSquares, LeastAbsoluteDeviation, Huber. seed
Integer, default: 0 The randomization seed.
Examples
Code Editor (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 a 10-tree gradient boosting classifier from the training sample.
var trainedClassifier = ee . Classifier . smileGradientTreeBoost ( 10 ). 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 setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
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 a 10-tree gradient boosting classifier from the training sample.
trained_classifier = ee . Classifier . smileGradientTreeBoost ( 10 ) . 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
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eCreates an empty Gradient Tree Boost classifier for regression or classification tasks.\u003c/p\u003e\n"],["\u003cp\u003eThe classifier uses decision trees with parameters for controlling the number of trees, learning rate, and sampling rate.\u003c/p\u003e\n"],["\u003cp\u003eOptional parameters allow customization of the maximum number of leaf nodes, loss function, and randomization seed.\u003c/p\u003e\n"],["\u003cp\u003eIt can be trained using the \u003ccode\u003etrain()\u003c/code\u003e method with a FeatureCollection and class property.\u003c/p\u003e\n"]]],["The content describes the `ee.Classifier.smileGradientTreeBoost` function, which creates a Gradient Tree Boost classifier. Key actions include: defining parameters like `numberOfTrees`, `shrinkage`, `samplingRate`, `maxNodes`, `loss`, and `seed`; training the classifier using a sample dataset; and using the trained classifier to perform classifications on images. The classifier's performance is then evaluated through confusion matrices and accuracy scores, based on both training and validation datasets.\n"],null,[]]