MCPcopy
hub / github.com/scikit-learn/scikit-learn / test_sparse_decision_function

Function test_sparse_decision_function

sklearn/svm/tests/test_sparse.py:207–231  ·  view source on GitHub ↗
(csr_container)

Source from the content-addressed store, hash-verified

205
206@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
207def 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)

Callers

nothing calls this directly

Calls 5

safe_sparse_dotFunction · 0.90
assert_allcloseFunction · 0.90
fitMethod · 0.45
decision_functionMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…