MATLAB: Do I receive “Undefined function or variable” error when calling the functions “predictorImportance” and “oobPermut​edPredicto​rImportanc​e”

oobpermutedpredictorimportancepredictorimportanceStatistics and Machine Learning Toolbox

I have Statistics and Machine Learning Toolbox installed. Why do I receive "Undefined function or variable" error message when calling the functions "predictorImportance" and "oobPermutedPredictorImportance" after MATLAB starts?

Best Answer

The function "predictorImportance" is a method of the "RegressionTree" class. When MATLAB starts, the "RegressionTree" classes are not loaded so the methods of these classes are not available at this point. Hence, one may get an error message like "Undefined function or variable" if he calls that function right after MATLAB starts. If a "RegressionTree" object is created (for example, by calling the function "fitrtree") before "predictorImportance" is executed, then running "predictorImportance" will not result in this type of error.
Similarly, the function "oobPermutedPredictorImportance" is a method of the "RegressionBaggedEnsemble" class. One needs to create a "RegressionBaggedEnsemble" object first before calling this function. One way to create such an object is to call the function "fitrensemble". Calling "oobPermutedPredictorImportance" without first creating a "RegressionBaggedEnsemble" object may result in this type of error.