This documentation is for scikit-learn version 0.11-gitOther versions


If you use the software, please consider citing scikit-learn.

This page

8.1.1. sklearn.cluster.AffinityPropagation

class sklearn.cluster.AffinityPropagation(damping=0.5, max_iter=200, convit=30, copy=True)

Perform Affinity Propagation Clustering of data

Parameters :

damping : float, optional

Damping factor

max_iter : int, optional

Maximum number of iterations

convit : int, optional

Number of iterations with no change in the number of estimated clusters that stops the convergence.

copy: boolean, optional :

Make a copy of input data. True by default.


See examples/ for an example.

The algorithmic complexity of affinity propagation is quadratic in the number of points.


Brendan J. Frey and Delbert Dueck, “Clustering by Passing Messages Between Data Points”, Science Feb. 2007


cluster_centers_indices_ array, [n_clusters] Indices of cluster centers
labels_ array, [n_samples] Labels of each point


fit(S[, p]) Compute affinity propagation clustering.
get_params([deep]) Get parameters for the estimator
set_params(**params) Set the parameters of the estimator.
__init__(damping=0.5, max_iter=200, convit=30, copy=True)
fit(S, p=None)

Compute affinity propagation clustering.

Parameters :

S: array [n_points, n_points] :

Matrix of similarities between points

p: array [n_points,] or float, optional :

Preferences for each point - points with larger values of preferences are more likely to be chosen as exemplars. The number of exemplars, ie of clusters, is influenced by the input preferences value. If the preferences are not passed as arguments, they will be set to the median of the input similarities.

damping : float, optional

Damping factor

copy: boolean, optional :

If copy is False, the affinity matrix is modified inplace by the algorithm, for memory efficiency


Get parameters for the estimator

Parameters :

deep: boolean, optional :

If True, will return the parameters for this estimator and contained subobjects that are estimators.


Set the parameters of the estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns :self :