Random Forest Machine Learning, We frequently utilize non-linear approaches to represent the link between a collection of predictor factors and a response variable when the relationship between them is extremely complex.

Classification and regression trees, often known as CART, are one such technique. These trees use a set of predictor variables to create decision trees that forecast the value of a response variable.

Best Books on Data Science with Python – Data Science Tutorials

An illustration of a regression tree that calculates a professional baseball player’s compensation based on years of experience and average home runs.

The advantage of decision trees is that they are simple to picture and understand. The drawback is that they frequently experience substantial variance.

To put it another way, if we divide a dataset in half and run a decision tree on each half, the outcomes may be very different.

The bagging technique, which operates as follows, is one strategy to lower the variance of decision trees.

1. Take b samples from the initial dataset that have been bootstrapped.

2. Create a decision tree for every sample that was bootstrapped.

3. To get a final model, average each tree’s projections.

5 Free Books to Learn Statistics For Data Science – Data Science Tutorials

The advantage of this strategy is that, as compared to a single decision tree, a bagged model often gives an improvement in test error rate.

The drawback is that, if there is a particularly potent predictor in the dataset, the predictions from the collection of bagged trees may be strongly correlated.

If this predictor is used for the initial split in the majority or all of the bagged trees, the resulting trees will be similar to one another and have highly associated predictions.

It is also probable that the final bagged model, which is created by averaging the predictions of each tree, does not significantly reduce variance when compared to a single decision tree.

Using the random forests technique is one approach to get around this problem.

Test for Normal Distribution in R-Quick Guide – Data Science Tutorials

## How Do Random Forests Work?

Random forests use b bootstrapped samples from an initial dataset, just like bagging.

However, only a random sample of m predictors—split candidates—from the entire set of p predictors are taken into account when creating a decision tree for each bootstrapped sample.

So, the complete process through which random forests create a model is as follows:

1. Take b samples from the initial dataset that have been bootstrapped.

2. Create a decision tree for every sample that was bootstrapped.

Only a random selection of m predictors—not the entire set of p predictors—are taken into account as split candidates for each split when the tree is being built.

3. To get a final model, average each tree’s projections.

When compared to trees made via bagging, the collection of trees in a random forest is decorrelated when using this method.

As a result, a final model that is created by averaging the predictions of each tree tends to be less variable and has a lower test error rate than a bagged model.

How to compare variances in R – Data Science Tutorials

Whenever we split a decision tree in a random forest, we normally take into account m = p predictors as split candidates.

We normally only examine m = 16 = 4 predictors as potential split candidates at each split, for instance, if p = 16 total predictors are present in the dataset.

### Technical Remark:

It’s interesting to notice that bagging is similar to choosing m = p, which means that we should examine all predictors as split candidates at each split.

#### Estimation of Out-of-Bag Error

We can use out-of-bag estimation to determine a random forest model’s test error in a manner similar to bagging.

It can be demonstrated that every bootstrapped sample includes roughly 2/3 of the data points from the original dataset. Out-of-bag (OOB) observations are the final third of the observations that weren’t used to fit the tree.

By taking the average prediction from each tree in which the ith observation was OOB, we can predict the value for the ith observation in the original dataset.

Using this method, we can anticipate each of the n observations in the original dataset and, as a result, determine an error rate, which is a reliable indicator of the test error.

How to draw heatmap in r: Quick and Easy way – Data Science Tutorials

This method for estimating test error has the advantage of being significantly faster than k-fold cross-validation, especially when the dataset is large.

##### Benefits and Drawbacks of Random Forests

There are several advantages of using random forests:

When compared to bagged models and, in particular, to lone decision trees, random forests will typically give an improvement in accuracy.

Random forests can withstand extreme cases.

Using random forests does not require any pre-processing.

However, the following possible downsides of random forests exist:

They are challenging to interpret.

Augmented Dickey-Fuller Test in R – Data Science Tutorials

They may take a long time to create huge datasets because of their computing requirements.

Random forests are frequently used in practice by data scientists to increase forecast accuracy, hence their difficulty in interpretation is usually not a problem.