[英]How to plot dbscan graph
我一直在嘗試 plot 一個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)
任何建議或替代方案都會有所幫助!
根據幫助文件,標簽位於model.labels_
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.