(csr_container)
| 205 | |
| 206 | @pytest.mark.parametrize("csr_container", CSR_CONTAINERS) |
| 207 | def test_sparse_decision_function(csr_container): |
| 208 | # Test decision_function |
| 209 | |
| 210 | # Sanity check, test that decision_function implemented in python |
| 211 | # returns the same as the one in libsvm |
| 212 | |
| 213 | # multi class: |
| 214 | iris_data_sp = csr_container(iris.data) |
| 215 | svc = svm.SVC(kernel="linear", C=0.1, decision_function_shape="ovo") |
| 216 | clf = svc.fit(iris_data_sp, iris.target) |
| 217 | |
| 218 | dec = safe_sparse_dot(iris_data_sp, clf.coef_.T) + clf.intercept_ |
| 219 | |
| 220 | assert_allclose(dec, clf.decision_function(iris_data_sp)) |
| 221 | |
| 222 | # binary: |
| 223 | clf.fit(X, Y) |
| 224 | dec = np.dot(X, clf.coef_.T) + clf.intercept_ |
| 225 | prediction = clf.predict(X) |
| 226 | assert_allclose(dec.ravel(), clf.decision_function(X)) |
| 227 | assert_allclose( |
| 228 | prediction, clf.classes_[(clf.decision_function(X) > 0).astype(int).ravel()] |
| 229 | ) |
| 230 | expected = np.array([-1.0, -0.66, -1.0, 0.66, 1.0, 1.0]) |
| 231 | assert_array_almost_equal(clf.decision_function(X), expected, decimal=2) |
| 232 | |
| 233 | |
| 234 | @pytest.mark.parametrize("lil_container", LIL_CONTAINERS) |
nothing calls this directly
no test coverage detected
searching dependent graphs…