@@ -177,12 +177,12 @@ def fit(self, X, y, sample_weight=None):
177
177
"boolean masks (use `indices=True` in CV)."
178
178
% (sample_weight .shape , X .shape ))
179
179
180
- kernel = self .kernel
181
- if callable (kernel ):
182
- kernel = 'precomputed'
180
+ kernel = 'precomputed' if callable (self .kernel ) else self .kernel
183
181
184
182
if kernel == 'precomputed' :
185
- self ._gamma = 0. # unused but needs to be a float
183
+ # unused but needs to be a float for cython code that ignores
184
+ # it anyway
185
+ self ._gamma = 0.
186
186
elif isinstance (self .gamma , str ):
187
187
if self .gamma == 'scale' :
188
188
# var = E[X^2] - E[X]^2 if sparse
@@ -207,10 +207,7 @@ def fit(self, X, y, sample_weight=None):
207
207
fit (X , y , sample_weight , solver_type , kernel , random_seed = seed )
208
208
# see comment on the other call to np.iinfo in this file
209
209
210
- if hasattr (X , 'shape' ):
211
- self .shape_fit_ = X .shape
212
- else :
213
- self .shape_fit_ = (_num_samples (X ),)
210
+ self .shape_fit_ = X .shape if hasattr (X , "shape" ) else (n_samples , )
214
211
215
212
# In binary case, we need to flip the sign of coef, intercept and
216
213
# decision function. Use self._intercept_ and self._dual_coef_
@@ -467,18 +464,16 @@ def _validate_for_predict(self, X):
467
464
raise ValueError (
468
465
"cannot use sparse input in %r trained on dense data"
469
466
% type (self ).__name__ )
470
- if not callable (self .kernel ):
471
- n_features = X .shape [1 ]
472
467
473
468
if self .kernel == "precomputed" :
474
469
if X .shape [1 ] != self .shape_fit_ [0 ]:
475
470
raise ValueError ("X.shape[1] = %d should be equal to %d, "
476
471
"the number of samples at training time" %
477
472
(X .shape [1 ], self .shape_fit_ [0 ]))
478
- elif not callable (self .kernel ) and n_features != self .shape_fit_ [1 ]:
473
+ elif not callable (self .kernel ) and X . shape [ 1 ] != self .shape_fit_ [1 ]:
479
474
raise ValueError ("X.shape[1] = %d should be equal to %d, "
480
475
"the number of features at training time" %
481
- (n_features , self .shape_fit_ [1 ]))
476
+ (X . shape [ 1 ] , self .shape_fit_ [1 ]))
482
477
return X
483
478
484
479
@property
0 commit comments