Learn R Programming

CAST (version 0.2.0)

ffs: Forward feature selection

Description

A simple forward feature selection algorithm

Usage

ffs(predictors, response, method = "rf",
  metric = ifelse(is.factor(response), "Accuracy", "RMSE"),
  maximize = ifelse(metric == "RMSE", FALSE, TRUE), withinSE = FALSE,
  trControl = caret::trainControl(), tuneLength = 3, tuneGrid = NULL,
  seed = sample(1:1000, 1), ...)

Arguments

predictors

see train

response

see train

method

see train

metric

see train

maximize

see train

withinSE

Logical Models are only selected if they are better than the currently best models Standard error

trControl

see train

tuneLength

see train

tuneGrid

see train

seed

A random number used for model training

...

arguments passed to the classification or regression routine (such as randomForest). Errors will occur if values for tuning parameters are passed here.

Value

A list of class train. Beside of the usual train content the object contains the vector "selectedvars" and "selectedvars_perf" that give the order of the best variables selected as well as their corresponding performance (starting from the first two variables). It also contains "perf_all" that gives the performance of all model runs.

Details

Models with two predictors are first trained using all possible pairs of predictor variables. The best model of these initial models is kept. On the basis of this best model the predictor variables are iteratively increased and each of the remaining variables is tested for its improvement of the currently best model. The process stops if none of the remaining variables increases the model performance when added to the current best model.

The internal cross validation can be run in parallel. See information on parallel processing of carets train functions for details.

Using withinSE will favour models with less variables and probably shorten the calculation time

References

  • Gasch, C.K., Hengl, T., Gr<U+00E4>ler, B., Meyer, H., Magney, T., Brown, D.J. (2015): Spatio-temporal interpolation of soil water, temperature, and electrical conductivity in 3D+T: the Cook Agronomy Farm data set. Spatial Statistics 14: 70-90.

  • Meyer, H., Reudenbach, C., Hengl, T., Katurji, M., Nau<U+00DF>, T. (2018): Improving performance of spatio-temporal machine learning models using forward feature selection and target-oriented validation. Environmental Modelling & Software 101: 1-9.

See Also

train, trainControl,CreateSpacetimeFolds

Examples

Run this code
# NOT RUN {
data(iris)
ffsmodel <- ffs(iris[,1:4],iris$Species)
ffsmodel$selectedvars
ffsmodel$selectedvars_perf
# }
# NOT RUN {
# or perform model with target-oriented validation (LLO CV)
#the example is taken from the GSIF package and is described
#in Gasch et al. (2015). The ffs approach for this dataset is described in
#Meyer et al. (2018).
#Due to high computation time needed, only a small and thus not robust example
#is shown here. Run it in parallel on 3 cores:
# }
# NOT RUN {
library(doParallel)
cl <- makeCluster(3)
registerDoParallel(cl)

dat <- get(load(system.file("extdata","Cookfarm.RData",package="CAST")))
trainDat <- dat[createDataPartition(dat$VW, p = 0.001,list=FALSE),]
indices <- CreateSpacetimeFolds(trainDat,spacevar = "SOURCEID")
predictors <- c("DEM","TWI","NDRE.M","Bt","BLD","PHI","Precip_cum","cdayt")
ffsmodel <- ffs(trainDat[,predictors],trainDat$VW,method="rf",
trControl=trainControl(method="cv",index=indices$index,indexOut=indices$indexOut),
tuneLength=1)

stopCluster(cl)
# }

Run the code above in your browser using DataLab