如何解决使用 UMAP 和 HDBScan 进行聚类
我有大量的文本数据,大约有 5000 人输入。我使用 doc2vec 为每个人分配了一个向量,使用 UMAP 减少到二维,并使用 HDBSCAN 突出显示其中包含的组。目的是突出具有相似主题相似性的组。这导致了下面看到的散点图。
这看起来可以接受。但是,当我在 bokeh 中使用相同的数据(为了创建交互式图形)时,输出看起来非常不同。尽管使用了与之前相同的坐标和分组,但之前看到的清晰分组已经消失了。相反,图表一团糟,颜色混杂。
当应用过滤器来选择一个随机组时,点在整个情节中非常分布,并且无论如何都不像一个有凝聚力的“组”。例如,第 41 组在图的每个角附近都有点。
使用此代码将文档向量简化为 X、Y 坐标:
clusterable_embedding = umap.UMAP(
n_neighbors=150,min_dist=0,n_components=2,random_state=42,repulsion_strength=1.0,).fit_transform(model.dv.vectors)
并使用此代码分配组:
labels = hdbscan.HDBSCAN(
min_samples=1,min_cluster_size=10,).fit_predict(clusterable_embedding)
clustered = (labels >= 0)
from matplotlib.pyplot import figure
figure(figsize=(10,10),dpi=80)
plt.scatter(clusterable_embedding[~clustered,0],clusterable_embedding[~clustered,1],c=(0.5,0.5,0.5),s=10,alpha=0.5)
plt.scatter(clusterable_embedding[clustered,clusterable_embedding[clustered,c=(labels[clustered]),s=20,cmap='Spectral');
然后将其插入到 Pandas 数据帧中:
for item in list(clusterable_embedding[clustered]):
x = item[0]
y = item[1]
group = labels[int(len(all_data))]
topic = topiclist(group)
all_data.loc[len(all_data)] = [x,y,group,topic]
并创建了散景图:
datasource = ColumnDataSource(all_data)
yfig = figure(
plot_width=600,plot_height=600,tools=('pan,wheel_zoom,reset')
)
yfig.add_tools(HoverTool(tooltips="""
<div>
<div>
<span style='font-size: 16px; color: #224499'>Group: </span>
<span style='font-size: 18px'>@group</span>
</div>
<div>
<span style='font-size: 16px; color: #224499'>Topic: </span>
<span style='font-size: 18px'>@topic</span>
</div>
</div>
"""))
color_mapper = LinearColorMapper(palette='Magma256',low=min(groups),high=max(groups))
yfig.circle(
'x','y',source=datasource,color={'field': 'group','transform': color_mapper},line_alpha=0.6,fill_alpha=0.6,size=4
)
show(yfig)
我在这里做错了吗?或者这是技术或数据的限制?初始图中的彩色组是否真的按组分组,如果是,为什么散景图中的彩色组不是?
非常感谢任何帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。