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

前端 未结 5 1134
清酒与你
清酒与你 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:27

    Without access to the data, it's really hard to help. However, I suspect that train_labels should be a vector. So try

    cl = train_labels[,1]
    knn(train_points, test_points, cl, k = 5)
    

    Also double check:

    dim(train_points)
    dim(test_points)
    length(cl)
    

提交回复
热议问题