kknn分类:如何确定kmax的值?

时间:2019-03-31 01:50:06

标签: r classification knn

如何确定要使用的kmax的值?当我消除它时,R打印一条错误消息,而当我添加它时,R打印另一条错误消息。我一直四处走动,这无处可去。这些消息令人困惑。我在stackoverflow上查找了类似的问题,但没有看到一个问题,因此是这个问题。你知道为什么kmax = 7不正确吗?我如何知道kmax的正确值?感谢您的任何帮助,您可以提供。

#works
output1 <- train.kknn( as.factor(myParam)~., data <- trainingData)
output1

#works
output1 <- train.kknn( as.factor(myParam)~., data <- trainingData, distance <- 2)
output1

# does not work
#error message: Error in train.kknn(as.factor(myParam) ~ ., data <- trainingData, kmax <- 7,  : 
  NA/NaN/Inf in foreign function call (arg 9)
In addition: Warning message:
In train.kknn(as.factor(myParam) ~ ., data <- trainingData, kmax <- 7,  :  
NAs introduced by coercion

output1 <- train.kknn( as.factor(myParam)~.,  data <- trainingData, kmax <- 7, distance <- 2,kernel <- "rectangular")
output1


# does not work, 
# error message: Error in kmax + 2L : non-numeric argument to binary operator

output1 <- train.kknn( as.factor(myParam)~., data <- trainingData,  distance <- 2, kernel <- "rectangular")
output1

我需要这个才能工作:

output1 <- train.kknn( as.factor(myParam)~.,  data <- trainingData,
                     kmax <- ???,    <-  whatever this value should be
                     distance <- 2, kernel <- "rectangular")
output1

1 个答案:

答案 0 :(得分:0)

lmo的回答就是答案。谢谢lmo帮助我看到光。