# NOT RUN {
# get the samples for Mato Grosso for bands NDVI and EVI
samples_mt_ndvi <- sits_select(samples_mt_4bands, bands = c("NDVI"))
# filter the samples for three classes (to simplify the example)
samples_mt_ndvi <- dplyr::filter(samples_mt_ndvi, label %in%
c("Forest", "Pasture", "Soy_Corn"))
# build an XGB model
xgb_model <- sits_train(
samples_mt_ndvi,
sits_xgboost(nrounds = 10, verbose = FALSE)
)
# files that make up the data cube
ndvi_file <- c(system.file("extdata/raster/mod13q1/sinop-ndvi-2014.tif",
package = "sits"
))
# create the data cube
sinop_2014 <- sits_cube(
type = "BRICK",
name = "sinop-2014",
timeline = timeline_2013_2014,
satellite = "TERRA",
sensor = "MODIS",
bands = c("NDVI"),
files = c(ndvi_file)
)
# classify the data cube with xgb model
sinop_2014_probs <- sits_classify(sinop_2014,
xgb_model,
output_dir = tempdir(),
memsize = 4,
multicores = 1
)
# label the classification
sinop_2014_label <- sits_label_classification(sinop_2014_probs,
output_dir = tempdir()
)
# get ground truth points
ground_truth <- system.file("extdata/samples/samples_sinop_crop.csv",
package = "sits"
)
# calculate accuracy according to Olofsson's method
accuracy <- suppressWarnings(sits_accuracy(sinop_2014_label, ground_truth))
# }
Run the code above in your browser using DataLab