El paquete randomForest en R de A. Liaw es un puerto del código original que es una mezcla de código c (traducido) de algún código fortran restante y código de envoltorio R. Para decidir la mejor división general entre puntos de ruptura y variables variables, el código utiliza una función de puntuación similar a la ganancia de gini:
GiniGain(N,X)=Gini(N)−|N1||N|Gini(N1)−|N2||N|Gini(N2)
Donde es un rasgo dado, N es el nodo en el que la división se va a realizar, y N 1 y N 2 son los dos nodos hijo creados por división N . El | . El | es el número de elementos en un nodo.XNN1N2N|.|
Y , donde K es el número de categorías en el nodoGini(N)=1−∑Kk=1p2kK
Gini(N) y | N | son constantes para todas las divisiones comparadas y, por lo tanto, se omiten.
|N2||N|Gini(N2)∝|N2|Gini(N2)=|N2|(1−∑Kk=1p2k)=|N2|∑nclass22,k|N2|2
where nclass1,k is the class count of target-class k in daughter node 1. Notice |N2| is placed both in nominator and denominator.
removing the trivial constant 1− from equation such that best split decision is to maximize nodes size weighted sum of squared class prevalence...
score=
|N1|∑Kk=1p21,k+|N2|∑Kk=1p22,k=|N1|∑Kk=1nclass21,k|N1|2+|N2|∑Kk=1nclass22,k|N2|2
=∑Kk=1nclass22,k1|N1|−1+∑Kk=1nclass22,k1|N1|−2
=nominator1/denominator1+nominator2/denominator2
The implementation also allows for classwise up/down weighting of samples. Also very important when the implementation update this modified gini-gain, moving a single sample from one node to the other is very efficient. The sample can be substracted from nominators/denominators of one node and added to the others.
I wrote a prototype-RF some months ago, ignorantly recomputing from scratch gini-gain for every break-point and that was slower :)
If several splits scores are best, a random winner is picked.
This answer was based on inspecting source file "randomForest.x.x.tar.gz/src/classTree.c" line 209-250