LinearModel custom class questions

3 ビュー (過去 30 日間)
Brig
Brig 2012 年 11 月 9 日
回答済み: Leah 2013 年 9 月 26 日
I've been having issues with the LinearModel class. I want to create many different linear models on various subsets of predictors and observations. I would like to store all these models but don't want to have to re-store all of the observations used for each model (there are thousands of predictors for every observation).
If I have some data and create a model
ds = dataset({rand(5,1),'predictor'},{rand(5,1),'response'});
mdl = LinearModel.fit(ds);
I would like to be able to say
mdl.Variables = [];
but I get
Error using classreg.regr.FitObject/subsasgn (line 745)
The Variables property for class LinearModel is read-only.
It was suggested that I create my own class that inherits from LinearModel so I can change the permissions and store the model object sans variable info.
classdef customLinearModelClass< LinearModel
properties
end
methods
function clm= customLinearModelClass(linModel)
clm= clm@LinearModel;
end
end
end
but I get,
Error using customLinearModelClass
Class 'LinearModel' is Sealed and may not be used as a superclass.
And I could just copy all of the LinearModel code and create a new class that has the properties that I want but I would like to recreate a real LinearModel class if I want to. best case scenario I could do this.
customModel = magicFunction1(mdl);
mdl2 = magicFunction2(customModel);
where cutomModel does not contain all the Variable information and mdl and mdl2 are the same.
Any suggestions?

回答 (1 件)

Leah
Leah 2013 年 9 月 26 日
I think in order for you to have all the functionality of the class you need to keep the variable information. Can you just copy out the information you need from the class to a new structure? Like sometimes I'll just take out the coeff, Adjusted Rsq and pvals and ditch the md class

カテゴリ

Help Center および File ExchangeModel Building and Assessment についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by