Ejemplo n.º 1
0
def test_rf(n, reps, n_estimators):

    preds = np.zeros((reps, 10000))
    acc = np.zeros(reps)
    for i in range(reps):

        X_train, y_train, X_test, y_test = load_data(n)

        clf = rfc(n_estimators=n_estimators, projection_matrix="Base")

        clf.fit(X_train, y_train)

        preds[i] = clf.predict(X_test)
        acc[i] = np.sum(preds[i] == y_test) / len(y_test)

    np.save("output/rf_orthant_preds_" + str(n) + ".npy", preds)
    return acc
Ejemplo n.º 2
0
feature_combinations = [2, 3, 4, 5]
max_features = [3, 5, 10, 20]  # ceil of 20 ^ (0.25, 0.5, 0.75, 1)

dftrain = np.load("data/orthant_train_400.npy")
dftest = np.load("data/orthant_test.npy")

X_train = dftrain[:, :-1]
y_train = dftrain[:, -1]

X_test = dftest[:, :-1]
y_test = dftest[:, -1]

param_acc = np.zeros((4, 4))

for i, f in enumerate(feature_combinations):
    for j, m in enumerate(max_features):

        for k in range(3):

            clf = rfc(n_estimators=n_estimators,
                      projection_matrix="RerF",
                      feature_combinations=f,
                      max_features=m)

            clf.fit(X_train, y_train)
            preds = clf.predict(X_test)
            param_acc[i, j] = np.sum(preds == y_test) / len(y_test)

print(param_acc)
np.save("orthant_gridsearch", param_acc)
Ejemplo n.º 3
0
from sklearn.datasets import load_iris

from rerf.rerfClassifier import rerfClassifier as rfc
from proglearn.transformers import ObliqueTreeClassifier as of

data = load_iris()
X, y = data.data, data.target

rerf_acc = np.zeros(5)
of_acc = np.zeros(5)
for i in range(5):
    OF = of(  #oblique=True, 
        max_features=1.0, feature_combinations=1.0)

    RFC = rfc(n_estimators=1,
              projection_matrix="RerF",
              feature_combinations=1.0,
              max_features=1.0)

    # Rerf
    RFC.fit(X, y)
    rerf_preds = RFC.predict(X)
    rerf_acc[i] = np.sum(rerf_preds == y) / len(y)

    # Of
    OF.fit(X, y)
    of_preds = OF.predict(X)
    of_acc[i] = np.sum(of_preds == y) / len(y)

print("RerF: ", np.mean(rerf_acc))
print("OF: ", np.mean(of_acc))