MATLAB: How to save any trained machine learning model to use it for prediction later

machine learningmodel

Hi, I am using number of machine learning models which include inbuilt models in MATLAB like fitrsvm, fitrgp, fitrensemble etc. and some models using functions in external toolbox like 'dacefit.m' for kriging model etc.
Is there a common way to save my models which I have trained on a dataset, so that I could use the same trained models on different test data later?
If not, kindly help me with saving a trained fitrensemble (Regression Tree Ensemble) model so that I could just use it for predictions in future.
Thanks in advance!

Best Answer

The standard calling syntax, e.g.
Mdl = fitrensemble(Tbl,ResponseVarName);
stores everything you need in the model object named Mdl.
You can see in the first example in the documentation for fitrensemble how to then make predictions from the model.