@@ -166,7 +166,10 @@ def predict(self, X):
166
166
-------
167
167
C : array, shape = [n_samples]
168
168
"""
169
- X = np .atleast_2d (np .asanyarray (X , dtype = np .float64 , order = 'C' ))
169
+ X = np .asanyarray (X , dtype = np .float64 , order = 'C' )
170
+ if X .ndim == 1 :
171
+ # don't use np.atleast_2d, it doesn't guarantee C-contiguity
172
+ X = np .reshape (X , (1 , - 1 ), order = 'C' )
170
173
n_samples , n_features = X .shape
171
174
X = self ._compute_kernel (X )
172
175
@@ -212,7 +215,10 @@ def predict_proba(self, X):
212
215
if not self .probability :
213
216
raise ValueError (
214
217
"probability estimates must be enabled to use this method" )
215
- X = np .atleast_2d (np .asanyarray (X , dtype = np .float64 , order = 'C' ))
218
+ X = np .asanyarray (X , dtype = np .float64 , order = 'C' )
219
+ if X .ndim == 1 :
220
+ # don't use np.atleast_2d, it doesn't guarantee C-contiguity
221
+ X = np .reshape (X , (1 , - 1 ), order = 'C' )
216
222
X = self ._compute_kernel (X )
217
223
if self .impl not in ('c_svc' , 'nu_svc' ):
218
224
raise NotImplementedError ("predict_proba only implemented for SVC and NuSVC" )
@@ -265,7 +271,10 @@ def decision_function(self, X):
265
271
Returns the decision function of the sample for each class
266
272
in the model.
267
273
"""
268
- X = np .atleast_2d (np .asanyarray (X , dtype = np .float64 , order = 'C' ))
274
+ X = np .asanyarray (X , dtype = np .float64 , order = 'C' )
275
+ if X .ndim == 1 :
276
+ # don't use np.atleast_2d, it doesn't guarantee C-contiguity
277
+ X = np .reshape (X , (1 , - 1 ), order = 'C' )
269
278
X = self ._compute_kernel (X )
270
279
271
280
dec_func = libsvm .decision_function (
@@ -411,7 +420,10 @@ def decision_function(self, X):
411
420
Returns the decision function of the sample for each class
412
421
in the model.
413
422
"""
414
- X = np .atleast_2d (np .asanyarray (X , dtype = np .float64 , order = 'C' ))
423
+ X = np .asanyarray (X , dtype = np .float64 , order = 'C' )
424
+ if X .ndim == 1 :
425
+ # don't use np.atleast_2d, it doesn't guarantee C-contiguity
426
+ X = np .reshape (X , (1 , - 1 ), order = 'C' )
415
427
self ._check_n_features (X )
416
428
417
429
dec_func = liblinear .decision_function_wrap (
0 commit comments