Last active
October 10, 2018 19:24
-
-
Save schochastics/2f83532f04729321b06822fbaa98f3ab to your computer and use it in GitHub Desktop.
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