Main Content

shrink

Prune ensemble

Syntax

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

Description

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

ens

A regression ensemble created with fitrensemble.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

lambda

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: []

threshold

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

Default: 0

weightcolumn

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

Default: 1

Output Arguments

cmp

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.

Examples

expand all

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

Generate sample data.

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);
cmp = shrink(bag,'lambda',0.1);

View the number of members of the resulting ensemble.

cmp.NumTrained
ans = 94

Extended Capabilities