predict: Predict random forest model responses

predictR Documentation

Predict random forest model responses

Description

Predict values of random forest model response variables from new data.

Usage

predict(
  model,
  new_data,
  idx = NULL,
  type = c("response", "prob", "votes"),
  ...
)

## S4 method for signature 'RandomForest,AnalysisData'
predict(
  model,
  new_data,
  idx = NULL,
  type = c("response", "prob", "votes"),
  ...
)

Arguments

model

S4 object of class RandomForest

new_data

S4 object of class AnalysisData

idx

sample information column to use for sample names. If NULL, the sample row number will be used. Sample names should be unique for each row of data.

type

one of response, prob, or votes to indicate the type of prediction to make

...

arguments to pass to randomForest::predict.randomForest()

Details

The features contained within new_data should match those of the features used to train model. The features() method can be used to check this. The argument returnModels = TRUE should also be used when training the RandomForest-class object used for argument model.

Examples

library(metaboData)

## Prepare some data
x <- analysisData(abr1$neg[,200:300],abr1$fact) %>%
  occupancyMaximum(cls = 'day') %>%
  transformTICnorm()

## Extract data from which to train a random forest model
training_data <- x %>% 
  keepClasses(cls = 'day',
              classes = c('H','1'))

## Extract data for which response values will be predicted
test_data <- x %>% 
  keepClasses(cls = 'day',
              classes = c('2','3'))

rf <- randomForest(training_data,
                   cls = 'day',
                   returnModels = TRUE)

predict(rf,
        test_data)

jasenfinch/metabolyseR documentation built on Sept. 18, 2023, 1:25 a.m.