Random Forest and how it works

i-king-of-ml
3 min readOct 28, 2019

--

Random Forest

Random Forest is a Machine Learning Algorithm based on Decision Trees. Random forest works on the ensemble method which is very common these days. The ensemble method means that to make a decision collectively based on the decision trees. Actually, we make a prediction, not simply based on One Decision Tree, but by an unanimous Prediction, made by ‘K’ Decision Trees.

Why should we use

There are four reasons why should we use the random forest algorithm. The one is that it can be used for both classification and regression businesses. Overfitting is one critical problem that may make the results worse, but for the Random Forest algorithm, if there are enough trees in the forest, the classifier won’t overfit the model. The third reason is the classifier of Random Forest can handle missing values, and the last advantage is that the Random Forest classifier can be modeled for categorical values.

How does the Random Forest algorithm work

There are two stages in the Random Forest algorithm, one is random forest creation, the other is to make a prediction from the random forest classifier created in the first stage. The whole process is shown below, and it’s easy to understand using the figure.

In the first stage, we will build the random forest:

  1. Randomly select “K” features from total “m” features where k << m
  2. Among the “K” features, calculate the node “d” using the best split point
  3. Split the node into daughter nodes using the best split
  4. Repeat the a to c steps until “l” number of nodes has been reached
  5. Build forest by repeating steps a to d for “n” number times to create “n” number of trees

In the next stage, with the random forest created, we will make the prediction. The random forest prediction pseudocode is shown below:

  1. Takes the test features and use the rules of each randomly created decision tree to predict the outcome and stores the predicted outcome (target)
  2. Calculate the votes for each predicted target
  3. Consider the high voted predicted target as the final prediction from the random forest algorithm

The process is easy to understand, but it’s somehow efficient.

Where should we use

The random forest can be used in the: Banking, Medicine, Stock Market and E-commerce:

  • For the application in banking, the Random Forest algorithm is used to find loyal customers.
  • For the application in medicine, the Random Forest algorithm can be used to both identify the correct combination of components in medicine.
  • For the application in the stock market, the Random Forest algorithm can be used to identify a stock’s behavior and the expected loss or profit.
  • For the application in e-commerce, the Random Forest algorithm can be used for predicting whether the customer will like the recommend products, based on the experience of similar customers.

Feel free to share your knowledge, suggestions, and opinions in the comments section below.

--

--