Why does a "CompactRe​gressionEn​semble" Object Saved in MATLAB R2023b Cause Warnings When Loaded in MATLAB R2023a?

I've noticed an issue where a "CompactRegressionEnsemble" object, created and saved with MATLAB R2023b, is exhibiting numerous warnings and errors when it is loaded in MATLAB R2023a.
To reproduce this issue, I performed the following steps in MATLAB R2023b:
>> x = rand(1000,5);
>> y = rand(1000,1)<0.5;
>> tree = fitrensemble(x,double(y));
>> ok = compact(tree);
>> save('ok.mat','ok') 
Subsequently, the 'ok.mat' file was loaded in MATLAB R2023a, leading to the following warning:
>> load('ok.mat') 
Warning: While loading an object of class 'classreg.learning.regr.CompactRegressionTree': When constructing an instance of class 'classreg.learning.regr.CompactRegressionTree', the constructor must preserve the class of the returned object.

 Accepted Answer

You are attempting to load an object saved in MATLAB R2023b into MATLAB R2023a. It's important to note that this workflow is not officially supported. The reason being, there's no guarantee that the class definitions will remain unchanged in newer releases. Consequently, an object created and saved in MATLAB R2023b is not guaranteed to be loadable in an earlier release, such as MATLAB R2023a. Therefore, the warnings you are encountering are expected in this scenario.
However, in your specific case, these warnings appear to be harmless.
The Statistics and Machine Learning Toolbox is designed to be backward-compatible. This means that if you saved an object in MATLAB R2023a, it should work without any errors or warnings in a newer release, such as MATLAB R2023b. Please be aware that there may be very specific exceptions or limitations to this, which would be documented in the respective MATLAB documentation.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!