问题
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