Jaccard 類似性を使用します。以下の Python デモでは、類似性の「逆」である関数cosine
とリターン距離に注意して、コメントを読んでください。jaccard
# Input all the data
In [19]: from scipy.spatial.distance import cosine, jaccard
In [24]: a
Out[24]: array([ 1, 1, 15, 2, 0])
In [25]: b
Out[25]: array([ 0, 0, 15, 0, 0])
In [26]: c
Out[26]: array([ 1, 1, 11, 0, 1])
# Calculate cosine similarity. I've scaled it by a factor of 100 for legibility
In [20]: 100*cosine(a,b)
Out[20]: 1.3072457560346473
In [21]: 100*cosine(c,a)
Out[21]: 1.3267032349480568
# Note c is slightly "further away" from a than b.
# Now let's see what Mr Jaccard has to say
In [28]: jaccard(a,b)
Out[28]: 0.75
In [29]: jaccard(a,c)
Out[29]: 0.59999999999999998
# Behold the desired effect- c is now considerably closer to a than b
# Sanity check- the distance between a and a is 0
In [30]: jaccard(a,a)
Out[30]: 0.0
PSさらに多くの類似性尺度が存在し、それぞれが異なる状況下で適切です。がよりc
も に似ていると信じる正当な理由はありますか? あなたの仕事は何ですか?このテーマについてもっと読みたい場合は、この博士論文を強くお勧めします。警告: 200 ページの長さです。a
b