【问题标题】:How to plot dbscan graph如何绘制 dbscan 图
【发布时间】:2020-11-26 09:15:21
【问题描述】:

我一直在尝试绘制DBSCAN 聚类图,但遇到了错误:

AttributeError: 'DBSCAN' object has no attribute 'labels'

代码:

from sklearn.cluster import DBSCAN
    
model = DBSCAN(eps=3)
X = dataset.data
model.fit(X)
df=pd.DataFrame(iris['data'])
df.head()
    print(model)
%matplotlib inline
# Visualize the results
import matplotlib.pyplot as plt
X = dataset.data
y_kmeans = model.fit_predict(X) # this give the cluster number of the nearest centroid

# scatter plot the petal length (column 2), petal width (column 3)
plt.scatter(X[:, 2], X[:, 3], c=y_kmeans, s=50, cmap='viridis')
# show centroid centres as grey circle opacity 50%
centers = model.labels
plt.scatter(centers[:, 2], centers[:, 3], c='black', s=200, alpha=0.5)

任何建议或替代方案都会有所帮助!

【问题讨论】:

    标签: python unsupervised-learning dbscan


    【解决方案1】:

    根据help 文件,标签位于model.labels_

    【讨论】:

      猜你喜欢
      • 2015-07-20
      • 2014-09-18
      • 2023-03-23
      • 2020-07-29
      • 2011-10-13
      • 2019-08-14
      • 2017-08-27
      • 2017-09-22
      • 2020-10-28
      相关资源
      最近更新 更多