Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

compact

Clase: LinearModel

Compact linear regression model

Sintaxis

compactMdl = compact(mdl)

Description

compactMdl = compact(mdl) returns a compact linear regression model, compactMdl, which is the compact version of the full, fitted linear regression model mdl.

Argumentos de entrada

expandir todo

Full, fitted linear regression model, specified as a LinearModel object constructed using fitlm or stepwiselm.

Output Arguments

expandir todo

Compact linear regression model, returned as a CompactLinearModel object.

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.

Ejemplos

expandir todo

This example shows how to reduce the size of a full, fitted linear regression model by discarding the sample data and some information related to the fitting process.

Load the data into the workspace.

load(fullfile(matlabroot,'examples','stats','largedata4reg.mat'))

The simulated sample data contains 15,000 observations and 45 predictor variables.

Fit a simple linear regression model to the data.

mdl = fitlm(X,Y)
mdl = 
Linear regression model:
    y ~ [Linear formula with 46 terms in 45 predictors]

Estimated Coefficients:
                    Estimate          SE           tStat         pValue   
                   ___________    __________    ___________    ___________

    (Intercept)         3.2903    1.2333e-05     2.6679e+05              0
    x1              -0.0006461    5.9019e-09    -1.0947e+05              0
    x2             -0.00024739    1.0256e-08         -24121              0
    x3             -9.5161e-05    1.3149e-08        -7236.9              0
    x4              0.00013143    1.8311e-08         7177.3              0
    x5               7.163e-05    2.3367e-08         3065.4              0
    x6              4.5064e-06    2.6264e-08         171.58              0
    x7             -2.6258e-05     3.006e-08        -873.51              0
    x8               6.284e-05    3.0262e-08         2076.5              0
    x9             -0.00014288    3.3258e-08        -4296.1              0
    x10            -2.2642e-05    3.6555e-08        -619.41              0
    x11            -6.0227e-05    3.7353e-08        -1612.4              0
    x12             1.1665e-05    4.0048e-08         291.27              0
    x13             3.8595e-05     4.203e-08         918.26              0
    x14             0.00010021    4.7592e-08         2105.5              0
    x15            -6.5674e-06    4.9221e-08        -133.43              0
    x16             8.5598e-06    5.0296e-08         170.19              0
    x17            -3.9107e-05       5.3e-08        -737.87              0
    x18            -6.5841e-06    5.5355e-08        -118.94              0
    x19            -1.7053e-05    5.7431e-08        -296.94              0
    x20            -3.8911e-06    6.2724e-08        -62.036              0
    x21            -9.7219e-06    6.3515e-08        -153.06              0
    x22            -1.8749e-06    6.5388e-08        -28.673    4.6032e-176
    x23            -4.7514e-06    6.6636e-08        -71.303              0
    x24            -1.7756e-05    6.8495e-08        -259.23              0
    x25            -9.6673e-06    7.0054e-08           -138              0
    x26             7.6237e-06    7.2442e-08         105.24              0
    x27            -8.4338e-07    7.7519e-08         -10.88     1.8249e-27
    x28             7.0502e-06    8.1889e-08         86.094              0
    x29            -1.4703e-05    8.7126e-08        -168.75              0
    x30             2.7008e-05    9.0084e-08          299.8              0
    x31             6.3685e-07    9.1253e-08          6.979     3.0977e-12
    x32            -1.9916e-05    1.0034e-07        -198.48              0
    x33             1.7369e-05     1.019e-07         170.45              0
    x34             -9.931e-06    1.0706e-07        -92.764              0
    x35            -1.5195e-05    1.0858e-07        -139.94              0
    x36            -1.0118e-05    1.1122e-07        -90.976              0
    x37             2.4595e-06    1.1254e-07         21.856    2.9315e-104
    x38            -2.2928e-06    1.1493e-07         -19.95     2.0535e-87
    x39             1.1397e-05    1.1855e-07         96.136              0
    x40             4.0239e-06    1.2327e-07         32.643      7.75e-226
    x41            -8.6667e-06    1.2535e-07        -69.142              0
    x42            -8.2932e-06    1.3095e-07        -63.334              0
    x43             2.7309e-06    1.3452e-07         20.301     2.0697e-90
    x44            -6.9235e-06    1.3725e-07        -50.444              0
    x45             1.1165e-06    1.4021e-07         7.9633     1.7956e-15


Number of observations: 15000, Error degrees of freedom: 14954
Root Mean Squared Error: 0.00151
R-squared: 1,  Adjusted R-Squared 1
F-statistic vs. constant model: 2.82e+08, p-value = 0

Compact the model.

compactMdl = compact(mdl)
compactMdl = 
Compact linear regression model:
    y ~ [Linear formula with 46 terms in 45 predictors]

Estimated Coefficients:
                    Estimate          SE           tStat         pValue   
                   ___________    __________    ___________    ___________

    (Intercept)         3.2903    1.2333e-05     2.6679e+05              0
    x1              -0.0006461    5.9019e-09    -1.0947e+05              0
    x2             -0.00024739    1.0256e-08         -24121              0
    x3             -9.5161e-05    1.3149e-08        -7236.9              0
    x4              0.00013143    1.8311e-08         7177.3              0
    x5               7.163e-05    2.3367e-08         3065.4              0
    x6              4.5064e-06    2.6264e-08         171.58              0
    x7             -2.6258e-05     3.006e-08        -873.51              0
    x8               6.284e-05    3.0262e-08         2076.5              0
    x9             -0.00014288    3.3258e-08        -4296.1              0
    x10            -2.2642e-05    3.6555e-08        -619.41              0
    x11            -6.0227e-05    3.7353e-08        -1612.4              0
    x12             1.1665e-05    4.0048e-08         291.27              0
    x13             3.8595e-05     4.203e-08         918.26              0
    x14             0.00010021    4.7592e-08         2105.5              0
    x15            -6.5674e-06    4.9221e-08        -133.43              0
    x16             8.5598e-06    5.0296e-08         170.19              0
    x17            -3.9107e-05       5.3e-08        -737.87              0
    x18            -6.5841e-06    5.5355e-08        -118.94              0
    x19            -1.7053e-05    5.7431e-08        -296.94              0
    x20            -3.8911e-06    6.2724e-08        -62.036              0
    x21            -9.7219e-06    6.3515e-08        -153.06              0
    x22            -1.8749e-06    6.5388e-08        -28.673    4.6032e-176
    x23            -4.7514e-06    6.6636e-08        -71.303              0
    x24            -1.7756e-05    6.8495e-08        -259.23              0
    x25            -9.6673e-06    7.0054e-08           -138              0
    x26             7.6237e-06    7.2442e-08         105.24              0
    x27            -8.4338e-07    7.7519e-08         -10.88     1.8249e-27
    x28             7.0502e-06    8.1889e-08         86.094              0
    x29            -1.4703e-05    8.7126e-08        -168.75              0
    x30             2.7008e-05    9.0084e-08          299.8              0
    x31             6.3685e-07    9.1253e-08          6.979     3.0977e-12
    x32            -1.9916e-05    1.0034e-07        -198.48              0
    x33             1.7369e-05     1.019e-07         170.45              0
    x34             -9.931e-06    1.0706e-07        -92.764              0
    x35            -1.5195e-05    1.0858e-07        -139.94              0
    x36            -1.0118e-05    1.1122e-07        -90.976              0
    x37             2.4595e-06    1.1254e-07         21.856    2.9315e-104
    x38            -2.2928e-06    1.1493e-07         -19.95     2.0535e-87
    x39             1.1397e-05    1.1855e-07         96.136              0
    x40             4.0239e-06    1.2327e-07         32.643      7.75e-226
    x41            -8.6667e-06    1.2535e-07        -69.142              0
    x42            -8.2932e-06    1.3095e-07        -63.334              0
    x43             2.7309e-06    1.3452e-07         20.301     2.0697e-90
    x44            -6.9235e-06    1.3725e-07        -50.444              0
    x45             1.1165e-06    1.4021e-07         7.9633     1.7956e-15


Number of observations: 15000, Error degrees of freedom: 14954
Root Mean Squared Error: 0.00151
R-squared: 1,  Adjusted R-Squared 1
F-statistic vs. constant model: 2.82e+08, p-value = 0

The compact model discards the original sample data and some information related to the fitting 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 = 1×2

       83506    11410618

The compacted model consumes less memory than the full model.

Introducido en R2016a