Main Content

shrink

Prune regression ensemble

Description

cmp = shrink(ens) returns a CompactRegressionEnsemble version of ens, a regularized regression ensemble. cmp retains only those learners with weights above the specified threshold. shrink orders the members of cmp from largest to smallest. You can make predictions using cmp in the same way as when using ens with the predict function.

example

cmp = shrink(ens,Name=Value) specifies additional options using one or more name-value arguments. For example, you can specify the regularization parameter values for lasso, a lower cutoff on weights for weak learners, and the column index containing learner weights.

Input Arguments

expand all

Regression ensemble model, specified as a RegressionEnsemble model object trained 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.

Example: shrink(ens,Threshold=0.1,Weightcolumn=1) specifies to use a lower cutoff of 0.1 for weak learners, and that the first column of ens contains learner weights.

Regularization parameter values for lasso, specified as a vector of nonnegative scalar values. If ens.Regularization is nonempty (that is, the property contains values specified by the regularize function), shrink regularizes ens using Lambda. If ens contains a Regularization structure, you cannot specify Lambda.

Example: Lambda=[.01 .1 1]

Data Types: single | double

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

Example: Threshold=0.1

Data Types: single | double

Weights column, specified as a positive integer. Weightcolumn is the column index of ens.Regularization.TrainedWeights. shrink creates cmp with learner weights from this column.

Example: Weightcolumn=2

Data Types: single | double

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

Version History

Introduced in R2011a