Learn R Programming

caret (version 6.0-71)

nullModel: Fit a simple, non-informative model

Description

Fit a single mean or largest class model

Usage

nullModel(x, ...)
"nullModel"(x = NULL, y, ...)
"predict"(object, newdata = NULL, type = NULL, ...)

Arguments

x
An optional matrix or data frame of predictors. These values are not used in the model fit
y
A numeric vector (for regression) or factor (for classification) of outcomes
...
Optional arguments (not yet used)
object
An object of class nullModel
newdata
A matrix or data frame of predictors (only used to determine the number of predictions to return)
type
Either "raw" (for regression), "class" or "prob" (for classification)

Value

The output of nullModel is a list of class nullModel with elementspredict.nullModel returns a either a factor or numeric vector depending on the class of y. All predictions are always the same.

Details

nullModel emulates other model building functions, but returns the simplest model possible given a training set: a single mean for numeric outcomes and the most prevalent class for factor outcomes. When class probabilities are requested, the percentage of the training set samples with the most prevalent class is returned.

Examples

Run this code
outcome <- factor(sample(letters[1:2], 
                         size = 100, 
                         prob = c(.1, .9), 
                         replace = TRUE))
useless <- nullModel(y = outcome)
useless
predict(useless, matrix(NA, nrow = 10))

Run the code above in your browser using DataLab