<p dir="auto">The documentation for the <code class="notranslate">metric</code> parameter for <code class="notranslate">silhouette_score()</code> reads:</p>
<blockquote>
<p dir="auto">If metric is a string, it must be one of the options allowed by metrics.pairwise.pairwise_distances. If X is the distance array itself, use metric="precomputed".</p>
</blockquote>
<p dir="auto">However, entering <code class="notranslate">metric='l1'</code> or <code class="notranslate">metric='cosine'</code> both lead to an error:</p>
<blockquote>
<p dir="auto">File "search_cluster_02.py", line 148, in <br>
% metrics.silhouette_score(X, labels, sample_size=1000,metric="l1"))<br>
File "C:\Anaconda\lib\site-packages\sklearn\metrics\cluster\unsupervised.py", line 84, in silhouette_score<br>
return np.mean(silhouette_samples(X, labels, metric=metric, *_kwds))<br>
File "C:\Anaconda\lib\site-packages\sklearn\metrics\cluster\unsupervised.py", line 143, in silhouette_samples<br>
distances = pairwise_distances(X, metric=metric, *_kwds)<br>
File "C:\Anaconda\lib\site-packages\sklearn\metrics\pairwise.py", line 657, in pairwise_distances<br>
return func(X, Y, **kwds)<br>
File "C:\Anaconda\lib\site-packages\sklearn\metrics\pairwise.py", line 244, in manhattan_distances<br>
raise ValueError("manhattan_distance does not support sparse"</p>
</blockquote>
<p dir="auto">However, the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.pairwise_distances.html#sklearn.metrics.pairwise.pairwise_distances" rel="nofollow">documentation</a> for <code class="notranslate">metrics.pairwise.pairwise_distances</code> indicates that sparse matrices are allowed:</p>
<blockquote>
<p dir="auto">Please note that support for sparse matrices is currently limited to those metrics listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.</p>
</blockquote>
<p dir="auto">Looking there, on Github, we have:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PAIRWISE_DISTANCE_FUNCTIONS = {
    # If updating this dictionary, update the doc in both distance_metrics()
    # and also in pairwise_distances()!
    'cityblock': manhattan_distances,
    'cosine': cosine_distances,
    'euclidean': euclidean_distances,
    'l2': euclidean_distances,
    'l1': manhattan_distances,
    'manhattan': manhattan_distances, }"><pre class="notranslate"><code class="notranslate">PAIRWISE_DISTANCE_FUNCTIONS = {
    # If updating this dictionary, update the doc in both distance_metrics()
    # and also in pairwise_distances()!
    'cityblock': manhattan_distances,
    'cosine': cosine_distances,
    'euclidean': euclidean_distances,
    'l2': euclidean_distances,
    'l1': manhattan_distances,
    'manhattan': manhattan_distances, }
</code></pre></div>
<p dir="auto">Honestly, I can't tell if this is a documentation problem (or clarity issue) or a code problem.</p>
<p dir="auto">To reproduce this, just run the example script from this page:<br>
<a href="http://scikit-learn.org/stable/auto_examples/document_clustering.html" rel="nofollow">http://scikit-learn.org/stable/auto_examples/document_clustering.html</a></p>
<p dir="auto">and at the very bottom of the script, add the <code class="notranslate">metric='l1'</code> parameter to the call to <code class="notranslate">silhouette_score</code>.</p>
<p dir="auto">A simple case can be found here when manhattan_distances take two sparse matrices as input<br>
<a href="https://gist.github.com/4117966">https://gist.github.com/4117966</a><br>
The function fails without complaining.</p>
<p dir="auto">Seems <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jakevdp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jakevdp">@jakevdp</a> <a href="https://github.com/jakevdp/pyDistances/">https://github.com/jakevdp/pyDistances/</a> has many very efficient routines for computing pairwise-distances for sparse matrices, any plan for adopting some of them to sklearn?</p>