How can I efficiently save a linear model?
9 views (last 30 days)
Show older comments
I have a large dataset (8000 x 287) that I want to use for linear regression. I am using the "fitlm()" function to train linear models with interactions. I need to train multiple models with datasets of the same size, and I want to save them for later usage. I saved the resulting linear model objects with save.
mdl = fitlm(...)
save('mdl.mat', 'mdl', '-v7.3')
Everything works but each model has a size of about 5.1 GB! Is there a more efficient way to save trained models? I only need the fitted polynomial for my predictions, so I don't understand why so much space is required to save a single model.
0 Comments
Answers (1)
RAJA SEKHAR BATTU
on 27 Oct 2022
Hi Bastian,
I think you already aware of regression. But I give you an Idea. Regression is the way of using variables(input) to fit a polynomial.
You can optimize and reduce the dataset to less variable say may be 287 to 20. For this you can use PCA.
Check some details about optimal fetaures.
If you reduce the dataset, Automatically the model reduces its memory after fitiing.
To save models, If you want to save multiple models for future use. You can use cell array to save the models with a loop for change of parameters.
I hope It is clear
4 Comments
RAJA SEKHAR BATTU
on 27 Oct 2022
@Bastian I think then only way to reduce the memory is to use Principal component analysis(PCA) or any feature reduction technique to reduce the features. The number of features to be reduced can be obtained by wrting a loop and checking the error(After PCA).
Please go through feature engineering for regression. You may get more information.
we cannot change the read only parameters because you can use that model 'mdl' for more multiple purposes.
Please find the more information about linear model regression in the following link
https://uk.mathworks.com/help/stats/fitlm.html
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!