Main Content

regularize

アンサンブル回帰から学習器に最適な重みを特定する

説明

ens1 = regularize(ens) は、LASSO 正則化を使用して ens の学習器の最適な重みを求めます。regularizeens と同じ RegressionEnsemble モデルを返しますが、Regularization プロパティが埋め込まれています。

ens1 = regularize(ens,Name=Value) では、1 つ以上の名前と値の引数を使用して追加オプションを指定します。たとえば、正則化パラメーターの値、正則化レベルの相対許容誤差、LASSO 最適化の最大通過回数を指定できます。

すべて折りたたむ

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

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

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


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

入力引数

すべて折りたたむ

アンサンブル回帰モデル。fitrensemble で学習させた RegressionEnsemble モデル オブジェクトとして指定します。

名前と値の引数

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

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

例: regularize(ens,MaxIter=100,Npass=5) は、収束許容誤差に達するまで最大 100 回の反復を許容するように指定し、LASSO 最適化の最大通過回数を 5 と指定します。

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

例: Lambda=[0 0.001 0.01 0.1]

データ型: single | double

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

例: MaxIter=100

データ型: single | double

LASSO 最適化の最大通過回数。正の整数として指定します。

例: Npass=5

データ型: single | double

LASSO の正則化された損失の相対許容誤差。正の数値スカラーとして指定します。

例: Reltol=1e-4

データ型: single | double

詳細レベル。0 または 1 として指定します。この引数が 1 に設定されている場合、regularize は正則化プロセスで追加の情報を表示します。

例: Verbose=1

データ型: single | double

詳細

すべて折りたたむ

LASSO

LASSO アルゴリズムは、最小化する、学習器の重みの最適なセット αt を調べます。

n=1Nwng((t=1Tαtht(xn)),yn)+λt=1T|αt|.

ここで、

  • λ ≥ 0 は、メソッドに渡すパラメーターです。LASSO パラメーターと呼ばれます。

  • ht は、予測子 xn、応答 yn、および重み wn をもつ N の観測で学習されたアンサンブルの弱学習器です。

  • g(f,y) = (f – y)2 は二乗誤差です。

拡張機能

バージョン履歴

R2011a で導入