1

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.

gnovice
  • 125,304
  • 15
  • 256
  • 359
Thomas
  • 158
  • 9

1 Answers1

1

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.

gnovice
  • 125,304
  • 15
  • 256
  • 359
  • I think you were right. I had thought the same thing, and subsequently removed all items from the workspace but without much luck. However after restarting Matlab it worked. Many thanks! – Thomas Nov 21 '17 at 09:48