0
import pandas as pd, numpy as np, scipy
import sklearn.feature_extraction.text as text
from sklearn import decomposition
descs = ["You should not go there", "We may go home later", "Why should we do your chores", "What should we do"]
vectorizer = text.CountVectorizer()
dtm = vectorizer.fit_transform(descs).toarray()
vocab = np.array(vectorizer.get_feature_names())
nmf = decomposition.NMF(3, random_state = 1)
topic = nmf.fit_transform(dtm)
印刷topic
给我留下了:Sklearn:找到簇的平均质心位置?
>>> print(topic)
[0. , 1.403 , 0. ],
[0. , 0. , 1.637 ],
[1.257 , 0. , 0. ],
[0.874 , 0.056 , 0.065 ]
这是在descs
的可能性每个元素的矢量属于某个簇。我怎样才能得到每个群集质心的坐标?最终,我想开发一个函数来计算descs
中每个元素与其分配给的簇的质心之间的距离。
是否最好只计算每个群集的每个元素值的平均值?topic
?
我假设你创建了三个质心。 “nmf.components_”中每个元素表示的每个质心的坐标如何?该数组中非零元素的数量似乎表示高维度。 – blacksite
nmf.components_'的尺寸是3行乘14列,它们对应于3个簇和14个不同的单词,即表示簇质心的向量是词汇基础的线性组合。 – Tonechas
那么我怎么能找到质心本身的x-y坐标?或者这是一个误导的问题? – blacksite