predict2: Extract predictions train objects using a threshold

View source: R/predict2.R

predict2R Documentation

Extract predictions train objects using a threshold

Description

This function is a wrapper around predict.train, but it accepts a threshold cutoff to calculate predictions from class probabilities.

Usage

predict2(object, ...)

## S3 method for class 'train'
predict2(object, newdata = NULL, type = "raw", doclamp = FALSE, ...)

## S3 method for class 'list'
predict2(object, ...)

## S3 method for class 'RasterStack'
predict2(object, model, doclamp = FALSE, ...)

Arguments

object, model

A model returned by train or a list of models. object can also be a RasterStack from the raster package, used to create predictions.

...

Further arguments passed to predict or method 'train'.

newdata

An optional set of data to predict on.

type

One of "raw", "prob", "both", "both1" or "prob1" (see details).

doclamp

logical. Clamp newdata or RasterStack based on training data?

Details

Most arguments work the same as predict.train.

This function is only useful for two class Classification problems, when using type = "raw" and a different threshold from the default (which must set using setThreshold). Otherwise, the output is the same as predict.

Additionally, you can set type = "both", which will return a data.frame with all class probabilities and a prediction, type = "prob1" to return a single vector with the first class probabilities (assumed to be presence). type = "both1" will return class prediction and the first class probabilities.

The method for RasterStack is a simpler version of raster::predict, but it may be faster sometimes.

Value

A vector or data.frame with predictions or probabilities, based on the argument type. Check details. If model is a list of models, than a list of predictions is returned.

See Also

setThreshold clamp_data


correapvf/caretSDM documentation built on June 2, 2022, 8:29 a.m.