4

I want to use T-SNE to visualize user's variable but I want to be able to join the data to the user's social information.

Unfortunately, the output of Rtsne doesn't seems to return data with the user id..

The data looks like this:

  client_id recency frequen monetary
1         2       1       1        1
2         3       3       1        2
3         4       1       1        2
4         5       3       1        1
5         6       4       1        2
6         7       5       1        1

and the Rtsne output:

           x           y
1  -6.415009  -0.4726438
2 -16.027732  -9.3751709
3  17.947615   0.2561859
4   1.589996  13.8016613
5  -9.332319 -13.2144419
6  10.545698   8.2165265

and the code:

tsne = Rtsne(rfm[, -1], dims=2, check_duplicates=F)
David Arenburg
  • 91,361
  • 17
  • 137
  • 196
MathLal
  • 382
  • 3
  • 12

1 Answers1

3

Rtsne preserves the input order of the dataframe you pass to it.

Try:

Tsne_with_ID = cbind.data.frame(rfm[,1],tsne$y)

and then just fix the first column name:

colnames(Tsne_with_ID)[1] <- paste(colnames(rfm)[1])
Zander Fick
  • 106
  • 1
  • 9