我有4个集群,我需要在每个集群中找到一组最有影响力的特性,这样我就可以了解集群的特性,从而了解这些集群的行为。我该怎么做?
发布于 2018-10-31 10:58:49
解决这个问题的一个基本方法是为集群质心的特征找到描述性的统计数据。
寻找影响最大的变量的片段:
var_influence=cc.describe() #cc contains the cluster centroids
# The descriptive statistics of the cluster centroids are saved in a Dataframe var_influence.
# Sorting by standard deviation will give the variables with high standard deviation.
var_influence.sort_values(axis=1, by='std', ascending=False).iloc[:,:10] 这样,与方框绘图方法相比,更快更好地找到影响变量(这是很难用增加的功能来可视化的)。由于所有的变量都是标准化的,所以很容易比较不同的特性。
也可以使用max-min方法,这将允许我们看到具有最大带宽的变量。由于所有变量都已标准化,max-min是验证上述result.Code与下面相同的方法的好方法。
pd.Series(var_influence.loc['max']-var_influence.loc['min']).sort_values(ascending=False)[:10]多类分类
一个比较严重的发现影响特征的方法是多类分类:使用聚类标签作为目标变量对数据进行多类分类模型的训练。得到的模型系数可以用来确定特征的重要性。
发布于 2018-07-03 08:35:59
我使用的方法是训练一个分类器来预测每个聚类标签(如果是对应的簇,则为0),然后使用模型属性来确定每个聚类中最有区别的变量。我一直在使用RandomForest和镰刀中的属性feature_importances_进行学习,并且一直取得很好的结果。
然后,我使用盒图/密度图来表示每个集群中这些变量的分布情况。
您还可以使用更传统的方法,例如通过聚类比较每个变量的均值,并使用统计测试(如ANOVA )来获得更可靠的结果。
编辑:下面是Python中的一个示例:
for cl in data.cluster.unique():
custom_target = data.cluster.copy()
custom_target.loc[custom_target != cl] = -1
custom_target.loc[custom_target == cl] = 1
clf = RandomForestClassifier(100 , random_state = 10)
clf.fit(data.values[: , 1:-4], custom_target)
imps , features = zip(*sorted(zip(clf.feature_importances_, cols) , reverse = True))
# store the results as you likehttps://stackoverflow.com/questions/51148457
复制相似问题