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