Пример #1
0
class RotationForest():
    def __init__(self):
        super(RotationForest, self).__init__()
        self.rf = RotationForestClassifier()

    def train_step(self, X, y_train, plot=False):
        y_train = y_train["label"].astype('category').cat.codes
        self.rf.fit(X, y_train)

    def test_forced(self, X, y_test):
        y_test = y_test["label"].astype('category').cat.codes
        probabilities = self.rf.predict_proba(X)
        return probabilities, y_test
    def test_rotation_forest(self):
        """ Smoke test for rotation forest """
        X, y = classification_data()
        xt, xv, yt, yv = train_test_split(X, y, test_size=0.3, random_state=77)
        clf = RotationForestClassifier(random_state=1234)
        clf.fit(xt, yt)

        proba = clf.predict_proba(xv)
        assert proba.shape[0] == xv.shape[0]
        assert np.all(proba <= 1)
        assert np.all(proba >= 0)

        yhat = clf.predict(xv)
        assert yhat.shape[0] == xv.shape[0]
        assert np.unique(yhat).tolist() == [0, 1]