def _test_boston_poly_compare_with_sklearn(params): diabetes = datasets.load_boston() clf = SVR(kernel='poly', **params) clf.fit(diabetes.data, diabetes.target) result = clf.score(diabetes.data, diabetes.target) clf = SklearnSVR(kernel='poly', **params) clf.fit(diabetes.data, diabetes.target) expected = clf.score(diabetes.data, diabetes.target) assert result > 0.5 assert result > expected - 1e-5
def _test_boston_rbf_compare_with_sklearn(C, gamma): diabetes = datasets.load_boston() clf = SVR(kernel='rbf', gamma=gamma, C=C) clf.fit(diabetes.data, diabetes.target) result = clf.score(diabetes.data, diabetes.target) clf = SklearnSVR(kernel='rbf', gamma=gamma, C=C) clf.fit(diabetes.data, diabetes.target) expected = clf.score(diabetes.data, diabetes.target) assert result > 0.4 assert result > expected - 1e-5
def _test_boston_linear_compare_with_sklearn(C): diabetes = datasets.load_boston() clf = SVR(kernel='linear', C=C) clf.fit(diabetes.data, diabetes.target) result = clf.score(diabetes.data, diabetes.target) clf = SklearnSVR(kernel='linear', C=C) clf.fit(diabetes.data, diabetes.target) expected = clf.score(diabetes.data, diabetes.target) assert result > 0.5 assert result > expected - 1e-3
def _test_diabetes_compare_with_sklearn(kernel): diabetes = datasets.load_diabetes() clf_onedal = SVR(kernel=kernel, C=10.) clf_onedal.fit(diabetes.data, diabetes.target) result = clf_onedal.score(diabetes.data, diabetes.target) clf_sklearn = SklearnSVR(kernel=kernel, C=10.) clf_sklearn.fit(diabetes.data, diabetes.target) expected = clf_sklearn.score(diabetes.data, diabetes.target) assert result > expected - 1e-5 assert_allclose(clf_sklearn.intercept_, clf_onedal.intercept_, atol=1e-4) assert_allclose(clf_sklearn.support_vectors_.shape, clf_sklearn.support_vectors_.shape) assert_allclose(clf_sklearn.dual_coef_, clf_onedal.dual_coef_, atol=1e-2)
def test_diabetes_simple(): diabetes = datasets.load_diabetes() clf = SVR(kernel='linear', C=10.) clf.fit(diabetes.data, diabetes.target) assert clf.score(diabetes.data, diabetes.target) > 0.02