# AI News, Machine Learning FAQ

- On Thursday, June 7, 2018
- By Read More

## Machine Learning FAQ

Index Let’s assume we use a decision tree algorithms as base classifier for all three: boosting, bagging, and (obviously :)) the random forest.

The challenge of individual, unpruned decision trees is that the hypothesis often ends up being too complex for the underlying training data – decision trees are prone to overfitting.

E.g., if our training set consists of 7 training samples, our bootstrap samples (here: n=7) can look as follows, where C1, C2, … Cm shall symbolize the decision tree classifiers:

In contrast to bagging, you use very simple classifiers as base classifiers, so-called “weak learners.” Picture these weak learners as “decision tree stumps” – decision trees with only 1 splitting rule.

Due to the random feature selection, the trees are more independent of each other compared to regular bagging, which often results in better predictive performance (due to better variance-bias trade-offs), and I’d say that it’s also faster than bagging, because each tree learns only from a subset of features.

- On Monday, June 18, 2018
- By Read More

## Random forest

Random forests or random decision forests are an ensemble learning method for classification, regression and other tasks, that operate by constructing a multitude of decision trees at training time and outputting the class that is the mode of the classes (classification) or mean prediction (regression) of the individual trees.[1][2] Random decision forests correct for decision trees' habit of overfitting to their training set.[3]:587–588 The first algorithm for random decision forests was created by Tin Kam Ho[1] using the random subspace method,[2] which, in Ho's formulation, is a way to implement the 'stochastic discrimination' approach to classification proposed by Eugene Kleinberg.[4][5][6] An extension of the algorithm was developed by Leo Breiman[7] and Adele Cutler,[8] and 'Random Forests' is their trademark.[9] The extension combines Breiman's 'bagging' idea and random selection of features, introduced first by Ho[1] and later independently by Amit and Geman[10] in order to construct a collection of decision trees with controlled variance.

The general method of random decision forests was first proposed by Ho in 1995,[1] who established that forests of trees splitting with oblique hyperplanes, if randomly restricted to be sensitive to only selected feature dimensions, can gain accuracy as they grow without suffering from overtraining.

A subsequent work along the same lines[2] concluded that other splitting methods, as long as they are randomly forced to be insensitive to some feature dimensions, behave similarly.

Note that this observation of a more complex classifier (a larger forest) getting more accurate nearly monotonically is in sharp contrast to the common belief that the complexity of a classifier can only grow to a certain level of accuracy before being hurt by overfitting.

The explanation of the forest method's resistance to overtraining can be found in Kleinberg's theory of stochastic discrimination.[4][5][6] The early development of Breiman's notion of random forests was influenced by the work of Amit and Geman[10] who introduced the idea of searching over a random subset of the available decisions when splitting a node, in the context of growing a single tree.

The idea of random subspace selection from Ho[2] was also influential in the design of random forests.

In this method a forest of trees is grown, and variation among the trees is introduced by projecting the training data into a randomly chosen subspace before fitting each tree or each node.

Finally, the idea of randomized node optimization, where the decision at each node is selected by a randomized procedure, rather than a deterministic optimization was first introduced by Dietterich.[11] The introduction of random forests proper was first made in a paper by Leo Breiman.[7] This paper describes a method of building a forest of uncorrelated trees using a CART like procedure, combined with randomized node optimization and bagging.

In addition, this paper combines several ingredients, some previously known and some novel, which form the basis of the modern practice of random forests, in particular: The report also offers the first theoretical result for random forests in the form of a bound on the generalization error which depends on the strength of the trees in the forest and their correlation.

Decision trees are a popular method for various machine learning tasks.

Tree learning 'come[s] closest to meeting the requirements for serving as an off-the-shelf procedure for data mining', say Hastie et al., 'because it is invariant under scaling and various other transformations of feature values, is robust to inclusion of irrelevant features, and produces inspectable models.

However, they are seldom accurate'.[3]:352 In particular, trees that are grown very deep tend to learn highly irregular patterns: they overfit their training sets, i.e.

have low bias, but very high variance.

Random forests are a way of averaging multiple deep decision trees, trained on different parts of the same training set, with the goal of reducing the variance.[3]:587–588 This comes at the expense of a small increase in the bias and some loss of interpretability, but generally greatly boosts the performance in the final model.

The training algorithm for random forests applies the general technique of bootstrap aggregating, or bagging, to tree learners.

Given a training set X = x1, ..., xn with responses Y = y1, ..., yn, bagging repeatedly (B times) selects a random sample with replacement of the training set and fits trees to these samples: After training, predictions for unseen samples x' can be made by averaging the predictions from all the individual regression trees on x': or by taking the majority vote in the case of classification trees.

This bootstrapping procedure leads to better model performance because it decreases the variance of the model, without increasing the bias.

This means that while the predictions of a single tree are highly sensitive to noise in its training set, the average of many trees is not, as long as the trees are not correlated.

Simply training many trees on a single training set would give strongly correlated trees (or even the same tree many times, if the training algorithm is deterministic);

bootstrap sampling is a way of de-correlating the trees by showing them different training sets.

Additionally, an estimate of the uncertainty of the prediction can be made as the standard deviation of the predictions from all the individual regression trees on x': The number of samples/trees, B, is a free parameter.

Typically, a few hundred to several thousand trees are used, depending on the size and nature of the training set.

An optimal number of trees B can be found using cross-validation, or by observing the out-of-bag error: the mean prediction error on each training sample xᵢ, using only the trees that did not have xᵢ in their bootstrap sample.[12] The training and test error tend to level off after some number of trees have been fit.

The above procedure describes the original bagging algorithm for trees.

Random forests differ in only one way from this general scheme: they use a modified tree learning algorithm that selects, at each candidate split in the learning process, a random subset of the features.

This process is sometimes called 'feature bagging'.

The reason for doing this is the correlation of the trees in an ordinary bootstrap sample: if one or a few features are very strong predictors for the response variable (target output), these features will be selected in many of the B trees, causing them to become correlated.

An analysis of how bagging and random subspace projection contribute to accuracy gains under different conditions is given by Ho.[13] Typically, for a classification problem with p features, √p (rounded down) features are used in each split.[3]:592 For regression problems the inventors recommend p/3 (rounded down) with a minimum node size of 5 as the default.[3]:592 Adding one further step of randomization yields extremely randomized trees, or ExtraTrees.

These are trained using bagging and the random subspace method, like in an ordinary random forest, but additionally the top-down splitting in the tree learner is randomized.

Instead of computing the locally optimal feature/split combination (based on, e.g., information gain or the Gini impurity), for each feature under consideration, a random value is selected for the split.

This value is selected from the feature's empirical range (in the tree's training set, i.e., the bootstrap sample).[14] Random forests can be used to rank the importance of variables in a regression or classification problem in a natural way.

The following technique was described in Breiman's original paper[7] and is implemented in the R package randomForest.[8] The first step in measuring the variable importance in a data set

n

=

{

(

i

,

i

)

}

i

=

1

n

{\displaystyle {\mathcal {D}}_{n}=\{(X_{i},Y_{i})\}_{i=1}^{n}}

is to fit a random forest to the data.

During the fitting process the out-of-bag error for each data point is recorded and averaged over the forest (errors on an independent test set can be substituted if bagging is not used during training).

To measure the importance of the

j

{\displaystyle j}

-th feature after training, the values of the

j

{\displaystyle j}

-th feature are permuted among the training data and the out-of-bag error is again computed on this perturbed data set.

The importance score for the

j

{\displaystyle j}

-th feature is computed by averaging the difference in out-of-bag error before and after the permutation over all trees.

The score is normalized by the standard deviation of these differences.

Features which produce large values for this score are ranked as more important than features which produce small values.

The statistical definition of the variable importance measure was given and analyzed by Zhu et al.[15] This method of determining variable importance has some drawbacks.

For data including categorical variables with different number of levels, random forests are biased in favor of those attributes with more levels.

Methods such as partial permutations[16][17] and growing unbiased trees[18][19]can be used to solve the problem.

If the data contain groups of correlated features of similar relevance for the output, then smaller groups are favored over larger groups.[20] A

relationship between random forests and the k-nearest neighbor algorithm (k-NN) was pointed out by Lin and Jeon in 2002.[21] It turns out that both can be viewed as so-called weighted neighborhoods schemes.

These are models built from a training set

{

(

x

i

,

y

i

)

}

i

=

1

n

{\displaystyle \{(x_{i},y_{i})\}_{i=1}^{n}}

that make predictions

y

{\displaystyle {\hat {y}}}

for new points x' by looking at the 'neighborhood' of the point, formalized by a weight function W: Here,

(

x

i

,

x

′

)

{\displaystyle W(x_{i},x')}

is the non-negative weight of the i'th training point relative to the new point x' in the same tree.

For any particular x', the weights for points

x

i

{\displaystyle x_{i}}

must sum to one.

Weight functions are given as follows: Since a forest averages the predictions of a set of m trees with individual weight functions

j

{\displaystyle W_{j}}

,

its predictions are This shows that the whole forest is again a weighted neighborhood scheme, with weights that average those of the individual trees.

The neighbors of x' in this interpretation are the points

x

i

{\displaystyle x_{i}}

sharing the same leaf in any tree

j

{\displaystyle j}

.

In this way, the neighborhood of x' depends in a complex way on the structure of the trees, and thus on the structure of the training set.

Lin and Jeon show that the shape of the neighborhood used by a random forest adapts to the local importance of each feature.[21] As part of their construction, random forest predictors naturally lead to a dissimilarity measure among the observations.

One can also define a random forest dissimilarity measure between unlabeled data: the idea is to construct a random forest predictor that distinguishes the “observed” data from suitably generated synthetic data.[7][22] The observed data are the original unlabeled data and the synthetic data are drawn from a reference distribution.

A random forest dissimilarity can be attractive because it handles mixed variable types very well, is invariant to monotonic transformations of the input variables, and is robust to outlying observations.

The random forest dissimilarity easily deals with a large number of semi-continuous variables due to its intrinsic variable selection;

for example, the 'Addcl 1' random forest dissimilarity weighs the contribution of each variable according to how dependent it is on other variables.

The random forest dissimilarity has been used in a variety of applications, e.g.

to find clusters of patients based on tissue marker data.[23] Instead of decision trees, linear models have been proposed and evaluated as base estimators in random forests, in particular multinomial logistic regression and naive Bayes classifiers.[24][25] In machine learning, kernel random forests establish the connection between random forests and kernel methods.

By slightly modifying their definition, random forests can be rewritten as kernel methods, which are more interpretable and easier to analyze.[26] Leo Breiman[27] was the first person to notice the link between random forest and kernel methods.

He pointed out that random forests which are grown using i.i.d.

random vectors in the tree construction are equivalent to a kernel acting on the true margin.

Lin and Jeon[28] established the connection between random forests and adaptive nearest neighbor, implying that random forests can be seen as adaptive kernel estimates.

Davies and Ghahramani[29] proposed Random Forest Kernel and show that it can empirically outperform state-of-art kernel methods.

Scornet[26] first defined KeRF estimates and gave the explicit link between KeRF estimates and random forest.

He also gave explicit expressions for kernels based on centered random forest[30] and uniform random forest,[31] two simplified models of random forest.

He named these two KeRFs Centered KeRF and Uniform KeRF, and proved upper bounds on their rates of consistency.

Centered forest[30] is a simplified model for Breiman's original random forest, which uniformly selects an attribute among all attributes and performs splits at the center of the cell along the pre-chosen attribute.

The algorithm stops when a fully binary tree of level

k

{\displaystyle k}

is built, where

k

∈

{\displaystyle k\in \mathbb {N} }

is a parameter of the algorithm.

Uniform forest[31] is another simplified model for Breiman's original random forest, which uniformly selects a feature among all features and performs splits at a point uniformly drawn on the side of the cell, along the preselected feature.

Given a training sample

n

=

{

(

i

,

i

)

}

i

=

1

n

{\displaystyle {\mathcal {D}}_{n}=\{(\mathbf {X} _{i},Y_{i})\}_{i=1}^{n}}

of

[

0

,

1

]

p

{\displaystyle [0,1]^{p}\times \mathbb {R} }

-valued independent random variables distributed as the independent prototype pair

(

,

)

{\displaystyle (\mathbf {X} ,Y)}

,

where

⁡

[

2

]

<

{\displaystyle \operatorname {E} [Y^{2}]<\infty }

.

We aim at predicting the response

{\displaystyle Y}

,

associated with the random variable

{\displaystyle \mathbf {X} }

,

by estimating the regression function

m

(

x

)

=

⁡

[

∣

=

x

]

{\displaystyle m(\mathbf {x} )=\operatorname {E} [Y\mid \mathbf {X} =\mathbf {x} ]}

.

A random regression forest is an ensemble of

{\displaystyle M}

randomized regression trees.

Denote

m

n

{\displaystyle m_{n}(\mathbf {x} ,\mathbf {\Theta } _{j})}

the predicted value at point

{\displaystyle \mathbf {x} }

{\displaystyle j}

-th tree, where

{\displaystyle \mathbf {\Theta } _{1},\ldots ,\mathbf {\Theta } _{M}}

are independent random variables, distributed as a generic random variable

{\displaystyle \mathbf {\Theta } }

independent of the sample

{\displaystyle {\mathcal {D}}_{n}}

This random variable can be used to describe the randomness induced by node splitting and the sampling procedure for tree construction.

The trees are combined to form the finite forest estimate

{\displaystyle m_{M,n}(\mathbf {x} ,\Theta _{1},\ldots ,\Theta _{M})={\frac {1}{M}}\sum _{j=1}^{M}m_{n}(\mathbf {x} ,\Theta _{j})}

For regression trees, we have

{\displaystyle m_{n}=\sum _{i=1}^{n}{\frac {Y_{i}\mathbf {1} _{\mathbf {X} _{i}\in A_{n}(\mathbf {x} ,\Theta _{j})}}{N_{n}(\mathbf {x} ,\Theta _{j})}}}

{\displaystyle A_{n}(\mathbf {x} ,\Theta _{j})}

is the cell containing

{\displaystyle \mathbf {x} }

designed with randomness

{\displaystyle \Theta _{j}}

and dataset

{\displaystyle {\mathcal {D}}_{n}}

{\displaystyle N_{n}(\mathbf {x} ,\Theta _{j})=\sum _{i=1}^{n}\mathbf {1} _{\mathbf {X} _{i}\in A_{n}(\mathbf {x} ,\Theta _{j})}}

Thus random forest estimates satisfy, for all

{\displaystyle \mathbf {x} \in [0,1]^{d}}

{\displaystyle m_{M,n}(\mathbf {x} ,\Theta _{1},\ldots ,\Theta _{M})={\frac {1}{M}}\sum _{j=1}^{M}\left(\sum _{i=1}^{n}{\frac {Y_{i}\mathbf {1} _{\mathbf {X} _{i}\in A_{n}(\mathbf {x} ,\Theta _{j})}}{N_{n}(\mathbf {x} ,\Theta _{j})}}\right)}

Random regression forest has two level of averaging, first over the samples in the target cell of a tree, then over all trees.

Thus the contributions of observations that are in cells with a high density of data points are smaller than that of observations which belong to less populated cells.

In order to improve the random forest methods and compensate the misestimation, Scornet[26] defined KeRF by which is equal to the mean of the

's falling in the cells containing

{\displaystyle \mathbf {x} }

If we define the connection function of the

finite forest as

{\displaystyle K_{M,n}(\mathbf {x} ,\mathbf {z} )={\frac {1}{M}}\sum _{j=1}^{M}\mathbf {1} _{\mathbf {z} \in A_{n}(\mathbf {x} ,\Theta _{j})}}

the proportion of cells shared between

{\displaystyle \mathbf {x} }

{\displaystyle \mathbf {z} }

then almost surely we have

{\displaystyle {\tilde {m}}_{M,n}(\mathbf {x} ,\Theta _{1},\ldots ,\Theta _{M})={\frac {\sum _{i=1}^{n}Y_{i}K_{M,n}(\mathbf {x} ,\mathbf {x} _{i})}{\sum _{\ell =1}^{n}K_{M,n}(\mathbf {x} ,\mathbf {x} _{\ell })}}}

The construction of Centered KeRF of level

{\displaystyle k}

is the same as for centered forest, except that predictions are made by

{\displaystyle {\tilde {m}}_{M,n}(\mathbf {x} ,\Theta _{1},\ldots ,\Theta _{M})}

the corresponding kernel function, or connection function is Uniform KeRF is built in the same way as uniform forest, except that predictions are made by

{\displaystyle {\tilde {m}}_{M,n}(\mathbf {x} ,\Theta _{1},\ldots ,\Theta _{M})}

the corresponding kernel function, or connection function is Predictions given by KeRF and random forests are close if the number of points in each cell is controlled: Assume that there exist sequences

{\displaystyle (a_{n}),(b_{n})}

such that, almost surely, Then almost surely, When the number of trees

goes to infinity, then we have infinite random forest and infinite KeRF.

Their estimates are close if the number of observations in each cell is bounded: Assume that there exist sequences

{\displaystyle (\varepsilon _{n}),(a_{n}),(b_{n})}

such that, almost surely Then almost surely, Assume that

{\displaystyle Y=m(\mathbf {X} )+\varepsilon }

{\displaystyle \varepsilon }

is a centered Gaussian noise, independent of

{\displaystyle \mathbf {X} }

with finite variance

{\displaystyle \sigma ^{2}<\infty }

{\displaystyle \mathbf {X} }

is uniformly distributed on

{\displaystyle [0,1]^{d}}

{\displaystyle m}

Scornet[26] proved upper bounds on the rates of consistency for centered KeRF and uniform KeRF.

{\displaystyle k\rightarrow \infty }

{\displaystyle n/2^{k}\rightarrow \infty }

there exists a constant

{\displaystyle n}

{\displaystyle \mathbb {E} [{\tilde {m}}_{n}^{cc}(\mathbf {X} )-m(\mathbf {X} )]^{2}\leq C_{1}n^{-1/(3+d\log 2)}(\log n)^{2}}

{\displaystyle k\rightarrow \infty }

{\displaystyle n/2^{k}\rightarrow \infty }

there exists a constant

{\displaystyle \mathbb {E} [{\tilde {m}}_{n}^{uf}(\mathbf {X} )-m(\mathbf {X} )]^{2}\leq Cn^{-2/(6+3d\log 2)}(\log n)^{2}}

The algorithm is often used in scientific works because of its advantages.

For example, it can be used for quality assessment of Wikipedia articles[32][33][34].

- On Monday, June 18, 2018
- By Read More

## Bagging and Random Forest Ensemble Algorithms for Machine Learning

We can calculate the mean directly from the sample as: mean(x) = 1/100 * sum(x) We know that our sample is small and that our mean has error in it.

We can improve the estimate of our mean using the bootstrap procedure: For example, let’s say we used 3 resamples and got the mean values 2.3, 4.5 and 3.3.

This process can be used to estimate other quantities like the standard deviation and even quantities used in machine learning algorithms, like learned coefficients.

An ensemble method is a technique that combines the predictions from multiple machine learning algorithms together to make more accurate predictions than any individual model.

For example, if we had 5 bagged decision trees that made the following class predictions for a in input sample: blue, blue, red, blue and red, we would take the most frequent class and predict blue.

This can be chosen by increasing the number of trees on run after run until the accuracy begins to stop showing improvement (e.g.

Combining predictions from multiple models in ensembles works better if the predictions from the sub-models are uncorrelated or at best weakly correlated.

In CART, when selecting a split point, the learning algorithm is allowed to look through all variables and all variable values in order to select the most optimal split-point.

The random forest algorithm changes this procedure so that the learning algorithm is limited to a random sample of features of which to search.

Where m is the number of randomly selected features that can be searched at a split point and p is the number of input variables.

For example, if a dataset had 25 input variables for a classification problem, then: For each bootstrap sample taken from the training data, there will be samples left behind that were not included.

These drops in error can be averaged across all decision trees and output to provide an estimate of the importance of each input variable.

These outputs can help identify subsets of input variables that may be most or least relevant to the problem and suggest at possible feature selection experiments you could perform where some features are removed from the dataset.

- On Monday, June 18, 2018
- By Read More

## Decision Tree Ensembles- Bagging and Boosting

We all use Decision Tree technique on daily basis to plan our life, we just don’t give a fancy name to those decision-making process.

Ensemble methods, which combines several decision trees to produce better predictive performance than utilizing a single decision tree.

The main principle behind the ensemble model is that a group of weak learners come together to form a strong learner.

It takes one extra step where in addition to taking the random subset of data, it also takes the random selection of features rather than using all features to grow trees.

A subset of M features are selected randomly and whichever feature gives the best split is used to split the node iteratively.

- On Friday, March 22, 2019

**Bootstrap aggregating bagging**

This video is part of the Udacity course "Machine Learning for Trading". Watch the full course at

**Random Forest - Fun and Easy Machine Learning**

Random Forest - Fun and Easy Machine Learning

**Bagging & Boosting Algorithms | Decision Tree | Data Science**

In this video you will learn about theory behind bootstrap method of building decision tree and combining them for better prediction.. This type of algorithms are ...

**How Random Forest algorithm works**

In this video I explain very briefly how the Random Forest algorithm works with a simple example composed by 4 decision trees.

**Random Forests - The Math of Intelligence (Week 6)**

Only a few days left to signup for my Decentralized Applications course! This is one of the most used machine learning models ever

**Gini index based Decision Tree**

Hi, A small video demonstrating how a split is made in a Decision tree based on Gini Index.

**CS 155 Lecture 5: Decision Trees, Bagging, Random Forests**

**Decision Trees vs Ramdom Forest R Demo**

Video compares the performance of Random Forest vs Decision Trees. The sample code is based on R The video builds on top of previous videos a) Random ...

**Data Science - Part V - Decision Trees & Random Forests**

For downloadable versions of these lectures, please go to the following link: This lecture provides an ..

**R Tutorial 22: Decision Tree, Random Forest, Bagging, and Boosting**

This video is going to talk about Decision Tree, Random Forest, Bagging and Boosting methods. Decision tree is good at interpreting the result, but it is more ...