I have a dataset with last name, first name, middle name of people participating in sporting events. I need to train a neural network that will match similar surnames, first names and patronymics. But for this I still need to generate a threshold value. Could you please tell me how I can do this, taking into account that I am more interested in accuracy than in speed?

  • 1
    $\begingroup$ $1)$ Why do you need a threshold value? $2)$ Why is this a neural network problem? What are your features and the output you want to predict? $\endgroup$
    – Dave
    Commented May 8 at 13:46

2 Answers 2


There are two steps and I am in line with other answers and comments that you should reconsider step 1:

1. Find a distance / similarity measure

If you want to identify similar names, you need to quantify how similar these names are. Especially when dealing with names, there are better algorithms than neural networks for this.

So called string editing distances (Levenshtein is the most prominent one, but there are others) measure the distance in the number/costs of editing operations that are required to transform one string into another, e.g.

  • Levensthein considers adding, removing and replacing characters as operation
  • Damerau–Levenshtein adds swapping two characters
2. Choosing a threshold or policy to select matching data.

There are two different cases:

2.1 There is labeled ground truth

If you already have a dataset / subset where you know which instances should be matched, you can used this to compute precision and recall for different thresholds.

By systematically changing the threshold, you will get a precision-recall-curve. This allows you to choose the desired point on this curve where precision and recall are both sufficiently high (for your case). This point will be associated with the threshold you are looking for.

2.2 What if such labeled data does not exists?

Now things become tricky. You don't know if two instances should be matched. You could consider the whole problem as a clustering problem and create for different thresholds a clustering. Measures like Silhouette, Davies–Bouldin index or Dunn index will give you an indication which threshold creates the best clustering.
Note: Carefully check the results. Clustering often aims for fewer clusters. The indices could lead to undesired results.

You can even use a clustering based on the distances (some clustering algorithm only need pairwise distances between samples) which would go beyond simple thresholding.


I'm not sure if you need a neural network for your problem. A classical tool for this is Levenshtein distance. It will allow you to calculate the similarity between surnames. As it's a distance, you inherently have to set some similarity threshold, but the results will be better interpretable than they would be from a neural network.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.