DBSCAN Clustering - Exporting the clustered outcome to a new column issue

可紊 提交于 2021-02-05 09:23:11

问题


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.

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')

Anyone know how to do it with DBSCAN?


回答1:


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_


来源:https://stackoverflow.com/questions/65882879/dbscan-clustering-exporting-the-clustered-outcome-to-a-new-column-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!