I have trained a random forest for binary classification via TreeBagger
:
Mdl = TreeBagger(trees, X1, y1, 'NumPredictorsToSample', features, ...
'OOBPrediction', 'on', 'Method', 'classification', 'OOBVarImp', 'on');
I am trying to return the error (misclassification probability) of the training set (X1
):
train_error = error(Mdl, X1, y1)
However, I receive this error message:
Function 'subsindex' is not defined for values of class 'TreeBagger'.
Note that I am not looking for the out-of-bag error; I have already obtained that without problem.
I'd bet real-world currency you named a variable error
, and MATLAB is trying to index that variable using Mdl
. However, Mdl
can't be used as an index since it doesn't have a subsindex
method defined, as the error message states. Type the following then retry your code:
clear error
You generally shouldn't give a variable the same name as an existing function (i.e. "shadowing"). The function precedence order documentation has this to say:
If you create a variable with the same name as a function, MATLAB cannot run that function until you clear the variable from memory.