【问题标题】:Using map function from purrr to test 2 parameters on one UMAP function in R使用 purrr 中的 map 函数在 R 中的一个 UMAP 函数上测试 2 个参数
【发布时间】:2020-10-08 18:37:56
【问题描述】:

新手再次需要帮助。我正在使用 UMAP(一种降维工具)处理数据集。像这样的东西将有 2 个参数需要调整和查看。以前我用过 tSNE,它需要一个参数调整。对于 tSNE,该参数称为 perplexity。为了尝试一些困惑值并将结果可视化,我认为 purrr 中的 map 函数可以很好地自动执行此操作。

#for this purpose the sample data can be anything
#only that my dataset has lots labels
df <- data.frame(replicate(110,sample(-10:10,1000,rep=TRUE)))
df.label <- df[,1:20]
df.data <- df[,21:110]

library(tsne)
library(purrr)
#set the test values for perplexity a vector
#map along a vector

perplex=c(10,20,50,100)
map(perplex,tsne(df.data,perplexity = perplex))

tensor() 的结果将为每一行(样本)生成一个 x/y 坐标,然后我可以绘制它们。 虽然,在这里教我如何自动绘制所有 4 个测试结果的小帮助会很棒,否则我必须使用 plot 4 次,每次使用 x=tsne[,1] 和 y=tsne[,2]。

现在,对于我要测试的 umap。我想以相同的方式测试 2 个参数 n_neighbors 和 min_dist 。复杂性在于我为 n_neighbors 选择的每个值,我想测试所有 min_dist 测试值。例如,如果: n_neighbors= 10,50,20 min_dist= 0.1, 0.5, 1, 10 我想针对 n_neighbors=10 对我的数据运行 umap 函数,并迭代 min_dist=0.1、0.5、1、10。并对其余的 n_neighbors 值重复此操作。

然后我被 purrr 中的地图功能卡住了。我想我只能在函数中传递 1 个向量。

#map along a vector
n_neighbors.test= c(10,50,20)
min_dist.test= c(0.1, 0.5, 1, 10)

map(?,umap(df.data,n_neighbors = n_neighbors.test, min_dist=min_dist.test ))

还有绘图问题。 UMAP 还给出了一个列表,一个矩阵是包含行的 x/y 坐标的布局。

【问题讨论】:

    标签: r dictionary purrr runumap


    【解决方案1】:

    试试:

    expand.grid(n_neighbors.test,n_neighbors) %>% transpose() %>% map(~{umap(df.data,n_neighbors = .x[[1]], min_dist=.x[[2]] )})
    

    或者,您可以使用叠瓦状地图:

    unlist(map(n_neighbors.test,function(x){
      map(min_dist.test,function(y){umap(df.data,x,y)})
    }))
    

    【讨论】:

    • 感谢您的代码。这个 expand.grid 函数看起来很有前途。让我试试。不幸的是,数据正在杀死我的电脑。让我对一些子集进行测试:)
    • 笛卡尔积对于大型数据集很危险!
    • 查看我的编辑以获取内存密集度较低的替代方案
    • 这会很甜蜜
    • 总结时出错:'arg' 必须为 NULL 或字符向量。
    猜你喜欢
    • 1970-01-01
    • 2017-07-19
    • 2022-01-23
    • 1970-01-01
    • 2021-06-09
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    相关资源
    最近更新 更多