Beispiel #1
0
def test_classif_sample_weight():
    for criterion in ("gini", "entropy"):
        sk = 0
        iv = 0

        for X, y, w in _make_classification_datasets(10, sw=True):
            clf = skClassifTree(criterion=criterion, max_depth=5)
            clf.fit(X, y, w)
            y_pred = clf.predict(X)
            sk += accuracy_score(y, y_pred, sample_weight=w)

            clf = TreeClassifier(criterion=criterion, max_depth=5)
            clf.fit(X, y, w)
            y_pred = clf.predict(X)
            iv += accuracy_score(y, y_pred, sample_weight=w)

        sk /= 10
        iv /= 10

    assert_almost_equal(sk, iv)
Beispiel #2
0
def test_classif_sample_weight():
    for criterion in ("gini", "entropy"):
        sk = 0
        iv = 0

        for X, y, w in _make_classification_datasets(10, sw=True):
            clf = skClassifTree(criterion=criterion, max_depth=5)
            clf.fit(X, y, w)
            y_pred = clf.predict(X)
            sk += accuracy_score(y, y_pred, sample_weight=w)

            clf = TreeClassifier(criterion=criterion, max_depth=5)
            clf.fit(X, y, w)
            y_pred = clf.predict(X)
            iv += accuracy_score(y, y_pred, sample_weight=w)

        sk /= 10
        iv /= 10

    assert_almost_equal(sk, iv)
Beispiel #3
0
def test_classif_max_depth():
    for criterion in ("gini", "entropy"):
        sk = 0
        iv = 0

        for X, y in _make_classification_datasets(10):
            clf = skClassifTree(criterion=criterion,
                                max_depth=5,
                                random_state=1)
            clf.fit(X, y)
            y_pred = clf.predict(X)
            sk += np.mean(y == y_pred)

            clf = TreeClassifier(criterion=criterion,
                                 max_depth=5,
                                 random_state=1)
            clf.fit(X, y)
            y_pred = clf.predict(X)
            iv += np.mean(y == y_pred)

        sk /= 10
        iv /= 10

    assert_almost_equal(sk, iv)
Beispiel #4
0
def test_classif_max_depth():
    for criterion in ("gini", "entropy"):
        sk = 0
        iv = 0

        for X, y in _make_classification_datasets(10):
            clf = skClassifTree(criterion=criterion,
                                max_depth=5,
                                random_state=1)
            clf.fit(X, y)
            y_pred = clf.predict(X)
            sk += np.mean(y == y_pred)

            clf = TreeClassifier(criterion=criterion,
                                         max_depth=5,
                                         random_state=1)
            clf.fit(X, y)
            y_pred = clf.predict(X)
            iv += np.mean(y == y_pred)

        sk /= 10
        iv /= 10

    assert_almost_equal(sk, iv)