我使用DBSCAN方法對圖像進行聚類,但它會產生意想不到的結果。假設我有10張圖片。sklearn.cluster.DBSCAN給出了意想不到的結果
首先,我使用cv2.imread
在循環中讀取圖像。然後我計算每個圖像之間的結構相似性指數。之後,我有這樣一個矩陣:
[
[ 1. -0.00893619 0. 0. 0. 0.50148778 0.47921832 0. 0. 0. ]
[-0.00893619 1. 0. 0. 0. 0.00996088 -0.01873205 0. 0. 0. ]
[ 0. 0. 1. 0.57884212 0. 0. 0. 0. 0. 0. ]
[ 0. 0. 0.57884212 1. 0. 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]
[ 0.50148778 0.00996088 0. 0. 0. 1. 0.63224396 0. 0. 0. ]
[ 0.47921832 -0.01873205 0. 0. 0. 0.63224396 1. 0. 0. 0. ]
[ 0. 0. 0. 0. 0. 0. 0. 1. 0.77507487 0.69697053]
[ 0. 0. 0. 0. 0. 0. 0. 0.77507487 1. 0.74861881]
[ 0. 0. 0. 0. 0. 0. 0. 0.69697053 0.74861881 1. ]]
看起來不錯。然後,我有DBSCAN的簡單invokation:
db = DBSCAN(eps=0.4, min_samples=3, metric='precomputed').fit(distances)
labels = db.labels_
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
,其結果是
[0 0 0 0 0 0 0 0 0 0]
我該怎麼辦錯了嗎?爲什麼它將所有圖像放入一個集羣?