1818import pytest
1919from numpy .testing import assert_allclose , assert_array_almost_equal , assert_array_equal
2020from sklearn import datasets
21+ from sklearn .metrics import r2_score
2122from sklearn .metrics .pairwise import rbf_kernel
2223from sklearn .svm import SVR as SklearnSVR
2324
@@ -176,10 +177,12 @@ def test_synth_linear_compare_with_sklearn(queue, C):
176177
177178def _test_synth_poly_compare_with_sklearn (queue , params ):
178179 x , y = datasets .make_regression (** synth_params )
179- clf = SVR (kernel = "poly" , ** params )
180+ gamma = 1.0 / (x .shape [1 ] * x .var ())
181+ clf = SVR (kernel = "poly" , gamma = gamma , ** params )
180182 clf .fit (x , y , queue = queue )
181- result = clf .score (x , y , queue = queue )
183+ result = r2_score ( y , clf .predict (x , queue = queue ) )
182184
185+ # gamma='scale' by default in sklearn
183186 clf = SklearnSVR (kernel = "poly" , ** params )
184187 clf .fit (x , y )
185188 expected = clf .score (x , y )
@@ -193,8 +196,8 @@ def _test_synth_poly_compare_with_sklearn(queue, params):
193196@pytest .mark .parametrize (
194197 "params" ,
195198 [
196- {"degree" : 2 , "coef0" : 0.1 , "gamma" : "scale" , " C" : 100 },
197- {"degree" : 3 , "coef0" : 0.0 , "gamma" : "scale" , " C" : 1000 },
199+ {"degree" : 2 , "coef0" : 0.1 , "C" : 100 },
200+ {"degree" : 3 , "coef0" : 0.0 , "C" : 1000 },
198201 ],
199202)
200203def test_synth_poly_compare_with_sklearn (queue , params ):
0 commit comments