scikit-learn/scikit-learn — pull request #2959 by Oscarlsson (2014-03-11 14:28:12+00:00)
Title: Silhouette score crashed if wrong number of labels

Silhouette score is only defined if ```2 <= n_labels <= n_samples -1 ```
but before this fix silhouette_score crashed if ```n_labels <= 2``` with
```ValueError: zero-size array to reduction operation minimum which has no identity```
and returned 0 if ```n_labels == n_samples```

I thought raising a ValueError was the most appropriate solution, what do you think?
I added test to it, if necessary, and changed such that all tests depends on ```sklearn.testing```.

This fix makes it behave like silhouette {cluster} in R.
https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/silhouette.html

Example:
```
dataset = load_iris()
X = dataset.data
y = np.arange(X.shape[0]) # n_labels == n_samples
cluster.silhouette_score(X,y)
Out[39]: 0.0
```
```
dataset = load_iris()
X = dataset.data
y = np.zeros(X.shape[0]) # n_labels == 1
cluster.silhouette_score(X,y)

ValueError: zero-size array to reduction operation minimum which has no identity
```