2

I am trying to implement Knn using dtw as distance measure in R. Below is the code am trying to implement

## KNN + DTW
knn <- function(inputData, k){
   n <- nrow(inputData)
   if (n <= k) stop("Value of k should be <= k-1")
   neigh <- matrix(0, nrow = n, ncol = k)
   library(dtw)
   dist2.inputData <- dtw(inputData, inputData)
  for(i in 1:n) {
      dtw.dist <- dist2.inputData[i,]
      neigh[i, ] <- order(dtw.dist)[2:(k + 1)]
 }
   return(neigh)
}

But when I run this using dataset from UCR I get the error message below;

 predKit <- knn(inputData = TRAIN, k =3)

Error in cpp_cm(Q, C, dist_method = dist_method, ws = ws_cpp, nPrevObs = 0) : could not find function "cpp_cm"

Christoph
  • 6,529
  • 3
  • 38
  • 79

0 Answers0