predict.trainOcc: Predict method for 'trainOcc' objects.

Description Usage Arguments Value Note Examples

View source: R/predict.trainOcc.R

Description

The prediction works on usual matrices/data frames, the raster* and rasterTiled objects. If a parallel backend for foreach (e.g. via doParallel) is used for the prediction of raster* and rasterTiled objects. Small data sets are are processed faster sequentially due to the parallel overhead.

Usage

1
2
3
4
## S3 method for class 'trainOcc'
predict(object, newdata, type = "prob",
  allowParallel = TRUE, returnRaster = TRUE, mask = NULL,
  noWarnWithParRasPred = TRUE, ...)

Arguments

object

a trainOcc object

newdata

new data to predict on.

type

default is 'prob' which however returns the continuous decision values (see note!)

allowParallel

should parallel processing be allowed.

returnRaster

default TRUE

mask

if given and if returnRaster=TRUE only predictions of the valid cells are returned.

noWarnWithParRasPred

Supresses warning when predicting in parallel with spatial.tools. It always causes the following warning message for each worker: "In .local(x, ...) : min value not known, use setMinMax".

...

other arguments that can be passed to predict.train.

Value

the predicted data, eventually returned as rasterLayer.

Note

type='probs' does NOT return probabilities but the continuous decision values of the classifier, e.g. distances in the case of the one-class and biased svm) and not probabilities!

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
data(bananas)
### fit a model
fit <- trainOcc (x = bananas$tr[, -1], y = bananas$tr[, 1], method="biasedsvm", 
                 tuneGrid=expand.grid(sigma=c(0.1, 1), 
                                      cNeg=2^seq(-4, 2, 2), 
                                      cMultiplier=2^seq(4, 8, 2) ) )
# predict a raster
pred <- predict(fit, bananas$x)
plot(pred)

# register a parallel backend and predict in parallel with rasterEngine of spatial.tools
require(doParallel) # or use another parallel backend for foreach
cl <- makeCluster(detectCores()-1) # leave one core free if you don't want to go for coffee
registerDoParallel(cl)
pred <- predict(fit, bananas$x)
plot(pred)
stopCluster(cl)

## End(Not run)

benmack/oneClass documentation built on Dec. 15, 2020, 7:38 p.m.