例えば、
階層的手法でクラスタリングを行って、好ましい結果が得られている。
しかし、処理時間の点で課題があるので、K-Meansによるクラスタリングに置き換えたい。
といった時に、
K-Meansの結果が、階層的手法の結果とどれだけ近しいかを測りたい時があります。

クラスタリングの場合は、正解ラベルが一致するとは限らない
(ラベルが異なっていても、クラスタの別れ方が同じであれば結果は等しい)ので。
分類の精度を測る時のように、
単純に一方を正解として適合率(precision)や再現率(reacall)を求めることは出来ません。

そこで、どのような指標で測ることが出来るかを探していると、
次の項で示すQ&Aと参考論文を見つけたので、これを参考に指標を考えてみます。

参考とした資料

以下のQ&Aと参考論文を元に、指標を考えてみます。

Precision and recall for clustering? | StackExchange
https://stats.stackexchange.com/questions/15158/precision-and-recall-for-clustering/80194

Model-based Overlapping Clustering
http://www.ideal.ece.utexas.edu/papers/banerjee05overlapping.pdf

参考とした箇所は、以下の通り。

To evaluate the clustering results, precision, recall, and F-measure were calculated over pairs of points. For each pair of points that share at least one cluster in the overlapping clustering results, these measures try to estimate whether the prediction of this pair as being in the same cluster was correct with respect to the underlying true categories in the data. Precision is calculated as the fraction of pairs correctly put in the same cluster, recall is the fraction of actual pairs that were identified, and F-measure is the harmonic mean of precision and recall.

上記の説明は、ソフトクラスタリングですが、
このエントリではハードクラスタリングの場合を考えます。

指標を求める手続き

基本的に参考資料の通りですが、図に示しながら順に手続きを説明します。

例として、以下の2つのクラスタリング結果を考えます。

クラスタリング結果の比較

クラスタリング結果①について、
各要素のペアを作り、それぞれが同じクラスタに属するか否かを調べます。

要素同士が同じクラスタに属するかを調べる1

クラスタリング結果②についても同様。

要素同士が同じクラスタに属するかを調べる2

結果①と結果②を、prediction/actualとして扱い、
precisionとreacallを求めます。
precisionとrecallの調和平均をとってF値を求め、
これを、クラスタリング結果がどのくらい似ているかの指標として扱います。

要素同士が同一クラスタに属するかの比較

# 結果①と結果②のどちらを、actualとして扱うかによって、
# precisionとreacallの値は変わりますが、値が入れ替わるだけです。
# F値は、precisionとrecallの調和平均なので、同じ値になります。