Compact a ClassificationPartitionedModel
8 次查看(过去 30 天)
显示 更早的评论
I'm training several cross fold validated classification models on the same input data. I want to save the trained models but each model redunantly saves a copy of the training data in addition to my out of band copy which makes the mat files unmangable.
I've tried
>>compact(trainedClassifers.ctree)
Undefined function 'compact' for input arguments of type 'classreg.learning.partition.ClassificationPartitionedModel'.
I've also tried
>>trainedClassifers.ctree.X = {}
You cannot set the read-only property 'X' of ClassificationPartitionedModel.
Error in classreg.learning.internal.DisallowVectorOps/subsasgn (line 34)
[varargout{1:nargout}] = builtin('subsasgn',this,s,data);
34 [varargout{1:nargout}] = builtin('subsasgn',this,s,data);
Is there some way I'm unaware of?
0 个评论
回答(1 个)
Omega
2025-5-13
Hi Christopher,
It looks like you're trying to save your trained classification models without including the redundant training data. Unfortunately, the "compact" function isn't available for "ClassificationPartitionedModel" objects, and the "X" property is read-only.
As a workaround, you can extract the trained models from the partitioned model and compact each of them individually. For example:
trainedModel = trainedClassifiers.ctree.Trained{1}; % Extract the trained model
compactModel = compact(trainedModel); % Compact the model
Now, "compactModel" contains a compacted version of your model, without the training data. Instead of saving the entire "ClassificationPartitionedModel", save the compacted models:
save('compactModel.mat', 'compactModel');
I hope it helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!