@@ -184,6 +184,8 @@ def _preprocess_data(X, y, fit_intercept, normalize=False, copy=True,
184
184
def _rescale_data (X , y , sample_weight , order = 'C' ):
185
185
"""Rescale data so as to support sample_weight"""
186
186
n_samples = X .shape [0 ]
187
+ sparse_X = sparse .issparse (X )
188
+ sparse_y = sparse .issparse (y )
187
189
sample_weight = np .array (sample_weight )
188
190
if sample_weight .ndim == 0 :
189
191
sample_weight = np .full (n_samples , sample_weight ,
@@ -193,22 +195,26 @@ def _rescale_data(X, y, sample_weight, order='C'):
193
195
shape = (n_samples , n_samples ))
194
196
X = safe_sparse_dot (sw_matrix , X )
195
197
y = safe_sparse_dot (sw_matrix , y )
196
- if sparse .issparse (X ):
198
+
199
+ if sparse_X :
197
200
if order == 'F' :
198
- X = X .tocsc ()
199
- if y .ndim > 1 :
200
- y = y .tocsc ()
201
+ X = sparse .csc_matrix (X )
201
202
else :
202
- X = X . tocsr ( )
203
- if y . ndim > 1 :
204
- y = y . tocsr ( )
203
+ X = sparse . csr_matrix ( X )
204
+ elif order == 'F' :
205
+ X = np . asfortranarray ( X )
205
206
else :
207
+ X = np .ascontiguousarray (X )
208
+
209
+ if sparse_y :
206
210
if order == 'F' :
207
- X = np .asfortranarray (X )
208
- y = np .asfortranarray (y )
211
+ y = sparse .csc_matrix (y )
209
212
else :
210
- X = np .ascontiguousarray (X )
211
- y = np .ascontiguousarray (y )
213
+ y = sparse .csr_matrix (y )
214
+ elif order == 'F' :
215
+ y = np .asfortranarray (y )
216
+ else :
217
+ y = np .ascontiguousarray (y )
212
218
return X , y
213
219
214
220
0 commit comments