Elffuss BraidHub

kikocis/auto-code-rover public

main · 1.8 KiBRawPermalink
1Return values of non converged affinity propagation clustering
2The affinity propagation Documentation states:
3"When the algorithm does not converge, it returns an empty array as cluster_center_indices and -1 as label for each training sample."
4
5Example:
6```python
7from sklearn.cluster import AffinityPropagation
8import pandas as pd
9
10data = pd.DataFrame([[1,0,0,0,0,0],[0,1,1,1,0,0],[0,0,1,0,0,1]])
11af = AffinityPropagation(affinity='euclidean', verbose=True, copy=False, max_iter=2).fit(data)
12
13print(af.cluster_centers_indices_)
14print(af.labels_)
15
16```
17I would expect that the clustering here (which does not converge) prints first an empty List and then [-1,-1,-1], however, I get [2] as cluster center and [0,0,0] as cluster labels.
18The only way I currently know if the clustering fails is if I use the verbose option, however that is very unhandy. A hacky solution is to check if max_iter == n_iter_ but it could have converged exactly 15 iterations before max_iter (although unlikely).
19I am not sure if this is intended behavior and the documentation is wrong?
20
21For my use-case within a bigger script, I would prefer to get back -1 values or have a property to check if it has converged, as otherwise, a user might not be aware that the clustering never converged.
22
23
24#### Versions
25System:
26 python: 3.6.7 | packaged by conda-forge | (default, Nov 21 2018, 02:32:25) [GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]
27executable: /home/jenniferh/Programs/anaconda3/envs/TF_RDKit_1_19/bin/python
28 machine: Linux-4.15.0-52-generic-x86_64-with-debian-stretch-sid
29BLAS:
30 macros: SCIPY_MKL_H=None, HAVE_CBLAS=None
31 lib_dirs: /home/jenniferh/Programs/anaconda3/envs/TF_RDKit_1_19/lib
32cblas_libs: mkl_rt, pthread
33Python deps:
34 pip: 18.1
35 setuptools: 40.6.3
36 sklearn: 0.20.3
37 numpy: 1.15.4
38 scipy: 1.2.0
39 Cython: 0.29.2
40 pandas: 0.23.4
41
42