compact
Description
returns a compact model (compactMdl
= compact(Mdl
)compactMdl
), the compact version of the
trained multiresponse regression model Mdl
. That is,
compactMdl
does not contain the training data, whereas
Mdl
contains the training data in its X
,
Y
, and W
properties. You can use either model to
compute the loss or predict on new data.
Examples
Reduce Size of Multiresponse Regression Model
Reduce the size of a full multiresponse regression model by removing the training data from the model. You can use a compact model to improve memory efficiency.
Load the carbig
data set, which contains measurements of cars made in the 1970s and early 1980s. Create a table containing the predictor variables Displacement
, Horsepower
, and so on, as well as the response variables Acceleration
and MPG
. Display the first eight rows of the table.
load carbig cars = table(Displacement,Horsepower,Model_Year, ... Origin,Weight,Acceleration,MPG); head(cars)
Displacement Horsepower Model_Year Origin Weight Acceleration MPG ____________ __________ __________ _______ ______ ____________ ___ 307 130 70 USA 3504 12 18 350 165 70 USA 3693 11.5 15 318 150 70 USA 3436 11 18 304 150 70 USA 3433 12 16 302 140 70 USA 3449 10.5 17 429 198 70 USA 4341 10 15 454 220 70 USA 4354 9 14 440 215 70 USA 4312 8.5 14
Categorize the cars based on whether they were made in the USA.
cars.Origin = categorical(cellstr(cars.Origin)); cars.Origin = mergecats(cars.Origin,["France","Japan",... "Germany","Sweden","Italy","England"],"NotUSA");
Remove observations with missing values.
cars = rmmissing(cars);
Train a multiresponse regression model by passing the cars
data to the fitrchains
function. Use regression chains composed of regression SVM models with standardized numeric predictors.
Mdl = fitrchains(cars,["Acceleration","MPG"], ... Learner=templateSVM(Standardize=true))
Mdl = RegressionChainEnsemble PredictorNames: {'Displacement' 'Horsepower' 'Model_Year' 'Origin' 'Weight'} ResponseName: ["Acceleration" "MPG"] CategoricalPredictors: 4 ResponseTransform: 'none' NumObservations: 392
Mdl
is a trained RegressionChainEnsemble
model object. The model contains information about the training data set, such as the training data properties X
and Y
.
Reduce the size of the model by using the compact
object function.
compactMdl = compact(Mdl)
compactMdl = CompactRegressionChainEnsemble PredictorNames: {'Displacement' 'Horsepower' 'Model_Year' 'Origin' 'Weight'} ResponseName: ["Acceleration" "MPG"] CategoricalPredictors: 4 ResponseTransform: 'none'
compactMdl
is a CompactRegressionChainEnsemble
model object. compactMdl
contains fewer properties than the full model Mdl
.
Display the amount of memory used by each model.
whos("Mdl","compactMdl")
Name Size Bytes Class Attributes Mdl 1x1 125951 RegressionChainEnsemble compactMdl 1x1 95825 classreg.learning.regr.CompactRegressionChainEnsemble
The full model is larger than the compact model.
Input Arguments
Mdl
— Multiresponse regression model
RegressionChainEnsemble
object
Multiresponse regression model, specified as a RegressionChainEnsemble
object.
Output Arguments
compactMdl
— Compact multiresponse regression model
CompactRegressionChainEnsemble
object
Compact multiresponse regression model, returned as a CompactRegressionChainEnsemble
object.
Version History
Introduced in R2024b
MATLAB Command
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.
Select a Web Site
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: .
You can also select a web site from the following list:
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)