0

# Jaro Distance

Unsolved
###### NLP

Difficulty: 3 | Problem written by mesakarghm
##### Problem reported in interviews at

Jaro Distance is a measure of similarity between two strings.The Jaro Similarity is calculated using the formula:

\begin{aligned} Sim_J (s_1, s_2) = \begin{cases} 0 &\text{if } m = 0, \\ \frac{1}{3}\left( \frac{m}{|s_1|} + \frac{m}{|s_2|} + \frac{m - t}{m} \right) &\text{otherwise}. \end{cases} \end{aligned}

m is the number of matching characters
t is half the number of transpositions
|s1| and |s2| is the length of string s1 and s2 respectively.

The value of Jaro Distance should always be between 0 and 1. A distance value of 0 means the strings are not similar at all and a distance value of 1 means that the strings are really similar.

Write a function jaro_distance(s1,s2) which calculates the Jaro distance between the given two strings.

##### Sample Input:
<class 'str'>
s1: arow
<class 'str'>
s2: arrow

##### Expected Output:
<class 'float'>
0.9333333333333332

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Have an issue, the MLPro support team is available 24X7 to Premium users.