8000 Fixes incorrect output for precomputed input · scikit-learn/scikit-learn@7e044d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e044d4

Browse files
committed
Fixes incorrect output for precomputed input
1 parent c6b2002 commit 7e044d4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sklearn/cluster/dbscan_.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ def dbscan(X, eps=0.5, min_samples=5, metric='minkowski', metric_params=None,
121121
# neighborhood of point i. While True, its useless information)
122122
if metric == 'precomputed' and sparse.issparse(X):
123123
neighborhoods = np.empty(X.shape[0], dtype=object)
124+
125+
#Modify X so that every element first row are not zero
126+
if X.indptr[0] == X.indptr[1] == 0:
127+
indptr = X.indptr
128+
indptr = indptr+1
129+
indptr[1] = 1
130+
indptr[0] = 0
131+
indices = np.insert(X.indices, 0, 0)
132+
data = np.insert(X.data, 0, eps+1)
133+
X = sparse.csr_matrix((data, indices, indptr), shape=X.shape)
134+
124135
X.sum_duplicates() # XXX: modifies X's internals in-place
125136
X_mask = X.data <= eps
126137
masked_indices = astype(X.indices, np.intp, copy=False)[X_mask]

0 commit comments

Comments
 (0)
0