This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: RegressionEnsemble

Prune ensemble


cmp = shrink(ens)
cmp = shrink(ens,Name,Value)


cmp = shrink(ens) returns a compact shrunken version of ens, a regularized ensemble. cmp retains only learners with weights above a threshold.

cmp = shrink(ens,Name,Value) returns an ensemble with additional options specified by one or more Name,Value pair arguments. You can specify several name-value pair arguments in any order as Name1,Value1,…,NameN,ValueN.

Input Arguments


A regression ensemble created with fitrensemble.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.


Vector of nonnegative regularization parameter values for lasso. If ens.Regularization is nonempty (populate it with regularize), shrink regularizes ens using lambda. If ens contains a Regularization structure, you cannot pass lambda.

Default: []


Lower cutoff on weights for weak learners, a numeric nonnegative scalar. shrink creates cmp from those learners with weights above threshold.

Default: 0


Column index of ens.Regularization.TrainedWeights, a positive integer. shrink creates cmp with learner weights from this column.

Default: 1

Output Arguments


A regression ensemble of class CompactRegressionEnsemble. Use cmp for making predictions exactly as you use ens, with the predict method.

shrink orders the members of cmp from largest to smallest.


expand all

Shrink a 300-member bagged regression ensemble, and view the number of members of the resulting ensemble.

Generate sample data.

rng(10,'twister') % For reproducibility
X = rand(2000,20);
Y = repmat(-1,2000,1);
Y(sum(X(:,1:5),2)>2.5) = 1;

Shrink a 300-member bagged regression ensemble using 0.1 for the parameter lambda.

bag = fitrensemble(X,Y,'Method','Bag','NumLearningCycles',300,'Learners','Tree');
cmp = shrink(bag,'lambda',0.1);

View the number of members of the resulting ensemble.

ans = 87
Was this topic helpful?