Function/meaning 的 ~ 。用于插入符号 R 包中的训练功能

Function/meaning of ~ . for train function in caret R package

train(Class ~ ., data = training, 
                 method = "gbm", 
                 trControl = fitControl,
                 ## This last option is actually one
                 ## for gbm() that passes through
                 verbose = FALSE)

我知道 Class 是预测变量,但我不明白的是 meaning/need of ~ .

任何帮助或指向帮助的指示将不胜感激。

PS。我是 R

的新手

这意味着除 medv(在此示例中)之外的任何其他含义,例如公式中的正常用法。基本上,您是在针对数据集中的所有预测变量进行预测。举个例子:

library(caret)
library(mlbench)
data(BostonHousing)
lmFit <- train(medv ~ . + rm:lstat,
               data = BostonHousing,
               method = "lm")

要查看条款,请致电 lmFit$terms。重要的是:

medv ~ crim + zn + indus + chas + nox + rm + age + dis + rad + 
    tax + ptratio + b + lstat + rm:lstat

您可以这样排除:

lmFit <- train(medv ~.-zn -so on -so on  + rm:lstat,
               data = BostonHousing,
               method = "lm")