~是什么意思。在 R?
What is the meaning of ~. in R?
我想了解~.
在R中的含义。这是kknn函数的一个例子:
library(kknn)
data(iris)
m <- dim(iris)[1]
val <- sample(1:m, size = round(m/3), replace = FALSE, prob = rep(1/m, m))
iris.learn <- iris[-val,]
iris.valid <- iris[val,]
iris.kknn <- kknn(Species~., iris.learn, iris.valid, distance = 1, kernel = "triangular")
summary(iris.kknn)
fit <- fitted(iris.kknn)
table(iris.valid$Species, fit)
它包含在上面的 kknn 函数中,就在 Species 旁边。
谢谢!
这里~是分隔符,.代表所有其他属性。
你的意思是,你必须根据所有其他属性 [.]
来预测 Species~[separator]
如你所见here,
您正在创建一个公式对象。公式documentation表示:
There are two special interpretations of . in a formula. The usual one
is in the context of a data argument of model fitting functions and
means ‘all columns not otherwise in the formula’
因此,在您的情况下,您正在创建一个模型,该模型使用 'Species' 以外的所有其他变量作为预测变量来预测物种。
我想了解~.
在R中的含义。这是kknn函数的一个例子:
library(kknn)
data(iris)
m <- dim(iris)[1]
val <- sample(1:m, size = round(m/3), replace = FALSE, prob = rep(1/m, m))
iris.learn <- iris[-val,]
iris.valid <- iris[val,]
iris.kknn <- kknn(Species~., iris.learn, iris.valid, distance = 1, kernel = "triangular")
summary(iris.kknn)
fit <- fitted(iris.kknn)
table(iris.valid$Species, fit)
它包含在上面的 kknn 函数中,就在 Species 旁边。
谢谢!
这里~是分隔符,.代表所有其他属性。 你的意思是,你必须根据所有其他属性 [.]
来预测 Species~[separator]如你所见here, 您正在创建一个公式对象。公式documentation表示:
There are two special interpretations of . in a formula. The usual one is in the context of a data argument of model fitting functions and means ‘all columns not otherwise in the formula’
因此,在您的情况下,您正在创建一个模型,该模型使用 'Species' 以外的所有其他变量作为预测变量来预测物种。