KNN in R: ‘train and class have different lengths’?

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)

Leave a Comment