Skip to content

Commit

Permalink
DOC add example in docstring of silhouette_score (scikit-learn#28125)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Lemaitre <[email protected]>
  • Loading branch information
Harmanankohli and glemaitre committed Jan 16, 2024
1 parent db971d1 commit dcf6c27
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sklearn/metrics/cluster/_unsupervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def silhouette_score(
.. [2] `Wikipedia entry on the Silhouette Coefficient
<https://en.wikipedia.org/wiki/Silhouette_(clustering)>`_
Examples
--------
>>> from sklearn.datasets import make_blobs
>>> from sklearn.cluster import KMeans
>>> from sklearn.metrics import silhouette_score
>>> X, y = make_blobs(random_state=42)
>>> kmeans = KMeans(n_clusters=2, random_state=42)
>>> silhouette_score(X, kmeans.fit_predict(X))
0.49...
"""
if sample_size is not None:
X, labels = check_X_y(X, labels, accept_sparse=["csc", "csr"])
Expand Down

0 comments on commit dcf6c27

Please sign in to comment.