Skip to content

Commit 8fc9918

Browse files
committed
Sparse matrix conversion depending on the type of metric
If metric is "manhattan", then store it as csc since calculating the median is easier.
1 parent bda6706 commit 8fc9918

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sklearn/neighbors/nearest_centroid.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ def fit(self, X, y):
9494
y : array, shape = [n_samples]
9595
Target values (integers)
9696
"""
97-
X, y = check_X_y(X, y, ['csc'])
97+
# If X is sparse and the metric is "manhattan", store it in a csc
98+
# format is easier to calculate the median.
99+
if self.metric == 'manhattan':
100+
X, y = check_X_y(X, y, ['csc'])
101+
else:
102+
X, y = check_X_y(X, y, ['csr', 'csc'])
98103
is_X_sparse = sp.issparse(X)
99104
if is_X_sparse and self.shrink_threshold:
100105
raise ValueError("threshold shrinking not supported"

0 commit comments

Comments
 (0)