如何从Matlab广义线性模型对象中删除训练数据集

问题描述:

我在使用

glm =  fitglm(Ttrain,...)

我想保留glm并将其传递出去,但是matlab还将训练数据(Ttrain-表)绑定到该对象.如果您有许多模型+庞大的训练数据集(您很容易用完内存),这可能会变得令人望而却步.但是做一些天真的事情,例如设置:

I want to keep glm and pass it around, but matlab also keeps the training data (Ttrain - a table) bound to the object. This can become prohibitive if you have many models + large training data sets (you can easily run out of memory). However doing something naive like setting:

glm.Variables= [];

给予

Error using classreg.regr.FitObject/subsasgn (line 753)
The Variables property for class GeneralizedLinearModel is read-only.

如何丢弃线性模型中的训练数据,但仍然能够使用调用glm.predict(...)的所有便利性和安全性? (我当然可以剔除回归系数,自己做预测逻辑,但我不愿意这样做)

How do I discard the training data from the linear model, but still be able to use all the convenience and safety of calling glm.predict(...)? (I could of course rip out the regression coefficients and do the predict logic myself, but I prefer not to)

恐怕我认为您不能做到这一点.

I don't think you can do this, I'm afraid.

对于大多数其他模型类型,例如RegressionTreeClassificationSVM等,存在一个伴随模型类,例如CompactRegressionTreeCompactClassificationSVM等,它们是相同的,但没有保留训练数据(并因此略有减少的诊断功能,但保留了预测能力).

For most other model types, such as RegressionTree, ClassificationSVM and so on, there is a companion model class such as CompactRegressionTree, CompactClassificationSVM and so on, that are the same but without retaining the training data (and slightly reduced diagnostic functionality because of that, but retaining the ability to predict).

直到现在我还没有意识到这一点,但是看起来LinearModelNonLinearModelGeneralizedLinearModel类没有这样的等效项.

I hadn't realized this until now, but it looks like the LinearModel, NonLinearModel and GeneralizedLinearModel classes don't have such an equivalent.

恐怕我想不出一个简单的解决方法.我会为此向MathWorks提出一项增强请求(登录您的MathWorks帐户并转到支持部分),因为我想不出为什么这样做会很困难的原因,它将使一套更一致的建议成为可能.功能.

I'm afraid I can't think of an easy workaround for that. I would put in an enhancement request to MathWorks for it (log into your MathWorks account and go to the support section), as I can't think of a reason why it would be difficult, and it would make for a more consistent set of functionality.

看起来MathWorks正在逐渐引入此功能.在R2016a中引入了CompactLinearModel,在R2016b中引入了CompactGeneralizedLinearModel.但是,从R2017a开始,仍然没有CompactNonLinearModel.

Looks like MathWorks are gradually introducing this functionality. CompactLinearModel was introduced in R2016a, and CompactGeneralizedLinearModel was introduced in R2016b. As of R2017a, however, there's still no CompactNonLinearModel.