Esempio n. 1
0
 def test_with_X_nan(self, iris_X, iris_y):
     iris_X_nan = iris_X.copy()
     index = np.random.choice(iris_X_nan.size, 100, replace=False)
     iris_X_nan.ravel()[index] = np.nan
     assert np.sum(np.isnan(iris_X_nan)) == 100
     forest = GRFForestClassifier()
     forest.fit(iris_X_nan, iris_y)
     pred = forest.predict(iris_X_nan)
     assert len(pred) == iris_X_nan.shape[0]
Esempio n. 2
0
    def test_accuracy(self, iris_X, iris_y):
        X_train, X_test, y_train, y_test = train_test_split(iris_X,
                                                            iris_y,
                                                            test_size=0.33,
                                                            random_state=42)

        # train and test a random forest classifier
        rf = RandomForestClassifier()
        rf.fit(X_train, y_train)
        y_pred_rf = rf.predict(X_test)
        rf_acc = accuracy_score(y_test, y_pred_rf)

        # train and test a ranger classifier
        ra = GRFForestClassifier()
        ra.fit(X_train, y_train)
        y_pred_ra = ra.predict(X_test)
        ranger_acc = accuracy_score(y_test, y_pred_ra)

        # the accuracy should be good
        assert rf_acc > 0.9
        assert ranger_acc > 0.9
Esempio n. 3
0
 def test_predict(self, iris_X, iris_y):
     forest = GRFForestClassifier()
     forest.fit(iris_X, iris_y)
     pred = forest.predict(iris_X)
     assert len(pred) == iris_X.shape[0]