Skip to content

Instantly share code, notes, and snippets.

@schochastics
Last active October 10, 2018 19:24
Show Gist options
  • Save schochastics/2f83532f04729321b06822fbaa98f3ab to your computer and use it in GitHub Desktop.
Save schochastics/2f83532f04729321b06822fbaa98f3ab to your computer and use it in GitHub Desktop.
Quick and dirty way of using UMAP in R using rPyhton
#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