特征凝聚变换的结果

2024-06-11 20:43:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的变换函数从特征凝聚对象从scikit学习矩阵上的数据。运行转换函数后,在得到的矩阵(代码中的X_减少)上,第一个元素是簇0聚集的结果,第二个元素是簇1聚集的结果,依此类推?还是随机的

from sklearn import Cluster
agglo = cluster.FeatureAgglomeration(n_clusters=100)
agglo.fit(X_train_prepared)
X_reduced = agglo.transform(X_train_prepared)

Tags: 数据对象函数代码fromimport元素train
1条回答
网友
1楼 · 发布于 2024-06-11 20:43:29

相对于从agglo.labels_得到的标记是的,得到的矩阵的第一列是簇零

即以下情况:

from sklearn import cluster
from sklearn.datasets import load_iris, make_blobs
import pandas as pd
agglo = cluster.FeatureAgglomeration(n_clusters=95)
X,y = make_blobs(n_features=100)
agglo.fit(X)
X_reduced = agglo.transform(X)
# first column in reduced is the mean of all columns that lie in the first cluster
>>> all(X_reduced[:,0] == X[:,(agglo.labels_ == 0).nonzero()[0]].mean(axis=1))
True

相关问题 更多 >