Exemple #1
0
def test_multiclass_kernel_sgd():
    for fit_intercept in (True, False):
        clf = KernelSGDClassifier(kernel="rbf", gamma=0.1,
                                  fit_intercept=fit_intercept,
                                  random_state=0)
        clf.fit(mult_dense, mult_target)
        assert_equal(clf.score(mult_dense, mult_target), 1.0)
Exemple #2
0
def test_n_components_multiclass_natural():
    for loss in ("hinge", "log"):
        clf = KernelSGDClassifier(loss=loss, multiclass="natural",
                                  kernel="rbf", gamma=0.1, n_components=50,
                                  random_state=0)
        clf.fit(mult_dense, mult_target)
        assert_equal(clf.n_support_vectors(), 50)
        assert_greater(clf.score(mult_dense, mult_target), 0.38)
Exemple #3
0
def test_multiclass_hinge_kernel_sgd():
    for fit_intercept in (True, False):
        clf = KernelSGDClassifier(kernel="rbf", gamma=0.1,
                                  loss="hinge", multiclass="natural",
                                  fit_intercept=fit_intercept,
                                  random_state=0)
        clf.fit(mult_dense, mult_target)
        assert_greater(clf.score(mult_dense, mult_target), 0.90)
Exemple #4
0
def test_multiclass_sgd_equivalence():
    clf = KernelSGDClassifier(kernel="linear",
                              random_state=0)
    clf.fit(mult_dense, mult_target)
    decisions = clf.decision_function(mult_dense)
    predictions = clf.predict(mult_dense)

    clf = SGDClassifier(random_state=0)
    clf.fit(mult_dense, mult_target)
    decisions2 = clf.decision_function(mult_dense)
    predictions2 = clf.predict(mult_dense)

    assert_array_almost_equal(decisions, decisions2)
    assert_array_almost_equal(predictions, predictions2)
Exemple #5
0
def test_multiclass_natural_kernel_sgd_equivalence():
    for loss in ("hinge", "log"):
        clf = KernelSGDClassifier(kernel="linear",
                                  loss=loss, multiclass="natural",
                                  random_state=0)
        clf.fit(mult_dense, mult_target)
        decisions = clf.decision_function(mult_dense)
        predictions = clf.predict(mult_dense)

        clf = SGDClassifier(random_state=0, loss=loss, multiclass="natural")
        clf.fit(mult_dense, mult_target)
        decisions2 = clf.decision_function(mult_dense)
        predictions2 = clf.predict(mult_dense)

        assert_array_almost_equal(decisions, decisions2)
        assert_array_almost_equal(predictions, predictions2)
Exemple #6
0
def test_n_components_multiclass():
    clf = KernelSGDClassifier(kernel="rbf", gamma=1.0, loss="hinge",
                              random_state=0, n_components=50)
    clf.fit(mult_dense, mult_target)
    assert_equal(clf.n_support_vectors(), 55)
    assert_greater(clf.score(mult_dense, mult_target), 0.3)
Exemple #7
0
def test_n_components_binary():
    clf = KernelSGDClassifier(kernel="rbf", gamma=0.1, loss="hinge",
                              random_state=0, n_components=50)
    clf.fit(bin_dense, bin_target)
    assert_equal(clf.n_support_vectors(), 50)
    assert_greater(clf.score(bin_dense, bin_target), 0.6)