-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
random_forest.sg
36 lines (29 loc) · 1.16 KB
/
random_forest.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/classifier_4class_2d_linear_features_train.dat")
CSVFile f_feats_test("../../data/classifier_4class_2d_linear_features_test.dat")
CSVFile f_labels_train("../../data/classifier_4class_2d_linear_labels_train.dat")
CSVFile f_labels_test("../../data/classifier_4class_2d_linear_labels_test.dat")
set_global_seed(1)
#![create_features]
RealFeatures features_train(f_feats_train)
RealFeatures features_test(f_feats_test)
MulticlassLabels labels_train(f_labels_train)
MulticlassLabels labels_test(f_labels_test)
#![create_features]
#![create_combination_rule]
MajorityVote m_vote()
#![create_combination_rule]
#![create_instance]
RandomForest rand_forest(features_train, labels_train, 100)
rand_forest.set_combination_rule(m_vote)
#![create_instance]
#![train_and_apply]
rand_forest.train()
MulticlassLabels labels_predict = rand_forest.apply_multiclass(features_test)
#![train_and_apply]
#![evaluate_accuracy]
MulticlassAccuracy acc()
real oob = rand_forest.get_oob_error(acc)
real accuracy = acc.evaluate(labels_predict, labels_test)
#![evaluate_accuracy]
# additional integration testing variables
RealVector output = labels_predict.get_labels()