如何使用 Rtsne 包保留用户 ID

How to keep User ID using Rtsne package

我想使用 T-SNE 可视化用户的变量,但我希望能够将数据加入到用户的社交信息中。

不幸的是,Rtsne 的输出似乎没有 return 具有用户 ID 的数据..

数据如下所示:

  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

和 Rtsne 输出:

           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

和代码:

tsne = Rtsne(rfm[, -1], dims=2, check_duplicates=F)

Rtsne 保留您传递给它的数据帧的输入顺序。

尝试:

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

然后只需修复第一列名称:

colnames(Tsne_with_ID)[1] <- paste(colnames(rfm)[1])