I am using a RandomForest for multiclass classification. I would like to use the oob_decision_function to explore precision/recall, but I don't understand the OOB results.
I am using 25,000 trees (n_estimators=25000) and the possible class values are 0,1 or 2.
My results are (truncated to the first 10 rows):
y_train = [1 2 1 1 0 0 2 2 2 2]
y_pred = [2 2 2 1 0 2 2 2 2 2]
oob_decision_function:
[[ 0.25377529 0.28080796 0.46541674]
[ 0.32162915 0.3250808 0.35329005]
[ 0.34463485 0.27709584 0.3782693 ]
[ 0.31091392 0.2982096 0.39087648]
[ 0.34932553 0.28632762 0.36434685]
[ 0.31535905 0.19570567 0.48893528]
[ 0.25472683 0.35845451 0.38681866]
[ 0.32521156 0.31721116 0.35757728]
[ 0.30706625 0.32703203 0.36590172]
[ 0.29785305 0.22490485 0.4772421 ]]
The dataset is not uniform:
class 0: 32% of samples
class 1: 27% of samples
class 2: 41% of samples
The predictions don't seem to agree with the decision function. See for example the 4th sample: the prediction (y_pred[3]) is class 1, but the OOB values are 0.3109 (class 0), 0.2982 (class 1) and 0.3908 (class 2). Why is the prediction class 1 and not class 2? I thought after 25,000 trees the prediction should closely match the OOB probabilities, or am I not understanding OOB properly?
A few questions:
how are the OOB values calculated? I thought it was as follows: for each of the 25,000 trees it creates a new bagged training set. Let's say a given sample was not included (ie. out-of-bag) in 6000 of those trees. When the sample is out-of-bag, the current tree is used to predict the class for that sample. So for our given sample, it was estimated 6000 times and let's say the predictions were class 0 (1000 times), class 1 (2000 times) and class 2 (3000 times). Therefore the OOB values would be 1000/6000 (class 0), 2000/6000 (class 1) and 3000/6000 (class 2). Is this correct?
the OOB values are calculated using the results of the predictions from individual trees (as explained above), but the output predictions (ie. y_pred) are from the final ensemble of trees. Is this correct?
should the OOB values converge to the cross validation values as the number of trees increases? AFAIK k-fold cross validation splits the data into k subsets and uses the entire forest on each subset.
is there some sort of weighting being applied (e.g. if my data are not uniformly distributed)?