@@ -297,15 +297,15 @@ def test_oneclass_score_samples():
297
297
298
298
def test_svdd ():
299
299
# Test the output of libsvm for the SVDD problem with default parameters
300
- clf = svm .SVDD ()
300
+ clf = svm .SVDD (gamma = 'scale' )
301
301
clf .fit (X )
302
302
pred = clf .predict (T )
303
303
304
304
assert_array_equal (pred , [- 1 , - 1 , - 1 ])
305
305
assert_equal (pred .dtype , np .dtype ('intp' ))
306
- assert_array_almost_equal (clf .intercept_ , [0.491 ], decimal = 3 )
306
+ assert_array_almost_equal (clf .intercept_ , [0.383 ], decimal = 3 )
307
307
assert_array_almost_equal (clf .dual_coef_ ,
308
- [[0.632 , 0.233 , 0.633 , 0.234 , 0.632 , 0.633 ]],
308
+ [[0.681 , 0.139 , 0.680 , 0.140 , 0.680 , 0.680 ]],
309
309
decimal = 3 )
310
310
assert_false (hasattr (clf , "coef_" ))
311
311
@@ -330,7 +330,8 @@ def test_svdd_decision_function():
330
330
X_outliers = rnd .uniform (low = - 4 , high = 4 , size = (20 , 2 ))
331
331
332
332
# fit the model
333
- clf = svm .SVDD (nu = 0.1 , kernel = "poly" , degree = 2 , coef0 = 1.0 ).fit (X_train )
333
+ clf = svm .SVDD (gamma = 'scale' , nu = 0.1 ,
334
+ kernel = "poly" , degree = 2 , coef0 = 1.0 ).fit (X_train )
334
335
335
336
# predict and validate things
336
337
y_pred_test = clf .predict (X_test )
@@ -373,17 +374,22 @@ def test_svdd_score_samples():
373
374
X_test = np .c_ [xx .ravel (), yy .ravel ()]
374
375
375
376
# Fit the model for at least 10% support vectors
376
- clf = svm .SVDD (nu = 0.1 , kernel = "poly" , degree = 2 , coef0 = 1.0 )
377
+ clf = svm .SVDD (nu = 0.1 , kernel = "poly" , gamma = 'scale' , degree = 2 , coef0 = 1.0 )
377
378
clf .fit (X_train )
378
379
379
380
# Check score_samples() implementation
380
381
assert_array_almost_equal (clf .score_samples (X_test ),
381
382
clf .decision_function (X_test ) + clf .offset_ )
382
383
384
+ # Test the gamma="scale"
385
+ gamma = 1.0 / (X .shape [1 ] * X_train .std ())
386
+
387
+ assert_almost_equal (clf ._gamma , gamma )
388
+
383
389
# Compute the kernel matrices
384
390
k_zx = polynomial_kernel (X_train [clf .support_ ], X_test ,
385
- degree = clf .degree , coef0 = clf .coef0 )
386
- k_xx = polynomial_kernel (X_test ,
391
+ gamma = gamma , degree = clf .degree , coef0 = clf .coef0 )
392
+ k_xx = polynomial_kernel (X_test , gamma = gamma ,
387
393
degree = clf .degree , coef0 = clf .coef0 ).diagonal ()
388
394
389
395
# Compute the sample scores = decision scores without `-\rho`
@@ -405,10 +411,10 @@ def test_oneclass_and_svdd():
405
411
# Test the output of libsvm for the SVDD and the One-Class SVM
406
412
nu = 0.15
407
413
408
- svdd = svm .SVDD (nu = nu , kernel = "rbf" )
414
+ svdd = svm .SVDD (nu = nu , kernel = "rbf" , gamma = "scale" )
409
415
svdd .fit (X_train )
410
416
411
- ocsvm = svm .OneClassSVM (nu = nu , kernel = "rbf" )
417
+ ocsvm = svm .OneClassSVM (nu = nu , kernel = "rbf" , gamma = "scale" )
412
418
ocsvm .fit (X_train )
413
419
414
420
# The intercept of the SVDD differs from that of the One-Class SVM:
0 commit comments