DBSCAN 聚类 - 将聚类结果导出到新列问题 [英] DBSCAN Clustering - Exporting the clustered outcome to a new column issue

查看:80
本文介绍了DBSCAN 聚类 - 将聚类结果导出到新列问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Iris 数据集下使用 python 编写了一个代码 - 我使用的聚类技术是 DBSCAN.我需要将所需的结果取出到一个新列中.我有聚类的图形图表.需要取出更新后的新簇列的总数据集.

I have made a code using python under Iris Data set - the clustering technique i used is DBSCAN. I need to take out the desired outcome in to a new column. I have the graphical chart of the clustering. Needed to take out the total data set with updated new cluster column.

在 K-Means 中,我可以通过运行以下命令来做到这一点

In K-Means, I could do that by running the below

iris_frame['NEW_COLUMN'] = pd.Series(y, index=iris_frame.index)

在分层聚类中,我可以从下面的公式中取出所需的结果

In Hierarchical clustering i could take out the desired outcome from the below formula

from scipy.cluster.hierarchy import fcluster
iris_CM=iris.copy()
iris_CM['Hierarchical']=fcluster(dist_comp,3, criterion='maxclust')

有人知道如何使用 DBSCAN 吗?

Anyone know how to do it with DBSCAN?

推荐答案

您可以通过 labels_ 属性访问集群标签.根据文档

You can access the cluster labels by the labels_ attribute. According to the documentation

from sklearn.cluster import DBSCAN
import numpy as np
import pandas as pd

X = np.array([[1, 2], [2, 2], [2, 3],
              [8, 7], [8, 8], [25, 80]])
df = pd.DataFrame(X)
clustering = DBSCAN(eps=3, min_samples=2).fit(df)
df["clusters"] = clustering.labels_

这篇关于DBSCAN 聚类 - 将聚类结果导出到新列问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆