【问题标题】:What does mean affinity='precomputed' in Feature Agglomeration dimensionality reduction?特征聚集降维中的亲和力=“预计算”是什么意思?
【发布时间】:2019-03-03 11:04:19
【问题描述】:

affinity='precomputed' 在特征聚合降维(scikit-learn)中是什么意思,它是如何使用的? 我得到的结果比使用其他相似性选项(例如“euclidean”、“l1”、“l2”或“manhattan”)要好得多,但是,我不确定这个“预先计算”的实际含义以及我是否必须为特征聚集算法提供“预先计算”的东西? “预先计算”到底是什么意思?

除了预处理(缩放)的原始数据、numpy 数组之外,我没有传递任何东西。在 fit_transform 与特征聚集之后,结果被传递给 Birch 聚类算法,我得到了比提到的其他亲和性更好的结果。结果与 PCA 相当,但内存消耗开销要低得多,所以我会使用特征聚集作为降维,但我担心我做错了吗?

【问题讨论】:

标签: scikit-learn feature-extraction feature-selection dimensionality-reduction


【解决方案1】:

好问题。

affinity == 'precomputed'表示使用包含原始数据distance matrix的上三角的flatten数组。

参考(source code):

    if affinity == 'precomputed':
        # for the linkage function of hierarchy to work on precomputed
        # data, provide as first argument an ndarray of the shape returned
        # by pdist: it is a flat array containing the upper triangular of
        # the distance matrix.
        i, j = np.triu_indices(X.shape[0], k=1)
        X = X[i, j]
    elif affinity == 'l2':
        # Translate to something understood by scipy
        affinity = 'euclidean'
    elif affinity in ('l1', 'manhattan'):
        affinity = 'cityblock'

【讨论】:

猜你喜欢
  • 2013-11-04
  • 2012-08-11
  • 2016-03-16
  • 1970-01-01
  • 2011-07-12
  • 1970-01-01
  • 2022-01-16
  • 2019-02-28
  • 1970-01-01
相关资源
最近更新 更多