removeLearners

Remove members of compact regression ensemble

Syntax

```cens1 = removeLearners(cens,idx) ```

Description

`cens1 = removeLearners(cens,idx)` creates a compact regression ensemble identical to `cens` only without the ensemble members in the `idx` vector.

Input Arguments

 `cens` Compact regression ensemble, constructed with `compact`. `idx` Vector of positive integers with entries from `1` to `cens.NumTrained`, where `cens.NumTrained` is the number of members in `cens`. `cens1` contains the members of `cens` except those with indices in `idx`. Typically, you set `idx = j:cens.NumTrained` for some positive integer `j`.

Output Arguments

 `cens1` Compact regression ensemble, identical to `cens` except `cens1` does not contain members of `cens` with indices in `idx`.

Examples

expand all

Create a compact regression ensemble. Compact it further by removing members of the ensemble.

Load the `carsmall` data set and select `Weight` and `Cylinders` as predictors.

```load carsmall X = [Weight Cylinders];```

Train a regression ensemble using LSBoost. Specify tree stumps as the weak learners.

```t = templateTree('MaxNumSplits',1); ens = fitrensemble(X,MPG,'Method','LSBoost','Learners',t,... 'CategoricalPredictors',2);```

Create a compact classification ensemble `cens` from `ens`.

`cens = compact(ens);`

Remove the last 50 members of the ensemble.

```idx = cens.NumTrained-49:cens.NumTrained; cens1 = removeLearners(cens,idx);```

Tips

• Typically, set `cens1` equal to `cens` to retain just one ensemble.

• Removing learners reduces the memory used by the ensemble and speeds up its predictions.