title: Sklearn cosine similarity for strings, Python
body: <p>I am writing an algorithm that checks how much a string is equal to another string. I am using Sklearn cosine similarity.</p>
  
  <p>My code is:</p>
  
  <pre><code>from sklearn.feature_extraction.text import TfidfVectorizer
  from sklearn.metrics.pairwise import cosine_similarity
  
  example_1 = ("I am okey", "I am okeu")
  example_2 = ("I am okey", "I am crazy")
  
  tfidf_vectorizer = TfidfVectorizer()
  tfidf_matrix = tfidf_vectorizer.fit_transform(example_1)
  result_cos = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix)
  print(result_cos[0][1])
  </code></pre>
  
  <p>Running this code for example_1, prints 0.336096927276. Running it for example_2, it prints the same score. The result is the same in both cases because there is only one different word.</p>
  
  <p>What I want is to get a higher score for example_1 because the different words "okey vs okeu" have only one different letter. In contrast in example_2 there are two completely different words "okey vs crazy".</p>
  
  <p>How can my code take in consideration that in some cases the different words are not completely different?</p>