2

I try to use T-sne in R. I want to use dtw instead of Euclidean distance. How can I change the spec in R?

Executing the algorithm on curated data

library(Rtsne)

tsne <- Rtsne(train[,-1], dims = 2, perplexity=30, verbose=TRUE, max_iter = 500)
tSNE
exeTimeTsne<- system.time(Rtsne(train[,-1], dims = 2, perplexity=30, verbose=TRUE, max_iter = 500))
Anonymous coward
  • 2,061
  • 1
  • 16
  • 29
차태희
  • 21
  • 2
  • 1
    I don't know what dynamic time warping is, but if it creates a distance matrix, you can supply it instead of it computing Euclidean distances. See `?Rtsne` for help. – Anonymous coward Nov 14 '18 at 15:22
  • You mean that i have to make a dtw distance matrix first. The class of data X becomes a dist. And then change "is_distance=true" in Rtsne. is that right? – 차태희 Nov 14 '18 at 23:19
  • @Anonymouscoward: could you turn this into an answer for a given distance metric, say `bray-curtis` or `manhattan`? Thank you! – crazysantaclaus Jul 08 '19 at 07:51
  • 1
    I can post an answer, but bear in mind I'm not familiar with `Rtsne`, so I'm just plugging a matrix in. – Anonymous coward Jul 08 '19 at 14:57

1 Answers1

1

You can supply any distance matrix to Rtsne using a method of your choosing, and setting the is_distance flag to TRUE. See the Supplying precomputed distances section of ?Rtsne for more info.

library(Rtsne)
library(vegan)

df = data.frame(A = c(4, 11, 17, 0, 2, 4, 8, 10, 2, 4),
                B = c(6, 10, 7, 2, 21, 3, 3, 0, 2, 17),
                C = c(5, 2, 3, 12, 12, 14, 0, 7, 8, 2),
                D = c(7, 16, 24, 18, 31, 8, 2, 21, 3, 13))


bc <- vegdist(df, method = "bray")
tSNE <- Rtsne(bc, is_distance = TRUE, dims = 2, perplexity = 2, verbose = TRUE, max_iter = 500)
Anonymous coward
  • 2,061
  • 1
  • 16
  • 29