PolyFuzz icon indicating copy to clipboard operation
PolyFuzz copied to clipboard

Weirdly High scores (False Positives)

Open Pranav082001 opened this issue 1 year ago • 1 comments

I have been experimenting with PolyFuzz for a while. I have observed some weird scoring behavouir. Following is the case in which I am getting a very high score of 90 despite the string hardly equal. It is not expected to get such high scores just because of common string "america", the edit distance would be very low if you compare it with list1 strings.

list1= ["american Futures and Options Exchange","America First Credit Union"]
list2=["america"]
model = PolyFuzz("EditDistance").match(list1, list2)
data=model.get_matches()
print(data)
                                    From       To  Similarity
0  american Futures and Options Exchange  america         0.9
1             America First Credit Union  america         0.9

Any workaround would be appreciated... Thanks!

Pranav082001 avatar Aug 02 '22 07:08 Pranav082001

The edit distance that is being used as a default is RapidFuzz, more specifically, it uses the WRatio method for calculating the edit distance. The output is expected according to the scoring function that is being used. You can check it with the following:

>>> from rapidfuzz import process, fuzz
>>> match = process.extractOne(list2[0], list1, scorer=fuzz.WRatio)
>>> match
('american Futures and Options Exchange', 90.0, 0)

If you want to use a different edit distance technique, you can do something like this instead:

from polyfuzz import PolyFuzz
from polyfuzz.models import EditDistance
from rapidfuzz.distance import Levenshtein

list1 = ["american Futures and Options Exchange","America First Credit Union"]
list2 = ["America"]

distance = EditDistance(scorer=Levenshtein.distance, normalize=False)
model = PolyFuzz(distance).match(list1, list2)

MaartenGr avatar Aug 02 '22 07:08 MaartenGr