/


Imagine a set of machine learning algorithms that can achieve competitive results as its sophisticated counterparts without relying on a large cluster of GPU-accelerated machines, be match-winners at major data science competitions, and all of this without losing out on interpretability. Sounds ideal, doesn´t it?
Tree-based algorithms can empower predictive models with all the above-mentioned properties and are also widely used in various industries to provide productionised solutions.
Tree-based algorithms are supervised learning models that address classification or regression problems by constructing a tree-like structure to make predictions.
The underlying idea of these algorithms is simple: to come up with a series of if-else conditions to create decision boundaries and use an aggregation method (like mean or mode) on values in a decision region to predict the outcome – a target value in case of regression and a target class in case of classification. Tree-based algorithms can either produce a single tree or multiple trees based on the specific algorithm used.
The following are some of the key properties of tree-based learning that make it an important approach:
Some applications of tree-based algorithms are listed below:

As mentioned above, tree-based methods create decision regions based on if-else conditions on features by making orthogonal splits. But, how are these splitting conditions devised? Also, the process of creating decision regions could be carried out many times. How many times should we split our decision space?
These are the key components that need to be addressed while creating trees: which features to split on and at what value, and when to stop splitting.
To decide the feature split, different metrics are used to decide the best split in a top-down greedy manner i.e. the splitting begins from a state when all points belong to the same region and successive splits are made such that the resulting tree has a better metric value as compared to the previous tree. The following are some commonly used cost functions for different tasks:
1. For classification:
2. For regression:
An orthogonal split is made for a feature and a corresponding feature value that increases the information gain or reduces the residual sum of squares the most as compared to other potential splits. This process is then repeated to perform the next best split and so on.
Fig 2 shows the decision regions generated for a sample dataset.

As this splitting process is repeated, the tree keeps on growing and becomes more complex. At this point, the algorithm starts learning noise along with the signals present in the dataset. This results in overfitting i.e. the model becomes too specific to a dataset that it is trained on and can not generalize well on other unseen datasets. In order to avoid this situation, a technique called pruning is incorporated.
Pruning aims at getting rid of sections of the tree that have low predictive power. It can be done by limiting the maximum depth of the tree or by limiting the minimum number of samples per region.
Other pruning methods such as cost complexity pruning get rid of subtrees by updating the cost function with an additional term to penalise complex trees. A large tree is first grown using recursive splitting and cost complexity pruning is then applied to the large tree to find the best sequence of subtrees. This idea is similar to Lasso Regression, which regularizes the complexity of the model by penalizing weights.
Tree-based approaches can classify based on the number of trees used for prediction and the order in which they are produced. Some of the important methods are listed below:
1. Decision trees
2. Ensemble methods
Let’s deep dive into each of these methods.

Decision trees are tree-based structures that involve working with a single tree, using boolean conditions to form decision boundaries until a stopping condition is reached. These can be utilized for classification and regression tasks and hence are popularly termed as Classification and Regression Trees (CART).
Fig X showcases an example of a decision tree to determine type of contact lens to be worn by a person.
Decision trees work on the principle as described in the previous section. A brief algorithm below describes the steps to grow a decision tree. The algorithm is agnostic to the type of problem in hand (classification or regression):
Once the decision tree has been constructed, it can be used to evaluate new instance. The new instance is first placed in the corresponding decision region based on the tree logic and the aggregated measure of all the training target values (e.g. for classification: mode of class values, for regression: mean of outcome value) is predicted for the instance.
Advantages:
Disadvantages:
Due to their interpretability, decision trees have been utilised in wide range of applications:

Though pruning helps to avoid overfitting of decision trees, a single tree has limited predictive power. To address this, multiple decision trees can be built and finally their predictions can be combined to improve predictive power. This method of combining multiple trees to make predictions is called ensembling, which is based on an idea of wisdom of crowds – a crowd is wiser than an individual.
We would inspect some popular ensembling methods: Bagging (Bootstrap Aggregation), Random Forests and Boosting.
Bagging or Bootstrap Aggregation is a technique to construct multiple decision trees at a time, each trained using a subset of data. This data subset is obtained by randomly sampling instances with replacement also known as bootstrapping. Finally, the predictions obtained from all decision trees are aggregated to obtain a single prediction.
Bagging helps in reducing high variance observed while training a single decision tree. This is because aggregating multiple bootstrapped training datasets reduce variance.

The following are the steps to perform bagging:
To evaluate a new instance, the appropriate decision region in which the instance would lie is identified for each for the decision trees and an aggregation method on the training target values laying in the decision region is used to get predictions from each decision tree. Furthermore, another level of aggregation is used to combine individual predictions and make a collective prediction.
Advantages:
Disadvantages:
The following are some of the prominent applications where bagging has been used:
Random Forest build upon the Bootstrap Aggregation algorithm by involving an additional step to decorrelate the decision trees. Along with bootstrapping instances for each decision tree, Random Forest also chooses a subset of features from the feature set to train the decision tree.
By doing this it tends to lower down the correlation between decision trees. Since every decision tree uses all the features, a strong predictor would influence the way decision splits occur in most of the decision trees, making them look similar. Further, aggregation of correlated trees leads to lesser reduction in variance. This situation is avoided when a subset of features is considered for training different decision trees.

The following are the steps to implement Random Forest:
Advantages:
Disadvantages:
Random Forest has been utilised in the following applications:

Another ensemble approach to improve performance of a decision tree works on the idea of growing trees sequentially instead of parallelly, as we saw for Random Forests. This method is known as Boosting.
The fundamental idea behind boosting is to make trees learn from the errors committed by the predecessors and it does so by stacking tress in a sequential manner.
This overcomes one of the drawbacks observed in the Random Forest i.e. Random Forest does not reduce bias, and eventually improves the predictive accuracy.
There are different types of boosting approaches. Some of the popular ones include AdaBoost (Adapative Boosting), Gradient Boosting and XGBoost (Extreme Gradient Boosting). These methods differ in the way the net errors from the predecessor trees are addressed.

AdaBoost is mainly used for classification tasks. This method assigns weights to the training instances. In each iteration of training a decision tree, assess the performance of weak learner, identifies mis-classfied training instances and adjusts their weight such that the next decision trees pay more attention to correctly classify them. This process is repeated until the stopping condition is reached.
Gradient Boosting also works on the same principle as AdaBoost but differs in the way it operates on the “weakness” of the previous learners. Instead of adjusting the weights of training instances, it trains the successive decision trees on the residual error of the previous trees. This process is repeated until a stopping condition is reached. This method can be used for both classification and regression tasks.
XGBoost is an optimised version of Gradient Boosting that leverages distributed training using multiple CPU cores. This allows for training to occur in parallel and speeds up the computational process. It also includes regularization terms in the cost function which improves model generalization and addressed overfitting
Advantages:
Disadvantages:
Boosting has some major commercial applications, few of which are listed below:

Tree-based algorithms make an important addition to a data science toolkit. With their competitive predictive power, interpretability and ease of deployment, these methods have a wide application base in a variety of industries.
You might also like