Example #1
0
    def test_incremental_learning(self):
        # Test that we can initialize the RF, add a feature, score, add features, score.

        rf = RF(y, mtry=0.8, n_jobs=2, seed=2001)
        rf.fit(X0)
        prediction1 = rf.score(X0)
        rf.fit(X1)
        prediction2 = rf.score(column_stack((X0, X1)))

        assert_almost_equal(
            prediction1,
            y,
            err_msg="Feature X0 is a leaking feature - overfit on it!")
        assert_almost_equal(
            prediction2,
            y,
            err_msg="Feature X0 is a leaking feature - overfit on it!")
Example #2
0
class RFWrapper:
    """
    Online Random Forest.
    """
    def __init__(self, y, X_t, y_t, n_jobs, mtry, random_state):
        self.rf = RF(y, n_jobs=n_jobs, mtry=mtry, seed=random_state)
        self.X_t = X_t
        self.y_t = y_t

    def fit(self, x):
        self.rf.fit(x)

    def get_auc(self):
        prediction = self.rf.score(self.X_t)
        fpr, tpr, thresholds = metrics.roc_curve(self.y_t,
                                                 prediction,
                                                 pos_label=1)
        return metrics.auc(fpr, tpr)