Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9f236c

Browse files
adrinjalaliqinhanmin2014
authored andcommitted
DOC AffinityPropagation example added to its class's docstring (scikit-learn#11484)
1 parent 153aec4 commit a9f236c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

sklearn/cluster/affinity_propagation_.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,24 @@ class AffinityPropagation(BaseEstimator, ClusterMixin):
290290
n_iter_ : int
291291
Number of iterations taken to converge.
292292
293+
Examples
294+
--------
295+
>>> from sklearn.cluster import AffinityPropagation
296+
>>> import numpy as np
297+
>>> X = np.array([[1, 2], [1, 4], [1, 0],
298+
... [4, 2], [4, 4], [4, 0]])
299+
>>> clustering = AffinityPropagation().fit(X)
300+
>>> clustering # doctest: +NORMALIZE_WHITESPACE
301+
AffinityPropagation(affinity='euclidean', convergence_iter=15, copy=True,
302+
damping=0.5, max_iter=200, preference=None, verbose=False)
303+
>>> clustering.labels_
304+
array([0, 0, 0, 1, 1, 1])
305+
>>> clustering.predict([[0, 0], [4, 4]])
306+
array([0, 1])
307+
>>> clustering.cluster_centers_
308+
array([[1, 2],
309+
[4, 2]])
310+
293311
Notes
294312
-----
295313
For an example, see :ref:`examples/cluster/plot_affinity_propagation.py

0 commit comments

Comments
 (0)