String Distance Matrix in Python -
how calculate levenshtein distance matrix of strings in python
str1 str2 str3 str4 ... strn str1 0.8 0.4 0.6 0.1 ... 0.2 str2 0.4 0.7 0.5 0.1 ... 0.1 str3 0.6 0.5 0.6 0.1 ... 0.1 str4 0.1 0.1 0.1 0.5 ... 0.6 . . . . . ... . . . . . . ... . . . . . . ... . strn 0.2 0.1 0.1 0.6 ... 0.7
using ditance function can calculate distance betwwen 2 words. here have 1 list containing n number of strings. wanted calculate distance matrix after want clustering of words.
just use pdist
version accepts custom metric.
y = pdist(x, levensthein)
and levensthein
can use implementation of rosettacode suggested tanu
if want full squared matrix use squareform
on result:
y = np.squareform(y)
Comments
Post a Comment