Main Content

compact

Class: RegressionSVM

Compact support vector machine regression model

Syntax

compactMdl = compact(mdl)

Description

compactMdl = compact(mdl) returns a compact support vector machine (SVM) regression model, compactMdl, which is the compact version of the full, trained SVM regression model mdl.

compactMdl does not contain the training data, whereas mdl contains the training data in its properties mdl.X and mdl.Y.

Input Arguments

expand all

Full, trained SVM regression model, specified as a RegressionSVM model returned by fitrsvm.

Output Arguments

expand all

Compact SVM regression model, returned as a CompactRegressionSVM model.

Predict response values using compactMdl exactly as you would using mdl. However, since compactMdl does not contain training data, you cannot perform certain tasks, such as cross validation.

Examples

expand all

This example shows how to reduce the size of a full, trained SVM regression model by discarding the training data and some information related to the training process.

This example uses the abalone data from the UCI Machine Learning Repository. Download the data and save it in your current directory with the name 'abalone.data'. Read the data into a table.

tbl = readtable('abalone.data','Filetype','text','ReadVariableNames',false);
rng default  % for reproducibility

The sample data contains 4177 observations. All of the predictor variables are continuous except for sex, which is a categorical variable with possible values 'M' (for males), 'F' (for females), and 'I' (for infants). The goal is to predict the number of rings on the abalone, and thereby determine its age, using physical measurements.

Train an SVM regression model using a Gaussian kernel function and an automatic kernel scale. Standardize the data.

mdl = fitrsvm(tbl,'Var9','KernelFunction','gaussian','KernelScale','auto','Standardize',true)
mdl = 

  RegressionSVM
           PredictorNames: {1x8 cell}
             ResponseName: 'Var9'
    CategoricalPredictors: 1
        ResponseTransform: 'none'
                    Alpha: [3635x1 double]
                     Bias: 10.8144
         KernelParameters: [1x1 struct]
                       Mu: [1x10 double]
                    Sigma: [1x10 double]
          NumObservations: 4177
           BoxConstraints: [4177x1 double]
          ConvergenceInfo: [1x1 struct]
          IsSupportVector: [4177x1 logical]
                   Solver: 'SMO'


  Properties, Methods

Compact the model.

compactMdl = compact(mdl)
compactMdl = 

  classreg.learning.regr.CompactRegressionSVM
           PredictorNames: {1x8 cell}
             ResponseName: 'Var9'
    CategoricalPredictors: 1
        ResponseTransform: 'none'
                    Alpha: [3635x1 double]
                     Bias: 10.8144
         KernelParameters: [1x1 struct]
                       Mu: [1x10 double]
                    Sigma: [1x10 double]
           SupportVectors: [3635x10 double]


  Properties, Methods

The compacted model discards the training data and some information related to the training process.

Compare the size of the full model mdl and the compact model compactMdl.

vars = whos('compactMdl','mdl');
[vars(1).bytes,vars(2).bytes]
ans =

      323793      775968

The compacted model consumes about half the memory of the full model.

This example shows how to reduce the memory consumption of a full, trained SVM regression model by compacting the model and discarding the support vectors.

Load the carsmall sample data.

load carsmall
rng default  % for reproducibility

Train a linear SVM regression model using Weight as the predictor variable and MPG as the response variable. Standardize the data.

mdl = fitrsvm(Weight,MPG,'Standardize',true);

Note that MPG contains several NaN values. When training a model, fitrsvm will remove rows that contain NaN values from both the predictor and response data. As a result, the trained model uses only 94 of the 100 total observations contained in the sample data.

Compact the regression model to discard the training data and some information related to the training process.

compactMdl = compact(mdl);

compactMdl is a CompactRegressionSVM model that has the same parameters, support vectors, and related estimates as mdl, but no longer stores the training data.

Discard the support vectors and related estimates for the compacted model.

mdlOut = discardSupportVectors(compactMdl);

mdlOut is a CompactRegressionSVM model that has the same parameters as mdl and compactMdl, but no longer stores the support vectors and related estimates.

Compare the sizes of the three SVM regression models, compactMdl, mdl, and mdlOut.

vars = whos('compactMdl','mdl','mdlOut');
[vars(1).bytes,vars(2).bytes,vars(3).bytes]
ans =

        3601       13727        2305

The compacted model compactMdl consumes 3601 bytes of memory, while the full model mdl consumes 13727 bytes of memory. The model mdlOut, which also discards the support vectors, consumes 2305 bytes of memory.

References

[1] Nash, W.J., T. L. Sellers, S. R. Talbot, A. J. Cawthorn, and W. B. Ford. "The Population Biology of Abalone (Haliotis species) in Tasmania. I. Blacklip Abalone (H. rubra) from the North Coast and Islands of Bass Strait." Sea Fisheries Division, Technical Report No. 48, 1994.

[2] Waugh, S. "Extending and Benchmarking Cascade-Correlation: Extensions to the Cascade-Correlation Architecture and Benchmarking of Feed-forward Supervised Artificial Neural Networks." University of Tasmania Department of Computer Science thesis, 1995.

[3] Clark, D., Z. Schreter, A. Adams. "A Quantitative Comparison of Dystal and Backpropagation." submitted to the Australian Conference on Neural Networks, 1996.

[4] Lichman, M. UCI Machine Learning Repository, [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science.

Extended Capabilities

Version History

Introduced in R2015b

expand all