小编Bru*_*ent的帖子

在sklearn FeatureAgglomeration中使用Pearson相关

我有一个具有100行和10,000个功能的熊猫数据框。我想通过使用pearson相关性作为sklearn.cluster.FeatureAgglomeration中的亲和力参数来对数据进行分层聚类。

到目前为止,我已经尝试了两种方法使其工作:第一种是:

feature_agglomator = FeatureAgglomeration(n_clusters=10, affinity=np.corrcoef, linkage='average')
Run Code Online (Sandbox Code Playgroud)

第二个:

from scipy.spatial.distance import correlation 
feature_agglomator = FeatureAgglomeration(n_clusters=10,affinity='correlation', linkage='average')
Run Code Online (Sandbox Code Playgroud)

运行后:

feature_agglomator.fit_transform(X)
Run Code Online (Sandbox Code Playgroud)

两者都以相同的例外结尾:

ValueError: The condensed distance matrix must contain only finite values.
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能使其正常工作?

python affinity scipy scikit-learn

5
推荐指数
0
解决办法
1079
查看次数

标签 统计

affinity ×1

python ×1

scikit-learn ×1

scipy ×1