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,841
  • 4
  • 37
  • 89
Alex Uyi
  • 41
  • 7
  • 2
    Please provide a minimal reproducible example. – Christoph Oct 12 '18 at 15:32
  • For reproduciblity, some refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Oct 12 '18 at 15:50
  • 1
    Thanks @Christoph, @ r2evans... I have been able to sort what the problem was and the code works fine now. – Alex Uyi Oct 14 '18 at 02:12

0 Answers0