简体   繁体   中英

sklearn.cluster.DBSCAN gives unexpected result

I'm using DBSCAN method for clustering images, but it gives unexpected result. Let's assume I have 10 images.

Firstly, I read an images in a loop using cv2.imread . Then I compute structural similarity index between each images. After that, I have a matrix like this:

[
[ 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.        ]]

Looks good. Then I have simple invokation of DBSCAN:

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)

And the result is

[0 0 0 0 0 0 0 0 0 0]

What do I do wrong? Why it puts all images into one cluster?

DBSCAN usually assumes a dissimilarity (distance) not a similarity. It can be implemented with a similarity threshold, too (see Generalized DBSCAN)

问题是我错误地计算了距离矩阵-主对角线上的条目全为零。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM