Main Content

learnersize

Compact size of trained machine learning model object

Since R2024b

    Description

    size = learnersize(Mdl) returns the compact size (in bytes) of the trained machine learning model object Mdl. If Mdl is compact or has no supported compact object version, learnersize returns its actual size. Otherwise, learnersize returns the size of the compact version of Mdl.

    example

    size = learnersize(Mdl,SizeType=type) returns the model size of the specified type. If you specify type="coder" and Mdl is supported for code generation, learnersize returns the approximate size of Mdl (in bytes) in C/C++ code generated by saveLearnerForCoder and codegen (MATLAB Coder).

    example

    Examples

    collapse all

    Train a neural network classification model using the ionosphere data set, and return the compact model object size in bytes.

    load ionosphere.mat;
    Mdl = fitcnet(X,Y);
    size = learnersize(Mdl)
    size = 
    8140
    

    Train a neural network classification model using the ionosphere data set.

    load ionosphere.mat;
    Mdl = fitcnet(X,Y);

    Return the approximate size of the model (in bytes) in C/C++ code generated by saveLearnerForCoder and codegen (MATLAB Coder).

    size = learnersize(Mdl,SizeType="coder")
    size = 
    3834
    

    Because the learnersize function does not generate code, the size represents an estimate of the amount of system memory that would be used by the trained model in generated code.

    Input Arguments

    collapse all

    Machine learning model, specified as a regression or classification model object as given in the following tables of supported models. If you specify SizeType="coder", then Mdl must be supported for code generation.

    Classification Model Object

    ModelFull and Compact Model ObjectsCode Generation Support
    Discriminant analysis classificationClassificationDiscriminant
    CompactClassificationDiscriminant
    Yes
    Multiclass model for support vector machines (SVMs) or other classifiersClassificationECOC
    CompactClassificationECOC
    Yes
    Ensemble classifierClassificationEnsemble
    CompactClassificationEnsemble
    ClassificationBaggedEnsemble
    Yes
    Gaussian kernel model for binary classification of big dataClassificationKernelYes
    k-nearest neighbor classificationClassificationKNNYes
    Linear model for binary classification of high-dimensional dataClassificationLinearYes
    Naive Bayes classifierClassificationNaiveBayes
    CompactClassificationNaiveBayes
    Yes
    Neural network classifierClassificationNeuralNetwork
    CompactClassificationNeuralNetwork
    Yes
    SVM for one-class and binary classificationClassificationSVM
    CompactClassificationSVM
    Yes
    Binary decision tree for classificationClassificationTree
    CompactClassificationTree
    Yes
    Generalized additive model ClassificationGAM
    CompactClassificationGAM
    No

    Regression Model Object

    ModelFull and Compact Model ObjectCode Generation Support
    Generalized linear modelGeneralizedLinearModel
    CompactGeneralizedLinearModel
    Yes
    Linear regression modelLinearModel
    CompactLinearModel
    Yes
    Ensemble regressionRegressionEnsemble
    CompactRegressionEnsemble
    RegressionBaggedEnsemble
    Yes
    Gaussian process regressionRegressionGP
    CompactRegressionGP
    Yes
    Gaussian kernel regression for big dataRegressionKernelYes
    Linear regression for high-dimensional dataRegressionLinearYes
    Neural network regressionRegressionNeuralNetwork
    CompactRegressionNeuralNetwork
    Yes
    Regression treeRegressionTree
    CompactRegressionTree
    Yes
    SVM regressionRegressionSVM
    CompactRegressionSVM
    Yes
    Generalized additive modelRegressionGAM
    CompactRegressionGAM
    No

    Type of the size output, specified as one of the values in this table:

    ValueOutput of learnersize
    "compact" (default)Compact size (in bytes) of the trained machine learning model object Mdl. If Mdl is compact or has no supported compact object version, learnersize returns its actual size. Otherwise, learnersize returns the size of the compact version of Mdl.
    "coder"Approximate size of Mdl (in bytes) in C/C++ code generated by saveLearnerForCoder and codegen. Because the learnersize function does not generate code, the size represents an estimate of the amount of system memory that would be used by the trained model in generated code.

    If you specify SizeType="coder", then Mdl must be supported for code generation (see saveLearnerForCoder).

    Data Types: char | string

    Version History

    Introduced in R2024b

    See Also

    | (MATLAB Coder)