我在 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 聚类
发布评论