title: Adjusted Cosine Similarity in Python
body: <p>Referring to this <a href="https://stackoverflow.com/questions/42866174/cosine-similarity">link</a></p>
  
  <p>which calculates adjusted cosine similarity matrix (given the ratings matrix M having m users and n items) as below:</p>
  
  <pre><code>M_u = M.mean(axis=1)    
  item_mean_subtracted = M - M_u[:, None]    
  similarity_matrix = 1 - squareform(pdist(item_mean_subtracted.T, 'cosine'))
  </code></pre>
  
  <p>I cannot see how the <strong>'both rated'</strong> condition is met as per this <a href="http://www10.org/cdrom/papers/519/node14.html" rel="nofollow noreferrer">definition</a></p>
  
  <p>I have manually calculated the adjusted cosine similarities and they seem to differ with the values I get from above code.</p>
  
  <p>Could anyone please clarify this?</p>