| 1 | diff --git a/sklearn/cluster/_affinity_propagation.py b/sklearn/cluster/_affinity_propagation.py |
| 2 | --- a/sklearn/cluster/_affinity_propagation.py |
| 3 | +++ b/sklearn/cluster/_affinity_propagation.py |
| 4 | @@ -194,17 +194,19 @@ def affinity_propagation(S, preference=None, convergence_iter=15, max_iter=200, |
| 5 | unconverged = (np.sum((se == convergence_iter) + (se == 0)) |
| 6 | != n_samples) |
| 7 | if (not unconverged and (K > 0)) or (it == max_iter): |
| 8 | + never_converged = False |
| 9 | if verbose: |
| 10 | print("Converged after %d iterations." % it) |
| 11 | break |
| 12 | else: |
| 13 | + never_converged = True |
| 14 | if verbose: |
| 15 | print("Did not converge") |
| 16 | |
| 17 | I = np.flatnonzero(E) |
| 18 | K = I.size # Identify exemplars |
| 19 | |
| 20 | - if K > 0: |
| 21 | + if K > 0 and not never_converged: |
| 22 | c = np.argmax(S[:, I], axis=1) |
| 23 | c[I] = np.arange(K) # Identify clusters |
| 24 | # Refine the final set of exemplars and clusters and return results |
| 25 | @@ -408,6 +410,7 @@ def predict(self, X): |
| 26 | Cluster labels. |
| 27 | """ |
| 28 | check_is_fitted(self) |
| 29 | + X = check_array(X) |
| 30 | if not hasattr(self, "cluster_centers_"): |
| 31 | raise ValueError("Predict method is not supported when " |
| 32 | "affinity='precomputed'.") |