regularize
アンサンブル回帰から学習器に最適な重みを特定する
説明
は、LASSO 正則化を使用して ens1
= regularize(ens
)ens
の学習器の最適な重みを求めます。regularize
は ens
と同じ RegressionEnsemble
モデルを返しますが、Regularization
プロパティが埋め込まれています。
では、1 つ以上の名前と値の引数を使用して追加オプションを指定します。たとえば、正則化パラメーターの値、正則化レベルの相対許容誤差、LASSO 最適化の最大通過回数を指定できます。ens1
= regularize(ens
,Name=Value
)
例
バギング木のアンサンブルの正則化
バギング木のアンサンブルを正則化します。
標本データを生成します。
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
個のメンバーが含まれています。
入力引数
ens
— アンサンブル回帰モデル
RegressionEnsemble
モデル オブジェクト
アンサンブル回帰モデル。fitrensemble
で学習させた RegressionEnsemble
モデル オブジェクトとして指定します。
名前と値の引数
オプションの引数のペアを Name1=Value1,...,NameN=ValueN
として指定します。ここで Name
は引数名、Value
は対応する値です。名前と値の引数は他の引数の後ろにする必要がありますが、ペアの順序は関係ありません。
R2021a より前では、名前と値をそれぞれコンマを使って区切り、Name
を引用符で囲みます。
例: regularize(ens,MaxIter=100,Npass=5)
は、収束許容誤差に達するまで最大 100 回の反復を許容するように指定し、LASSO 最適化の最大通過回数を 5 と指定します。
Lambda
— 正則化パラメーターの値
[0 logspace(log10(Lambda_max/1000),log10(Lambda_max),9)]
(既定値) | 非負のスカラー値のベクトル
LASSO の正則化パラメーターの値。非負のスカラー値のベクトルとして指定します。Lambda
の既定の設定を使用した場合、regularize
は、学習器のすべての最適な重みが 0
となる最小値 Lambda_max
を計算します。Lambda
の既定値は、0
および Lambda_max/1000
から Lambda_max
までの指数関数的な間隔の 9 つの数値を含むベクトルです。
例: Lambda=[0 0.001 0.01 0.1]
データ型: single
| double
Npass
— 最大通過回数
10
(既定値) | 正の整数
LASSO 最適化の最大通過回数。正の整数として指定します。
例: Npass=5
データ型: single
| double
Reltol
— 相対許容誤差
1e-3
(既定値) | 正の数値スカラー
LASSO の正則化された損失の相対許容誤差。正の数値スカラーとして指定します。
例: Reltol=1e-4
データ型: single
| double
Verbose
— 詳細レベル
0
(既定値) | 1
詳細レベル。0
または 1
として指定します。この引数が 1
に設定されている場合、regularize
は正則化プロセスで追加の情報を表示します。
例: Verbose=1
データ型: single
| double
詳細
LASSO
LASSO アルゴリズムは、最小化する、学習器の重みの最適なセット αt を調べます。
ここで、
λ ≥ 0 は、メソッドに渡すパラメーターです。LASSO パラメーターと呼ばれます。
ht は、予測子 xn、応答 yn、および重み wn をもつ N の観測で学習されたアンサンブルの弱学習器です。
g(f,y) = (f – y)2 は二乗誤差です。
拡張機能
GPU 配列
Parallel Computing Toolbox™ を使用してグラフィックス処理装置 (GPU) 上で実行することにより、コードを高速化します。
この関数は、GPU 配列を完全にサポートします。詳細は、GPU での MATLAB 関数の実行 (Parallel Computing Toolbox)を参照してください。
バージョン履歴
R2011a で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)