Apache Mahout > Mahout Wiki > Algorithms > Random Forests |
source : [3]
LearnUnprunedTree(X,Y)
Input: X a matrix of R rows and M columns where Xij = the value of the j'th attribute in the i'th input datapoint. Each column consists of either all real values or all categorical values.
Input: Y a vector of R elements, where Yi = the output class of the i'th datapoint. The Yi values are categorical.
Output: An Unpruned decision tree
If all records in X have identical values in all their attributes (this includes the case where R<2), return a Leaf Node predicting the majority output, breaking ties randomly. This case also includes
If all values in Y are the same, return a Leaf Node predicting this value as the output
Else
select m variables at random out of the M variables
For j = 1 .. m
If j'th attribute is categorical
IGj = IG(Y|Xj) (see Information Gain)
Else (j'th attribute is real-valued)
IGj = IG*(Y|Xj) (see Information Gain)
Let j* = argmaxj IGj (this is the splitting attribute we'll use)
If j* is categorical then
For each value v of the j'th attribute
Let Xv = subset of rows of X in which Xij = v. Let Yv = corresponding subset of Y
Let Childv = LearnUnprunedTree(Xv,Yv)
Return a decision tree node, splitting on j'th attribute. The number of children equals the number of values of the j'th attribute, and the v'th child is Childv
Else j* is real-valued and let t be the best split threshold
Let XLO = subset of rows of X in which Xij <= t. Let YLO = corresponding subset of Y
Let ChildLO = LearnUnprunedTree(XLO,YLO)
Let XHI = subset of rows of X in which Xij > t. Let YHI = corresponding subset of Y
Let ChildHI = LearnUnprunedTree(XHI,YHI)
Return a decision tree node, splitting on j'th attribute. It has two children corresponding to whether the j'th attribute is above or below the given threshold.
Note: There are alternatives to Information Gain for splitting nodes
source : [3]
suppose X can have one of m values V1,V2,...,Vm
P(X=V1)=p1, P(X=V2)=p2,...,P(X=Vm)=pm
H(X)= -sumj=1m pj log2 pj (The entropy of X)
H(Y|X=v) = the entropy of Y among only those records in which X has value v
H(Y|X) = sumj pj H(Y|X=vj)
IG(Y|X) = H(Y) - H(Y|X)
suppose X is real valued
define IG(Y|X:t) as H(Y) - H(Y|X:t)
define H(Y|X:t) = H(Y|X<t) P(X<t) + H(Y|X>=t) P(X>=t)
define IG*(Y|X) = maxt IG(Y|X:t)
source : [1]
Each tree is grown as follows:
source : [2]
Random Forests are easy to use, the only 2 parameters a user of the technique has to determine are the number of trees to be used and the number of variables (m) to be randomly selected from the available set of variables.
Breinman's recommendations are to pick a large number of trees, as well as the square root of the number of variables for m.
Classify(node,V)
Input: node from the decision tree, if node.attribute = j then the split is done on the j'th attribute
Input: V a vector of M columns where Vj = the value of the j'th attribute.
Output: label of V
If node is a Leaf then
Return the value predicted by node
Else
Let j = node.attribute
If j is categorical then
Let v = Vj
Let childv = child node corresponding to the attribute's value v
Return Classify(childv,V)
Else j is real-valued
Let t = node.threshold (split threshold)
If Vj < t then
Let childLO = child node corresponding to (<t)
Return Classify(childLO,V)
Else
Let childHI = child node corresponding to (>=t)
Return Classify(childHI,V)
source : [1]
in random forests, there is no need for cross-validation or a separate test set to get an unbiased estimate of the test set error. It is estimated internally, during the run, as follows:
source : [1]
[1] Random Forests - Classification Description
http://www.stat.berkeley.edu/~breiman/RandomForests/cc_home.htm
[2] B. Larivière & D. Van Den Poel, 2004. "Predicting Customer Retention and Profitability by Using Random Forests and Regression Forests Techniques,"
Working Papers of Faculty of Economics and Business Administration, Ghent University, Belgium 04/282, Ghent University,
Faculty of Economics and Business Administration.
Available online : http://ideas.repec.org/p/rug/rugwps/04-282.html
[3] Decision Trees - Andrew W. Moore[4]
http://www.cs.cmu.edu/~awm/tutorials[1\]
[4] Information Gain - Andrew W. Moore
http://www.cs.cmu.edu/~awm/tutorials