R 为什么我不断地获取和未使用的参数错误?

R 为什么我不断地获取和未使用的参数错误?,r,knn,R,Knn,我将kNN算法应用于一个包含6个预测器和1个类变量(共1599行)的数据集,我已经多次检查了我的语法,并回顾了其他示例,试图找到我的错误。我现在完全被迷惑了。我已经将数据集分解为测试集、测试集、训练集、训练集。任何帮助都会很棒,请参阅下面的代码和错误 num_obs <- nrow(wine_preds3) # set the sample size to be 80% sample_size <- as.integer(num_obs*0.8) # set the seed for

我将kNN算法应用于一个包含6个预测器和1个类变量(共1599行)的数据集,我已经多次检查了我的语法,并回顾了其他示例,试图找到我的错误。我现在完全被迷惑了。我已经将数据集分解为测试集、测试集、训练集、训练集。任何帮助都会很棒,请参阅下面的代码和错误

num_obs <- nrow(wine_preds3)
# set the sample size to be 80%
sample_size <- as.integer(num_obs*0.8)
# set the seed for the sample split
set.seed(0)
# randomly split 80% the data indexes in reduced wine
split_index <- sample(num_obs, size = sample_size, replace = FALSE)
# subset the reduced wine into a testing subset of 20%
test_wine_preds <- wine_preds3[-split_index, 1:6]
test_wine_class <- wine_preds3[-split_index, 7]
# subset the reduced wine into a training subset of 80%
train_wine_preds <- wine_preds3[split_index, 1:6]
train_wine_class <- wine_preds3[split_index, 7]
Pred_class <- kNN(train = train_wine_preds, test = test_wine_preds, cl = train_wine_class, k = 15)

Error in kNN(train = train_wine_preds, test = test_wine_preds, cl = train_wine_class,  : 
  unused arguments (train = train_wine_preds, test = test_wine_preds, cl = train_wine_class)

num\u obs您使用了什么类型的knn软件包?我认为您使用了错误的函数。您的命令看起来应该使用类包中的
knn
。如果我正确,您使用的是
knn
,并将其误认为
knn
(小写)。形式是
class::knn(train,test,cl,k=1,l=0,prob=FALSE,use.all=TRUE)
dbscan::knn(x,k,query=NULL,sort=TRUE,search=“kdtree”,bucketSize=10,splitRule=“suggest”,approx=0)
(非常不同的参数列表)。谢谢大家,这么简单的事情。我似乎总是这样。@r2evans你应该在下面回答这个问题!