微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python 使 UMAP 更快呃

如何解决Python 使 UMAP 更快呃

我正在使用 UMAP (https://umap-learn.readthedocs.io/en/latest/#) 来减少数据中的维度。我的数据集包含 4700 个样本,每个样本有 120 万个特征(我想减少)。然而,尽管使用了 32 个 cpu 和 120GB RAM,但这需要相当长的时间。尤其是embedding的构建速度很慢,而且verbose输出在最近3.5小时内没有变化:

UMAP(dens_frac=0.0,dens_lambda=0.0,low_memory=False,n_neighbors=10,verbose=True)
Construct fuzzy simplicial set
Mon Jul  5 09:43:28 2021 Finding Nearest Neighbors
Mon Jul  5 09:43:28 2021 Building RP forest with 59 trees
Mon Jul  5 10:06:10 2021 metric NN descent for 20 iterations
     1  /  20
     2  /  20
     3  /  20
     4  /  20
     5  /  20
    Stopping threshold met -- exiting after 5 iterations
Mon Jul  5 10:12:14 2021 Finished Nearest Neighbor Search
Mon Jul  5 10:12:25 2021 Construct embedding

有什么方法可以加快这个过程。我已经在使用这里描述的稀疏矩阵 (scipy.sparse.lil_matrix):https://umap-learn.readthedocs.io/en/latest/sparse.html。此外,我还安装了 pynndescent(如此处所述:https://github.com/lmcinnes/umap/issues/416)。我的代码如下:

from scipy.sparse import lil_matrix
import numpy as np
import umap.umap_ as umap

term_dok_matrix = np.load('term_dok_matrix.npy')
term_dok_mat_lil = lil_matrix(term_dok_matrix,dtype=np.float32)

test = umap.UMAP(a=None,angular_rp_forest=False,b=None,force_approximation_algorithm=False,init='spectral',learning_rate=1.0,local_connectivity=1.0,metric='euclidean',metric_kwds=None,min_dist=0.1,n_components=2,n_epochs=None,negative_sample_rate=5,output_metric='euclidean',output_metric_kwds=None,random_state=None,repulsion_strength=1.0,set_op_mix_ratio=1.0,spread=1.0,target_metric='categorical',target_metric_kwds=None,target_n_neighbors=-1,target_weight=0.5,transform_queue_size=4.0,unique=False,verbose=True).fit_transform(term_dok_mat_lil)

是否有任何技巧或想法可以使计算速度更快?我可以更改一些参数吗?我的矩阵仅由零和一组成是否有帮助(意味着我的矩阵中的所有非零条目都是一)。

解决方法

拥有 1.2 百万 个特征和仅 4700 个样本,您最好预先计算完整距离矩阵并将其与 metric="precomputed" 传递。目前,它正在花费大量工作来计算这 120 万个长向量的最近邻。只是蛮力会好很多。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。