-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate_random_forest.py
30 lines (26 loc) · 1.04 KB
/
evaluate_random_forest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import argparse
from statistics import mean, stdev
import numpy as np
from sklearn.ensemble import RandomForestRegressor
parser = argparse.ArgumentParser()
parser.add_argument(
"-i", type=int, default=20, help="number of iterations that are done, default: 20"
)
args = parser.parse_args()
x_train = np.load("data/x_train.npy")
x_test = np.load("data/x_test.npy")
y_train = np.load("data/y_train.npy")
y_test = np.load("data/y_test.npy")
# train and evaluate i random forests, then average their scores
scores = []
for _ in range(args.i):
regressor = RandomForestRegressor()
regressor.fit(x_train, y_train)
# print(regressor.score(x_train, y_train)) # uncomment to print scores on train data
# print(x_test[:5]) # uncomment to see a few of the
# print(y_test[:5]) # true data points and labels
# print(regressor.predict(x_test[:5])) # uncomment to see predicted labels
score = regressor.score(x_test, y_test)
scores.append(score)
print(mean(scores))
print(stdev(scores))