introduction of "the alternate features search" using r

26
見見見見見見見見見 見見見見見 Finding Alternate Features in Lassos” 1.“ Finding Alternate Features in Lassos” 見 見 R 見見見見見見 見見 (Satoshi Hara and Takanori Maehara (2016): "Finding Alternate Features in Lasso", in NIPS 2016 workshop on Interpretable Machine Learning for Complex Systems, December 10th, 2016.) 2. {glmnet} 見見見見見見見見見見見 Lasso 見見見見見見見見見見見見見見見見見見見見見見 58見 R 見見見 見見見 @( #TokyoR

Upload: satoshi-kato

Post on 24-Jan-2017

343 views

Category:

Data & Analytics


1 download

TRANSCRIPT

Page 1: Introduction of  "the alternate features search" using R

見落とされた変数に 救いの手を“ Finding Alternate Features in Lassos”

1.“ Finding Alternate Features in Lassos” の一部を R でトレースします(Satoshi Hara and Takanori Maehara (2016): "Finding Alternate Features in Lasso", in NIPS 2016 workshop on Interpretable Machine Learning for Complex Systems, December 10th, 2016.) 2. {glmnet} で実装して使ってみますLasso における変数選択と代替候補となる変数の可視化

第58回 R勉強会@東京(#TokyoR)

Page 2: Introduction of  "the alternate features search" using R

変数選択 ( モデル選択 ) どうしてますか ?

オペレーションズ・リサーチ 2013 年 5 月号, 261-266

LASSO

Page 3: Introduction of  "the alternate features search" using R

Lasso の変数選択の問題点#2#1

• 「変数の数 >> サンプルサイズ」 なデータの扱い• http://www.slideshare.net/kato_kohaku/oracle-property-andhdmpkgrigorouslasso 

#2• “Finding Alternate Features in Lassos” の論文紹介

• R で線形回帰だけ実装したので {glmnet} の Lasso における変数選択と代替候補となる変数を可視化• 重回帰分析の前処理をとしての多重共線性のチェックを、二次工程に回

せるのでは?• 二値分類とかは本家の Python で。

Page 4: Introduction of  "the alternate features search" using R

Lasso• 回帰モデルの係数 (β) の絶対値を大きくしたくない → 損失関数に罰則項を加えた目的関数 L(β) とする

The Lasso optimal solution• この目的関数を最小化するような推定量 (β*) を求

める𝛽∗=arg min

𝛽𝑓 ( 𝑋 𝛽 , 𝑦 )+𝜆‖𝛽‖1

Page 5: Introduction of  "the alternate features search" using R

Lasso• 線形重回帰モデルで、最小二乗法で係数を推定をする場

合:

|β| の大きさに対する罰則項最小二乗法

 λ は罰則の大きさを 調整するパラメータ

β の絶対値を大きさを定数 t 以下に抑えたい最小二乗法

Page 6: Introduction of  "the alternate features search" using R

Lasso の縮小推定( shrinkage )

Hao Helen Zhang, Fall 2015 Lecture 12: Variable Selection - Lasso

推定された β j が0なら変数 x j は予測に貢献しない

Page 7: Introduction of  "the alternate features search" using R

Lasso の罰則項soft-thresholding operator

Hao Helen Zhang, Fall 2015 Lecture 12: Variable Selection - Lasso

Lasso の推定量(      )と、最小二乗推定量(    )には、以下の関係がなりたつ

λ

Page 8: Introduction of  "the alternate features search" using R

Lasso の罰則の強さと推定量と変数選択

λ

log(λ)

λ が大きいほど Lasso ので 0 と推定される変数が増える

Page 9: Introduction of  "the alternate features search" using R

Lasso と変数選択Lasso によって「よいモデル」を推定したい= 最適な罰則の強さ( λ )の下で選ばれる 変数とその推定量を決めたい

• λ → 0 (no penalty) では、罰則のない重回帰• λ → ∞ では、定数項だけのモデル

※ 典型的には cross-validation error を眺めながら決める> plot(cv.glmnet(X, y)) > plot(glmnet(X, y) , xvar = "lambda")

λ

log(λ)

Page 10: Introduction of  "the alternate features search" using R

Lasso と変数選択: 見落としの問題• 変数の数 p がサンプルサイズ n よりも多い場合 (p>n) 、 選択される説明変数はサンプルサイズを超えない → 幾つかの改良法が提案されている

• http://www.slideshare.net/kato_kohaku/oracle-property-andhdmpkgrigorouslasso 

• 重要な変数のあいだに高い相関 がある場合、 それらの変数のうちの 1 つだけを選びたがる

Page 11: Introduction of  "the alternate features search" using R

https://arxiv.org/abs/1611.05940 

変数間に高い相関がある場合の見落としに着目

Page 12: Introduction of  "the alternate features search" using R

余談ですが ..

Page 13: Introduction of  "the alternate features search" using R

https://arxiv.org/abs/1606.09066https://github.com/sato9hara/defragTrees

defragTrees の作者

Page 14: Introduction of  "the alternate features search" using R

この論文の提案: Alternate Lasso

選択された変数が使われなかった としたら代わりにどの変数が選択されるか を出力↓複数の解候補を提示することで利用者に納得感を与える

特徴量たちの関係理解・結果の解釈性が高まると期待著者らによる研究の説明から改変http://www.prefield.com/commentary.html  

Page 15: Introduction of  "the alternate features search" using R

Lasso を解きなおす: Alternate Lasso

The Lasso optimal solution• この目的関数を最小化するような推定量 (β*) を求

める𝛽∗=arg min𝛽𝑓 ( 𝑋 𝛽 , 𝑦 )+𝜆‖𝛽‖1

Alternate Lasso

• Lasso 推定量 (β*) のうち β*i≠0, β*j=0 となる i,j の組について β*i=0, βj≠ 0 とおいて、 β*j の推定量を求める

𝛽 𝑗∗❑=arg min

𝛽 𝑗

𝑓 (𝑋 𝛽∗−𝑋 𝑖 𝛽𝑖∗+𝑋 𝑗 𝛽 𝑗+ , 𝑦 )+𝜆‖𝛽‖1

非ゼロ項について足し上げ β*i=0 βj≠ 0

Page 16: Introduction of  "the alternate features search" using R

再推定β*i=0, βj≠ 0 とおいて、 β*j の推定量を求める

再推定された β j が0なら変数 x j は xi を代替しない

Page 17: Introduction of  "the alternate features search" using R

Alternate Lasso の変数スコア• 「差し替えた後の目的関数値がほとんど変わらない」変数は、オリジナルに近いと考える。つまり、  score(xi → x j ) が小さいほどオリジナルに近い

は Lasso が選んだ推定値

どれくらい代わりになるか?という指標(相対値)

Page 18: Introduction of  "the alternate features search" using R

作った: R で minimal

• 線形回帰モデル• 最小二乗法• soft-thresholding operator

https://github.com/katokohaku/AlternateLassoR 

著者の github の Python 実装をみながら R で実装

Page 19: Introduction of  "the alternate features search" using R

動作確認: シンプルな人工データ• 重要な変数= X1, X2• X1 と相関: X3, X4• X2 と相関: X5• 無関係な変数: X6

Page 20: Introduction of  "the alternate features search" using R

作った: re-fit

作った: print() & summary()

glmnet の Lasso で推定した β を解きなおす

Page 21: Introduction of  "the alternate features search" using R

作った: plot()

Page 23: Introduction of  "the alternate features search" using R

使ってみた: Boston Housing Data Set

あとで再利用するのであらかじめデータを正規化CV で λ を見つつ今回は λ.1SE を採用

Page 24: Introduction of  "the alternate features search" using R

使ってみた: Boston Housing Data Set

• Score の順と相関の大きさの順は概ね一致• しないことも結構あるっぽい

• 解釈はできるような、できないような ..

町毎の児童と教師の比率 (ptratio) alt score cor1 $10,000 ドルあたりの不動産税率の総計 tax 0.01382 0.4608532 町毎の児童と教師の比率 (ptratio) zn 0.015046 -0.391683 小売業以外の商業が占める面積の割合 indus 0.015151 0.3832484 環状高速道路へのアクセスしやすさ rad 0.016183 0.4647415 1940 年より前に建てられた物件の割合 age 0.016962 0.261515

Page 25: Introduction of  "the alternate features search" using R

まとめやらなかったこと• Python版にある predict() と evaluate() の実装

• 予測はオリジナルのモデルでやればよいのでは。• 線形回帰以外のモデル所感など• 適用対象が広い

• 適当な損失関数+罰則項の再最適化なので、適用対象がフレキシブル • 元論文( Python版)には、ロジスティックロス関数で 2 値分類する実装も有り

• Score の順が変数間の相関と必ずしも一致しないので、 Lasso の枠組みの中では、単純に多重共線性を見るよりは良い?

• 重回帰分析の前処理をとしての多重共線性のチェックを、二次工程に回せるのでは?

発展版の続報が出てた• Satoshi Hara and Takanori Maehara (2017): "Enumerate Lasso Solutions for Feature Selection", in

Proceedings of the 31st AAAI Conference on Artificial Intelligence (AAAI'17), San Francisco. California, United States, February 4th--9th, 2017

• Python 実装がすでに著者の Github で公開中

Page 26: Introduction of  "the alternate features search" using R

参考文献• 紹介した論文

• Satoshi Hara and Takanori Maehara (2016): "Finding Alternate Features in Lasso", in NIPS 2016 workshop on Interpretable Machine Learning for Complex Systems, December 10th, 2016.

• https://arxiv.org/abs/1611.05940 • 著者による Python 実装@Github :

• Binary classification あり、 predict() あり。• https://github.com/sato9hara/LassoVariants/tree/master/AlternateLasso 

• 著者らによる研究紹介• http://www.prefield.com/commentary.html

• 実装時の参考• Lasso の理論と実装 - スパースな解の推定アルゴリズム -• http://qiita.com/hogefugabar/items/71916560f7efc6eededf