Skip to content

Commit fa6af0f

Browse files
committed
Fixes to sparse decision_function, rebase fixes.
1 parent e95815a commit fa6af0f

File tree

7 files changed

+1410
-1512
lines changed

7 files changed

+1410
-1512
lines changed

doc/whats_new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ Enhancements
207207
- Numerical stability improvements for :class:`preprocessing.StandardScaler`
208208
and :func:`preprocessing.scale`. By `Nicolas Goix`_
209209

210+
- :class:`svm.SVC` fitted on sparse input now implements ``decision_function``.
211+
By `Rob Zinkov`_ and `Andreas Müller`_.
212+
210213
Documentation improvements
211214
..........................
212215

sklearn/svm/base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,15 @@ def decision_function(self, X):
368368
X = self._validate_for_predict(X)
369369
X = self._compute_kernel(X)
370370

371-
X = self._validate_for_predict(X)
372-
373371
if self._sparse:
374372
dec_func = self._sparse_decision_function(X)
375373
else:
376374
dec_func = self._dense_decision_function(X)
377375

378376
# In binary case, we need to flip the sign of coef, intercept and
379377
# decision function.
380-
if self.impl != 'one_class' and len(self.classes_) == 2:
381-
return -dec_func
378+
if self._impl in ['c_svc', 'nu_svc'] and len(self.classes_) == 2:
379+
return -dec_func.ravel()
382380

383381
return dec_func
384382

@@ -412,11 +410,11 @@ def _sparse_decision_function(self, X):
412410
self.support_vectors_.indices,
413411
self.support_vectors_.indptr,
414412
self._dual_coef_.data, self._intercept_,
415-
LIBSVM_IMPL.index(self.impl), kernel_type,
416-
self.degree, self.gamma, self.coef0, self.tol,
413+
LIBSVM_IMPL.index(self._impl), kernel_type,
414+
self.degree, self._gamma, self.coef0, self.tol,
417415
self.C, self.class_weight_,
418416
self.nu, self.epsilon, self.shrinking,
419-
self.probability, self.n_support_, self._label,
417+
self.probability, self.n_support_,
420418
self.probA_, self.probB_)
421419

422420
def _validate_for_predict(self, X):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy