loadCompactModel
从保存模型中重建紧凑型分类或回归模型,以生成代码
要生成用于分类或回归的C代码,您必须有一个MATLAB®CODER™license.
Syntax
compactmdl = loadCompactmodel(文件名)
描述
重建紧凑的分类或回归模型CompactMdl
= loadCompactModel(filename
)CompactMdl
from the saved model stored in the MATLAB formatted binary file (MAT-file)filename
。你必须创建filename
usingSaveCompactModel
。
例子
Load Compact SVM Model from Structure Array
加载电离层
data set.
load电离层
Train an SVM classification model using the entire data set. Specify to standardize the data.
MDL= fitcsvm(X,Y,“标准化”,真正的)
MDL= ClassificationSVM ResponseName: 'Y' CategoricalPredictors: [] ClassNames: {'b' 'g'} ScoreTransform: 'none' NumObservations: 351 Alpha: [90×1 double] Bias: -0.1343 KernelParameters: [1×1 struct] Mu: [1×34 double] Sigma: [1×34 double] BoxConstraints: [351×1 double] ConvergenceInfo: [1×1 struct] IsSupportVector: [351×1 logical] Solver: 'SMO'
MDL
is a分类vm
model.
将SVM分类模型保存到文件'SVMIonosphere.mat'
。
SaveCompactModel(Mdl,'SVMIonosphere');
'SVMIonosphere.mat'
出现在您目前的工作目录中。SaveCompactModel
通过删除预测不需要的属性(例如训练数据)来减少模型的内存足迹。然后,SaveCompactModel
保存一个特征的结构数组MDL
在'SVMIonosphere.mat'
。
加载structure array in'SVMIonosphere.mat'
to the Workspace.
compactmdl = loadcompactmodel('SVMIonosphere')
CompactMdl = classreg.learning.classif.CompactClassificationSVM ResponseName: 'Y' CategoricalPredictors: [] ClassNames: {'b' 'g'} ScoreTransform: 'none' Alpha: [90×1 double] Bias: -0.1343 KernelParameters: [1×1 struct] Mu: [1×34 double] Sigma: [1×34 double] SupportVectors: [90×34 double] SupportVectorLabels: [90×1 double]
CompactMdl
is acompactClassificationvm
设备进行预测的模型。
从函数中生成代码,该函数对新数据进行分类
Declare a function that classifies new observations using a trained classification model. This example requires a MATLAB® Coder™ license.
加载Fisher的虹膜数据集。
load渔业
培训由SVM二进制学习者组成的ECOC模型。使用SVM模板,标准化数据,保留30%的培训数据,并指定高斯内核。
t = templatesvm(“标准化”,true,'kernelfunction','gaussian');CVMDL= fitcecoc(meas,species,“学习者”,t,'Holdout',0.30);
CVMDL
is a分类部门
存储等的模型:
A compact ECOC model, which
fitcecoc
trained using the training set.数据分区对象,指定如何
fitcecoc
randomly split the data into training and holdout sets.
Extract the compact ECOC classification model and the holdout set indices using dot notation. Identify the holdout observations.
compactmdl = cvmdl.Trained {1};cvp = cvmdl.partition;idxtest = test(CVP);MEATHO = MEAS(IDXTEST,:);
CompactMdl
is aCompactClassificationECOC
model equipped to classify new observations.
Save the compact ECOC classification model to the fileECOCIris.mat
。
SaveCompactModel(CompactMdl,'ecociris');
Declare a function in your current working folder called分类
那:
Accepts iris-flower measurements commensurate with
测量
并返回预测标签加载紧凑的ECOC分类模型
Passes the loaded model and iris-flower measurements to
预测
功能label = classifyIrises(X)%#codegen百分比使用ECOC模型对虹膜物种进行分类% CLASSIFYIRISES classifies the iris-flower measurements in X%在文件ecociris.mat中使用紧凑型ECOC模型,然后% returns class labels in label.compactmdl = loadcompactmodel('ecociris');label = predition(compactmdl,x);end
The%#codegen
compilation directive indicates that the MATLAB® code is intended for code generation.
Generate a MEX function from分类
。Because C uses static typing,codegen
must determine the properties of all variables in MATLAB® files at compile time. To ensure that the MEX function can use the same input, specify the holdout observations as arguments to the function using the'-args'
选项。
codegen分类-args{measHO}
MEX文件classifyiries_mex.mexw64
生成您当前的工作目录。文件扩展名取决于您的平台。
Compare labels predicted using预测
at the command line,分类
, 和classifyIrises_mex
。
label1 = predition(compactmdl,measho);label2 = classifyirise(measho);label3 = classifyirises_mex(meadho);comp12 = cellfun(@strcmp,label1,label2);Comp23 = CellFun(@strcmp,label2,label3);class12 = sum(comp12)== numel(label1)colle23 = sum(comp23)== numel(label1)
agree12 = logical 1 agree23 = logical 1
标签预测所有三种方式都是相同的。
输入参数
filename
— MAT-file name containing structure array representing compact classification or regression model
角色向量
MAT文件名称包含代表紧凑型分类或回归模型的结构数组,该模型指定为字符向量。你必须创建filename
usingSaveCompactModel
。
loadCompactModel
重建紧凑的分类或回归模型stored infilename
在编译时。有关支持金宝app的紧凑分类或回归模型,请参见MDL
输入参数。
如果filename
没有扩展名(即,没有延期的时间),然后loadCompactModel
appends。mat
。
如果filename
does not include a full path, thenloadCompactModel
loads from the present working directory.
例子:'CompactMdl'
Output Arguments
CompactMdl
- 紧凑分类或回归模型
分类线
compact model object |CompactClassificationECOC
模型对象|紧凑型classificationEnsemble
模型对象|compactClassificationvm
模型对象|compactClassificationTree
模型对象|紧凑型地线模型
模型对象|CompactLinearModel
模型对象|CompactregressionTree
模型对象|...
Compact classification or regression model, returned as分类线
,CompactClassificationECOC
,紧凑型classificationEnsemble
,compactClassificationvm
,compactClassificationTree
,CompactLinearModel
,紧凑型地线模型
,或CompactregressionTree
model object.
CompactMdl
必须是一个编译时间常数,也就是说,您在加载它后不能更改它loadCompactModel
。
Extended Capabilities
C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。
用法注释和限制:
使用代码生成支持这些分类和回归模型对象,并使用金宝appSaveCompactModel
。
Classification models:
完整或紧凑的分类树,
分类树
或者compactClassificationTree
, respectively完整或紧凑的支持向量机(SVM)金宝app,
分类vm
或者compactClassificationvm
, respectively线性分类模型,
分类线
模型对象Full or compact classification ensembles,
分类安排
或者分类袋装
, or紧凑型classificationEnsemble
, respectivelyFull or compact error-correcting output codes models (ECOC),
ClassificationECOC
或者CompactClassificationECOC
分别模型对象。
回归模型:
Full or compact linear models,
线性模型
或者CompactLinearModel
, respectively完整或紧凑的广泛线性模型,
GeneralizedLinearModel
或者紧凑型地线模型
, respectivelyFull or compact regression trees,
回归树
或者CompactregressionTree
, respectively
See Also
Introduced in R2016b
matlab命令
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
美洲
- AméricaLatina(Español)
- 加拿大(英语)
- 美国(英语)