# NOT RUN {
library(caret)
library(raster)
## Training data
data(lsat)
poly <- readRDS(system.file("external/trainingPolygons.rds", package="RStoolbox"))
## Split training data in training and validation set (50%-50%)
splitIn <- createDataPartition(poly$class, p = .5)[[1]]
train <- poly[splitIn,]
val <- poly[-splitIn,]
## Classify (deliberately poorly)
sc <- superClass(lsat, trainData = train, responseCol = "class", nSamples = 50, model = "mlc")
## Polish map with majority filter
polishedMap <- focal(sc$map, matrix(1,3,3), fun = modal)
## Validation
## Before filtering
val0 <- validateMap(sc$map, valData = val, responseCol = "class",
classMapping = sc$classMapping)
## After filtering
val1 <- validateMap(polishedMap, valData = val, responseCol = "class",
classMapping = sc$classMapping)
# }
Run the code above in your browser using DataLab