Closed
Description
Description
Using dbscan with precomputed neighbors gives an error in 0.22.X, but not in 0.21.3.
I am not sure if this is an intended change or not, but could not see anything on this in the release history. If this is due to a mistake on my part on how to us precomputed neighbors, please tell me, and I will direct my question elsewhere.
Steps/Code to Reproduce
import numpy as np
from sklearn.cluster import dbscan
from sklearn.neighbors import radius_neighbors_graph
space = np.ones((4, 3))
neighbors_distances = radius_neighbors_graph(space, radius=2, mode="distance")
core_samples, cluster_labels = dbscan(
neighbors_distances, min_samples=1, metric="precomputed"
)
print(cluster_labels)
The error can also be encountered using a random space, for example:
np.random.seed(3)
space = np.random.random((4, 3))
print(space)
# [[0.5507979 0.70814782 0.29090474]
# [0.51082761 0.89294695 0.89629309]
# [0.12558531 0.20724288 0.0514672 ]
# [0.44080984 0.02987621 0.45683322]]
Expected Results
Output in 0.21.3:
[0 0 0 0]
Actual Results
Output in 0.22.0 and 0.22.1:
Traceback (most recent call last):
File "test.py", line 29, in <module>
neighbors_distances, min_samples=1, metric="precomputed"
File "/home/simen/src/miniconda3/envs/dfs/lib/python3.6/site-packages/sklearn/cluster/_dbscan.py", line 144, in dbscan
est.fit(X, sample_weight=sample_weight)
File "/home/simen/src/miniconda3/envs/dfs/lib/python3.6/site-packages/sklearn/cluster/_dbscan.py", line 350, in fit
dbscan_inner(core_samples, neighborhoods, labels)
File "sklearn/cluster/_dbscan_inner.pyx", line 19, in sklearn.cluster._dbscan_inner.dbscan_inner
ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
Versions
Dependencies with 0.21.3:
System:
python: 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) [GCC 7.3.0]
executable: /home/simen/src/miniconda3/envs/dfs/bin/python
machine: Linux-5.0.0-37-generic-x86_64-with-debian-buster-sid
Python deps:
pip: 19.1.1
setuptools: 39.1.0
sklearn: 0.21.3
numpy: 1.18.0
scipy: 1.4.1
Cython: 0.29.2
pandas: 0.25.3
Dependencies with 0.22.0:
System:
python: 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) [GCC 7.3.0]
executable: /home/simen/src/miniconda3/envs/dfs/bin/python
machine: Linux-5.0.0-37-generic-x86_64-with-debian-buster-sid
Python dependencies:
pip: 19.1.1
setuptools: 39.1.0
sklearn: 0.22
numpy: 1.18.0
scipy: 1.4.1
Cython: 0.29.2
pandas: 0.25.3
matplotlib: 3.1.2
joblib: 0.14.1
Built with OpenMP: True