KlausVigo / kknn

Weighted k-Nearest Neighbors
http://klausvigo.github.io/kknn/
23 stars 10 forks source link

[Bug] `kknn` returns a vector instead of a matrix for D and C when k = 1 #10

Closed RomeroBarata closed 6 years ago

RomeroBarata commented 6 years ago

Here is a reproducible example:

set.seed(123)
data_train <- data.frame(a = rnorm(3), b = rnorm(3), c = c("X0", "X0", "X1"))
data_test  <- data.frame(a = rnorm(5), b = rnorm(5))

# For k >= 2, knn${CL, W, D, C, prob} are all matrices.
knn <- kknn::kknn(c ~ ., 
                  train = data_train, test = data_test, 
                  k = 2, kernel = "rectangular")
knn$C

# However, for k == 1, knn${CL, W, prob} are matrices while knn${D, C} are vectors.
knn <- kknn::kknn(c ~ ., 
                  train = data_train, test = data_test, 
                  k = 1, kernel = "rectangular")
knn$C
KlausVigo commented 6 years ago

Dear @RomeroBarata, thanks for the bug report. This should be fixed now.