Implementation of Random Forest Classifier
The RandomForestClassifier class grows a number of trees using the DecisionTreeClassifier class. The training data for growing each tree is obtained using bootstrap sampling from the training data passed as input to the fit member function of this class.
-
class RandomForestClassifier : public ml::BaseModel
Public Functions
Constructor.
-
inline ~RandomForestClassifier()
Destructor.
-
virtual void set_data(TrainTestData &&train_test)
Initialize data.
Note the use of std::move(object).member instead of move(object.member) See https://oliora.github.io/2016/02/12/where-to-put-std-move.html.
-
void get_bootstrap_sample(vector<vector<double>> &features_sample, vector<vector<double>> &outputs_sample)
Get bootstrap sample.
-
virtual void fit()
Perform model training.
-
vector<vector<double>> predict()
Perform model inference.
-
virtual void evaluate()
Evaluate model using test data.
Public Members
-
nlohmann::json parameters
Parameters to pass to Decision Tree constructor.
-
vector<shared_ptr<DecisionTreeClassifier>> trees = {}
An array of decision trees.
-
vector<vector<double>> train_features = {}
Training features.
-
vector<vector<double>> train_labels = {}
Training labels.
-
vector<vector<double>> test_features = {}
Test features.
-
vector<vector<double>> test_labels = {}
Test labels.