validateMap: Map accuracy assessment

Description Usage Arguments Note Examples

View source: R/validateMap.R

Description

validate a map from a classification or regression model. This can be useful to update the accuracy assessment after filtering, e.g. for a minimum mapping unit.

Usage

1
2
validateMap(map, valData, responseCol, nSamples = 500,
  mode = "classification", classMapping = NULL)

Arguments

map

RasterLayer. The classified map.

valData

SpatialPolygonsDataFrame or SpatialPointsDataFrame with validation data.

responseCol

Character. Column containing the validation data in attribute table of valData.

nSamples

Integer. Number of pixels to sample for validation (only applies to polygons).

mode

Character. Either 'classification' or 'regression'.

classMapping

optional data.frame with columns 'class' and 'classID' defining the mapping from raster integers to class names.

Note

Polygons, which are smaller than the map resolution will only be considered if they overlap with a pixel center coordinate, otherwise they will be ignored.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## 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)

## End(Not run)

RStoolbox documentation built on July 24, 2019, 1:04 a.m.