-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
random_forest_regression.sg
35 lines (29 loc) · 1.12 KB
/
random_forest_regression.sg
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
31
32
33
34
35
CSVFile f_feats_train("../../data/regression_1d_linear_features_train.dat")
CSVFile f_feats_test("../../data/regression_1d_linear_features_test.dat")
CSVFile f_labels_train("../../data/regression_1d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/regression_1d_linear_labels_test.dat")
set_global_seed(1)
#![create_features]
RealFeatures features_train(f_feats_train)
RealFeatures features_test(f_feats_test)
RegressionLabels labels_train(f_labels_train)
RegressionLabels labels_test(f_labels_test)
#![create_features]
#![create_combination_rule]
MeanRule mean_rule()
#![create_combination_rule]
#![create_instance]
RandomForest rand_forest(features_train, labels_train, 5)
rand_forest.set_combination_rule(mean_rule)
#![create_instance]
#![train_and_apply]
rand_forest.train()
RegressionLabels labels_predict = rand_forest.apply_regression(features_test)
#![train_and_apply]
#![evaluate_error]
MeanSquaredError mse()
real oob = rand_forest.get_oob_error(mse)
real mserror = mse.evaluate(labels_predict, labels_test)
#![evaluate_error]
# additional integration testing variables
RealVector output = labels_predict.get_labels()