0 Replies Latest reply on Apr 28, 2018 3:18 AM by Biplab Muduli

    R integration for K Nearest Neighbor in Tableau

    Biplab Muduli



        I am new to R integration in Tableau. I was trying to visualize KNN for IRIS data in Tableau. When i tried in R it's success, but i am getting an error while integrating the same in Tableau.

        I used the following script as calculated field :-

        KNN :- 



      gp <- runif(nrow(iris))

      iris <- iris[order(gp), ]

      normalize <- function(x) { return( (x - min(x)) / (max(x) - min(x)) ) }

      iris_new <- as.data.frame(lapply(iris[,c(1,2,3,4)], normalize))

      iris_train <- iris_new[1:129, ]

      iris_test <- iris_new[130:150, ]

      iris_train_target <- iris[1:129, 5]

      iris_test_target <- iris[130:150, 5]



      .arg1 <- iris_train

      .arg2 <- iris_test

      .arg3 <- iris_train_target



      kNN(as.matrix(data.frame(train= .arg1, test= .arg2, cl= .arg3)), k=13)


      SUM([Petal Length]),

      SUM([Petal Width]),

      SUM([Sepal Length]),

      SUM([Sepal Width]))


      and getting an error like :- An error occurred while communicating  with the RServe service. Error in data.frame(train= .arg1, test= .arg2, cl= .arg3) : arguments imply differing number of

      rows: 129, 21. 

      I have attached  a screen shot for this error and the dashboard as well.


      Any help to resolve this error is greatly appreciated.


      Thanks and Regards,