title: Use a similarity function for clustering scikit-learn
body: <p>I use a function to calculate similarity between a pair of documents and wanto perform clustering using this similarity measure.<br>
  Code so Far      </p>
  
  <pre><code>Sim=np.zeros((n, n)) # create a numpy arrary  
  i=0  
  j=0       
  for i in range(0,n):      
     for j in range(i,n):  
      if i==j:  
          Sim[i][j]=1
       else:    
           Sim[i][j]=simfunction(list_doc[i],list_doc[j]) # calculate similarity between documents i and j using simfunction
  Sim=Sim+ Sim.T - np.diag(Sim.diagonal()) # complete the symmetric matrix
  
  AggClusterDistObj=AgglomerativeClustering(n_clusters=num_cluster,linkage='average',affinity="precomputed") 
  Res_Labels=AggClusterDistObj.fit_predict(Sim)
  </code></pre>
  
  <p>My concern is that here I used a similarity function , and I think as per documents it should be a disimilarity matrix, how can I change it to dissimilarity matrix. 
  Also what would be a more efficient way to do this.</p>