For the random forest algorithm, I think everyone will go to the paper and recommend two URLs for foreigners. To put it bluntly, the process of random forest classification is to classify samples for each randomly generated decision tree classifier, input feature vector, and each tree in the forest, obtain the final classification result based on the weight of each tree. All tree training uses the same parameters, but the training set is different. The classifier Error Estimates use OOB (Out
Of bag. If you understand it, the next step is simple.
Let's first introduce the classes and functions corresponding to opencv. We have previously introduced machine learning classes in general, including cvrtparams and cvrtrees for random forest algorithms. I will explain it as follows:
The cvrtparams class contains all the parameters that need to be set during random Forest Training and inherits from cvdtparams. Where
Max_depth indicates the maximum depth of a single tree
Min_sample_count threshold. When the number of samples of a node is smaller than the threshold, the node is not split.
Regression_accuracy threshold value when returning to the inverse tree
Does use_surrogates use a proxy? (This is the magic horse function ...)
Max_categories maximum classification threshold
Possibility of priors prior classification
Indicates whether the importance of the calc_var_importance variable is calculated.
Nactive_vars size of feature subsets selected for each tree
Max_num_of_trees_in_the_forest
Forest_accuracy precision of OOB error in Forest Training
Termcrit_type type selected by the Forest Training threshold
The value assignment of the preceding parameters is implemented by the cvrtparams constructor.
Cvrtrees is the subject of the random forest. Contains the train training function, predict prediction function, predict_prob returned prediction classification label, getvarimportance returned Variable Weight Matrix, get_proximity returned similarity between two training samples, calc_error returned random forest prediction error, get_train_error returns the training error, get_rng returns the current value of the random number, get_tree_count returns the number of trees that construct the random forest, and get_tree returns the number of trees that construct the random forest.
Next, we will use the letter_recog.cpp provided by the sample to explain how to use the random forest Algorithm for letter recognition. The training sample library selected here is random. The training file letter-recognition.data has 20000 training letters, each represented by a 16-dimensional feature. This program uses the first 16000 for training and the last 4000 for testing. The only thing that upset me was that this program was written using the old data structure, so I decided to write it again with the new structure. I simplified the original program, deleted many irrelevant and unnecessary parts.
In fact, the use of random forest is very simple. The two most important steps are nothing more than the train () and predict () functions. Other functions are used to obtain test results.
Here I simplified it with a new structure after the code download link to the http://download.csdn.net/detail/yang_xian521/4134557