8000 Add random_state parameter to AffinityPropagation by rcwoolston · Pull Request #14337 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Add random_state parameter to AffinityPropagation #14337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
10 changes: 7 additions & 3 deletions sklearn/cluster/affinity_propagation_.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ..exceptions import ConvergenceWarning
from ..base import BaseEstimator, ClusterMixin
from ..utils import as_float_array, check_array
from ..utils import as_float_array, check_array, check_random_state
from ..utils.validation import check_is_fitted
from ..metrics import euclidean_distances
from ..metrics import pairwise_distances_argmin
Expand All @@ -32,7 +32,7 @@ def all_equal_similarities():

def affinity_propagation(S, preference=None, convergence_iter=15, max_iter=200,
damping=0.5, copy=True, verbose=False,
return_n_iter=False):
return_n_iter=False, random_state=0):
"""Perform Affinity Propagation Clustering of data

Read more in the :ref:`User Guide <affinity_propagation>`.
Expand Down Expand Up @@ -72,6 +72,10 @@ def affinity_propagation(S, preference=None, convergence_iter=15, max_iter=200,
return_n_iter : bool, default False
Whether or not to return the number of iterations.

random_state : int, np.random.RandomStateInstance or None, default: None
Pseudo-random number generator to control the starting state.
See :term:`random_state`.

Returns
-------

Expand Down Expand Up @@ -133,7 +137,7 @@ def affinity_propagation(S, preference=None, convergence_iter=15, max_iter=200,
if return_n_iter
else (np.array([0]), np.array([0] * n_samples)))

random_state = np.random.RandomState(0)
random_state = check_random_state(random_state)

# Place preference on the diagonal of S
S.flat[::(n_samples + 1)] = preference
Expand Down
0