以下是使用 IRIS 数据的 t-SNE 代码:
library(Rtsne)
iris_unique <- unique(iris) # Remove duplicates
iris_matrix <- as.matrix(iris_unique[,1:4])
set.seed(42) # Set a seed if you want reproducible results
tsne_out <- Rtsne(iris_matrix) # Run TSNE
# Show the objects in the 2D tsne representation
plot(tsne_out$Y,col=iris_unique$Species)
这产生了这个情节:
我如何使用 GGPLOT 来绘制该图?
我认为最简单/最干净ggplot
方法是将您需要的所有信息存储在data.frame
然后绘制它。从上面粘贴的代码来看,这应该有效:
library(ggplot2)
tsne_plot <- data.frame(x = tsne_out$Y[,1], y = tsne_out$Y[,2], col = iris_unique$Species)
ggplot(tsne_plot) + geom_point(aes(x=x, y=y, color=col))
我的情节使用常规plot
函数是:
plot(tsne_out$Y,col=iris_unique$Species)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)