Main Content

regularize

再代入誤差とペナルティー項を最小限にするための重み検索

構文

ens1 = regularize(ens)
ens1 = regularize(ens,Name,Value)

説明

ens1 = regularize(ens) は LASSO 正則化によって ens の学習器の最適な重みを求めます。regularizeens と同じアンサンブル回帰を返しますが、Regularization プロパティが埋め込まれています。

ens1 = regularize(ens,Name,Value) では、1 つまたは複数の Name,Value のペア引数で指定された追加オプションを使用して、最適な重みを計算します。Name1,Value1,…,NameN,ValueN のように、複数の名前と値のペアの引数を任意の順番で指定できます。

入力引数

ens

関数 fitrensemble で作成されたアンサンブル回帰。

名前と値の引数

オプションの引数のペアを Name1=Value1,...,NameN=ValueN として指定します。ここで Name は引数名、Value は対応する値です。名前と値の引数は他の引数の後ろにする必要がありますが、ペアの順序は関係ありません。

R2021a より前では、名前と値をそれぞれコンマを使って区切り、Name を引用符で囲みます。

lambda

LASSO に指定する非負の正則化パラメーター値のベクトル。lambda の既定の設定を使用した場合、regularize は、学習器のすべての最適な重みが 0 となる最小値 lambda_max を計算します。lambda の既定値は、0 および lambda_max/1000 から lambda_max までの 9 のべき乗数を含むベクトルです。

既定値: [0 logspace(log10(lambda_max/1000),log10(lambda_max),9)]

MaxIter

許容される最大反復回数。正の整数を指定します。収束許容誤差に達する前に MaxIter 回実行が反復された場合、反復が停止され、警告メッセージが返されます。lambda の値の個数または npass が 1 より大きい場合、複数の警告が返される可能性があります。

既定値: 1e3

npass

LASSO 最適化のパスの最大数で、正の整数。

既定値: 10

reltol

LASSO の正則化された損失の相対許容誤差、正の数値スカラー。

既定値: 1e-3

verbose

0 または 1 の詳細レベル。1 に設定した場合、regularize の実行時に追加情報が表示されます。

既定値: 0

出力引数

ens1

アンサンブル回帰。通常、ens1ens と同じ名前に設定します。

すべて展開する

バギング木のアンサンブルを正則化します。

標本データを生成します。

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

300 本の木によるバギング分類アンサンブルを標本データから作成できます。

bag = fitrensemble(X,Y,'Method','Bag','NumLearningCycles',300);

'Method''Bag' である場合、fitrensemble は既定の木テンプレート オブジェクト templateTree() を弱学習器として使用します。この例では、再現性を得るため、木テンプレート オブジェクトを作成するときに 'Reproducible',true を指定し、このオブジェクトを弱学習器として使用します。

t = templateTree('Reproducible',true); % For reproducibiliy of random predictor selections
bag = fitrensemble(X,Y,'Method','Bag','NumLearningCycles',300,'Learners',t);

バギング回帰木のアンサンブルを正則化します。

bag = regularize(bag,'lambda',[0.001 0.1],'verbose',1);
Starting lasso regularization for Lambda=0.001. Initial MSE=0.109923.
    Lasso regularization completed pass 1 for Lambda=0.001
        MSE = 0.086912
        Relative change in MSE = 0.264768
        Number of learners with nonzero weights = 15
    Lasso regularization completed pass 2 for Lambda=0.001
        MSE = 0.0670602
        Relative change in MSE = 0.296029
        Number of learners with nonzero weights = 34
    Lasso regularization completed pass 3 for Lambda=0.001
        MSE = 0.0623931
        Relative change in MSE = 0.0748019
        Number of learners with nonzero weights = 51
    Lasso regularization completed pass 4 for Lambda=0.001
        MSE = 0.0605444
        Relative change in MSE = 0.0305348
        Number of learners with nonzero weights = 70
    Lasso regularization completed pass 5 for Lambda=0.001
        MSE = 0.0599666
        Relative change in MSE = 0.00963517
        Number of learners with nonzero weights = 94
    Lasso regularization completed pass 6 for Lambda=0.001
        MSE = 0.0598835
        Relative change in MSE = 0.00138719
        Number of learners with nonzero weights = 105
    Lasso regularization completed pass 7 for Lambda=0.001
        MSE = 0.0598608
        Relative change in MSE = 0.000379227
        Number of learners with nonzero weights = 113
    Lasso regularization completed pass 8 for Lambda=0.001
        MSE = 0.0598586
        Relative change in MSE = 3.72856e-05
        Number of learners with nonzero weights = 115
    Lasso regularization completed pass 9 for Lambda=0.001
        MSE = 0.0598587
        Relative change in MSE = 6.42954e-07
        Number of learners with nonzero weights = 115
    Lasso regularization completed pass 10 for Lambda=0.001
        MSE = 0.0598587
        Relative change in MSE = 4.53658e-08
        Number of learners with nonzero weights = 115
    Completed lasso minimization for Lambda=0.001.
    Resubstitution MSE changed from 0.109923 to 0.0598587.
    Number of learners reduced from 300 to 115.
Starting lasso regularization for Lambda=0.1. Initial MSE=0.109923.
    Lasso regularization completed pass 1 for Lambda=0.1
        MSE = 0.104917
        Relative change in MSE = 0.0477191
        Number of learners with nonzero weights = 12
    Lasso regularization completed pass 2 for Lambda=0.1
        MSE = 0.0851031
        Relative change in MSE = 0.232821
        Number of learners with nonzero weights = 30
    Lasso regularization completed pass 3 for Lambda=0.1
        MSE = 0.081245
        Relative change in MSE = 0.0474877
        Number of learners with nonzero weights = 40
    Lasso regularization completed pass 4 for Lambda=0.1
        MSE = 0.0796749
        Relative change in MSE = 0.0197067
        Number of learners with nonzero weights = 53
    Lasso regularization completed pass 5 for Lambda=0.1
        MSE = 0.0788411
        Relative change in MSE = 0.0105746
        Number of learners with nonzero weights = 64
    Lasso regularization completed pass 6 for Lambda=0.1
        MSE = 0.0784959
        Relative change in MSE = 0.00439793
        Number of learners with nonzero weights = 81
    Lasso regularization completed pass 7 for Lambda=0.1
        MSE = 0.0784429
        Relative change in MSE = 0.000676468
        Number of learners with nonzero weights = 88
    Lasso regularization completed pass 8 for Lambda=0.1
        MSE = 0.078447
        Relative change in MSE = 5.24449e-05
        Number of learners with nonzero weights = 88
    Completed lasso minimization for Lambda=0.1.
    Resubstitution MSE changed from 0.109923 to 0.078447.
    Number of learners reduced from 300 to 88.

regularize では、進捗が報告されます。

生成された正則化の構造体を調べます。

bag.Regularization
ans = struct with fields:
               Method: 'Lasso'
       TrainedWeights: [300x2 double]
               Lambda: [1.0000e-03 0.1000]
    ResubstitutionMSE: [0.0599 0.0784]
       CombineWeights: @classreg.learning.combiner.WeightedSum

正則化されたアンサンブル内に重みが正である学習器がいくつあるかを調べます。これらは、縮小されたアンサンブルに含まれている学習器です。

sum(bag.Regularization.TrainedWeights > 0)
ans = 1×2

   115    88

Lambda = 0.1 による重みを使用してアンサンブルを縮小します。

cmp = shrink(bag,'weightcolumn',2)
cmp = 
  CompactRegressionEnsemble
             ResponseName: 'Y'
    CategoricalPredictors: []
        ResponseTransform: 'none'
               NumTrained: 88


  Properties, Methods

コンパクトなアンサンブルには、元の 300 個の 1/3 より少ない 87 個のメンバーが含まれています。

詳細

すべて展開する

拡張機能