Quick and dirty way of using UMAP in R using rPyhton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#install UMAP from https://github.com/lmcinnes/umap | |
#install.packages("rPython") | |
umap <- function(x,n_neighbors=10,n_components=2,min_dist=0.1,metric="euclidean"){ | |
x <- as.matrix(x) | |
colnames(x) <- NULL | |
rPython::python.exec( c( "def umap(data,n,d,mdist,metric):", | |
"\timport umap" , | |
"\timport numpy", | |
"\tembedding = umap.UMAP(n_neighbors=n,n_components=d,min_dist=mdist,metric=metric).fit_transform(data)", | |
"\tres = embedding.tolist()", | |
"\treturn res")) | |
res <- rPython::python.call( "umap", x,n_neighbors,n_components,min_dist,metric) | |
do.call("rbind",res) | |
} | |
data(iris) | |
res <- umap(iris[,1:4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment