Skip to content

Commit 48fa476

Browse files
author
Fabian Pedregosa
committed
FIX: always raise ValueError on deficient input in BaseLibSVM.
1 parent 5116c3d commit 48fa476

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

scikits/learn/svm/base.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ class BaseLibSVM(BaseEstimator):
3838
def __init__(self, impl, kernel, degree, gamma, coef0, cache_size,
3939
eps, C, nu, p, shrinking, probability):
4040

41-
assert impl in self._svm_types, \
42-
"impl should be one of %s, %s was given" % (
43-
self._svm_types, impl)
44-
45-
assert kernel in self._kernel_types or \
46-
hasattr(kernel, '__call__'), \
47-
"kernel should be one of %s or a callable, " \
48-
"%s was given." % ( self._kernel_types, kernel)
41+
if not impl in self._svm_types:
42+
raise ValueError("impl should be one of %s, %s was given" % (
43+
self._svm_types, impl))
44+
45+
if not kernel in self._kernel_types or hasattr(kernel, '__call__'):
46+
raise ValueError("kernel should be one of %s or a callable, " \
47+
"%s was given." % ( self._kernel_types, kernel))
4948

5049
self.kernel = kernel
5150
self.impl = impl

scikits/learn/svm/tests/test_svm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_error():
328328

329329
Y2 = Y[:-1] # wrong dimensions for labels
330330
assert_raises(ValueError, clf.fit, X, Y2)
331-
assert_raises(AssertionError, svm.SVC, X, Y2)
331+
assert_raises(ValueError, svm.SVC, X, Y2)
332332

333333
# Test with arrays that are non-contiguous.
334334
Xf = np.asfortranarray(X)
@@ -361,6 +361,7 @@ def test_LinearSVC():
361361
clf = svm.LinearSVC(penalty='l2', loss='l1', dual=True).fit(X, Y)
362362
assert_array_equal(clf.predict(T), true_result)
363363

364+
# test also decision function
364365
dec = clf.decision_function(X)
365366
assert_array_equal(np.argmax(dec, 1), true_result)
366367

0 commit comments

Comments
 (0)