|
3 | 3 |
|
4 | 4 | TODO: remove hard coded numerical results when possible |
5 | 5 | """ |
6 | | - |
7 | 6 | import numpy as np |
8 | 7 | import itertools |
9 | 8 | from numpy.testing import assert_array_equal, assert_array_almost_equal |
|
25 | 24 | from sklearn.exceptions import ConvergenceWarning |
26 | 25 | from sklearn.exceptions import NotFittedError |
27 | 26 | from sklearn.multiclass import OneVsRestClassifier |
| 27 | +from sklearn.externals import six |
28 | 28 |
|
29 | 29 | # toy sample |
30 | 30 | X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]] |
@@ -521,6 +521,30 @@ def test_bad_input(): |
521 | 521 | assert_raises(ValueError, clf.predict, Xt) |
522 | 522 |
|
523 | 523 |
|
| 524 | +def test_unicode_kernel(): |
| 525 | + # Test that a unicode kernel name does not cause a TypeError on clf.fit |
| 526 | + if six.PY2: |
| 527 | + # Test unicode (same as str on python3) |
| 528 | + clf = svm.SVC(kernel=unicode('linear')) |
| 529 | + clf.fit(X, Y) |
| 530 | + |
| 531 | + # Test ascii bytes (str is bytes in python2) |
| 532 | + clf = svm.SVC(kernel=str('linear')) |
| 533 | + clf.fit(X, Y) |
| 534 | + else: |
| 535 | + # Test unicode (str is unicode in python3) |
| 536 | + clf = svm.SVC(kernel=str('linear')) |
| 537 | + clf.fit(X, Y) |
| 538 | + |
| 539 | + # Test ascii bytes (same as str on python2) |
| 540 | + clf = svm.SVC(kernel=bytes('linear', 'ascii')) |
| 541 | + clf.fit(X, Y) |
| 542 | + |
| 543 | + # Test default behavior on both versions |
| 544 | + clf = svm.SVC(kernel='linear') |
| 545 | + clf.fit(X, Y) |
| 546 | + |
| 547 | + |
524 | 548 | def test_sparse_precomputed(): |
525 | 549 | clf = svm.SVC(kernel='precomputed') |
526 | 550 | sparse_gram = sparse.csr_matrix([[1, 0], [0, 1]]) |
|
0 commit comments