title: Using the class sklearn.cluster.SpectralClustering with parameter affinity='precomputed'
body: <p>I'm having trouble understanding a specific use case of the <code>sklearn.cluster.SpectralClustering</code> class as outlined in the official documentation <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cluster.SpectralClustering.html#sklearn.cluster.SpectralClustering" rel="noreferrer">here</a>. Say I want to use my own affinity matrix to perform clustering. I first instantiate an object of class <code>SpectralClustering</code> as follows:
   </p>
  
  <pre><code>from sklearn.clustering import SpectralClustering
  
  cl = SpectralClustering(n_clusters=5,affinity='precomputed')
  </code></pre>
  
  <p>The documentation for the <code>affinity</code> parameter above is as follows:</p>
  
  <blockquote>
    <p>affinity : string, array-like or callable, default ‘rbf’</p>
    
    <p>If a string, this may be one of ‘nearest_neighbors’, ‘precomputed’, ‘rbf’ or one of the kernels supported by sklearn.metrics.pairwise_kernels.
    Only kernels that produce similarity scores (non-negative values that increase with similarity) should be used. This property is not checked by the clustering algorithm.</p>
  </blockquote>
  
  <p>Now the object <code>cl</code> has a method <code>fit</code> for which the documentation about its sole parameter <code>X</code> is as follows:</p>
  
  <blockquote>
    <p>X : array-like or sparse matrix, shape (n_samples, n_features)</p>
    
    <p>OR, if affinity==<code>precomputed</code>, a precomputed affinity matrix of shape (n_samples, n_samples)</p>
  </blockquote>
  
  <p>This is where it gets confusing. I am using my own affinity matrix, where a measure of 0 means two points are identical, with a higher number meaning two points are more dissimilar. However, the other choices for the parameter <code>affinity</code> actually take a data set and produce a <em>similarity</em> matrix, for which <em>higher</em> values are indicative of more similarity, and <em>lower</em> values indicate dissimilarity (such as the radial basis kernel).</p>
  
  <p>So when using the <code>fit</code> method on my instance of <code>SpectralClustering</code>, do I actually need to transform my affinity matrix into a similarity matrix before passing it to the <code>fit</code> method call as the parameter <code>X</code>? The same documentation page makes a note on transforming distance to well-behaved similarities, but does not explicitly indicate where this step should should be carried out, and via which method call. </p>