KNN in R: 'train and class have different lengths'?

前端 未结 5 1137
清酒与你
清酒与你 2020-12-11 01:49

Here is my code:

train_points <- read.table(\"kaggle_train_points.txt\", sep=\"\\t\")
train_labels <- read.table(\"kaggle_train_labels.txt\", sep=\"\\t         


        
5条回答
  •  难免孤独
    2020-12-11 02:13

    I had the same issue in trying to apply knn on breast cancer diagnosis from wisconsin dataset I found that the issue was linked to the fact that cl argument need to be a vector factor (my mistake was to write cl=labels , I thought this was the vector to be predicted it was in fact a data frame of one column ) so the solution was to use the following syntax : knn (train, test,cl=labels$diagnosis,k=21) diagnosis was the header of the one column data frame labels and it worked well Hope this help !

提交回复
热议问题