SlideShare a Scribd company logo
1 of 30
森を見て枝を矯める
1.Toromei, et al. @KDD 2017 を紹介します
• randomForestの予測結果に基づいて、個別の事例に対する改善案を推薦する
2.Rで実装して使ってみます
第67回R勉強会@東京(#TokyoR)
Introduction of “Interpretable Predictions of Tree-based Ensembles
via Actionable FEATURE TWEAKING”
学習データのサブセットから構成した
各決定木の予測結果を結合 = 森
 分類 → 多数決
 回帰 → 平均
予測モデルを組み合わせるアンサンブル法のひとつ
ensemble trees
Image from: https://ja.wikipedia.org/wiki/%E6%A3%AE%E6%9E%97
木(弱学習器)
ensemble trees
各木の予測結果を結合 = 森
Image from: https://www.youtube.com/watch?v=KIP2N5HZRW8
ensemble trees
決定木の過半数 が negative と予測 → 多数決により、negative と判断する(予測を多数決する場合)
@ CRAN
CRAN Task View: Machine Learning & Statistical Learning
>Random Forest
>Boosting and Gradient Descent
CRAN Task View: Machine Learning & Statistical Learning
https://cran.r-project.org/web/views/MachineLearning.html
ensemble methods
相対重要度
ある特徴変数をノイズ化したときの精度低下にもとづいて、
その変数の予測精度への相対的な重要性を評価する
予測モデルを作った後は...
感度分析(Partial Dependency Plot)
予測モデルを作った後は...
各変数の動き vs 予測値の平均の動き を可視化する
各特徴量の感度分析 in ”forestFloorパッケージを使ったrandomForestの感度分析”
https://www.slideshare.net/kato_kohaku/sensitivity-analysis-usingforestfloor
ICEboxパッケージをつかったPDPの分解randomForestパッケージのPDP
貢献度と感度分析
各特徴量の貢献度を評価する in ”forestFloorパッケージを使ったrandomForestの感度分析”
https://www.slideshare.net/kato_kohaku/sensitivity-analysis-usingforestfloor
@TokyoR#55
予測モデルを作った後は...
貢献度(XGBoost版)
xgboostExplainerによる各特徴量の貢献度の可視化 in “xgboost の中を覗いてみる“
https://qiita.com/vascoosx/items/efb3177ecf2ead5d8ce0
予測モデルを作った後は...
欠損値の補完
missForestによる欠損値補完 in “Imputation of Missing Values using Random Forest”
https://www.slideshare.net/kato_kohaku/imputation-of-missing-values-using-random-forest
@TokyoR#53
ちょっと変わった使い方...
INTERPRETABILITY
• その入力→出力(予測)は、何故/どうやって得られたのか?
• その入力→出力(予測)は、何を意味しているのか?
Image from: https://www.youtube.com/watch?v=KIP2N5HZRW8
予測モデルの解釈性
利用者に納得感を与える変数選択法
LASSOの別解を与える in “Introduction of "the alternate features search" using R”
https://www.slideshare.net/kato_kohaku/introduction-alternate-featuresinlassor-71186764
@TokyoR#58
例えば...
正則化によるルール縮約
• randomForestでルール生成
• LASSOでルールの刈込み
原著:Friedman & Propescu (2005)
http://statweb.stanford.edu/~jhf/ftp/RuleFit.pdf
著者らによるR実装
http://statweb.stanford.edu/~jhf/R_RuleFit.html
紹介記事
https://www.datasciencecentral.com/profiles/blogs/using-rulefit-ensemble-models-is-about-to-become-very-important
randomForestと解釈性
バスケット分析によるルール抽出・要約
ランダムフォレストにバスケット分析 in “Interpreting Tree Ensembles with inTrees”
https://www.slideshare.net/kato_kohaku/interpreting-tree-ensembles-with-intrees
@TokyoR#51
defragTreesも良い
...が、R実装がない
randomForestと解釈性
Toromei, et al. @KDD 2017 (https://arxiv.org/abs/1706.06691 )
Actionable FEATURE TWEAKING
Wants
どの変数をどう変えたら予測が変わるか?
Modified from: https://www.youtube.com/watch?v=KIP2N5HZRW8
Which & How?
Actionable FEATURE TWEAKING
• モデルの予測を理解できる = 解釈
• ルール抽出 + 感度分析、というアプローチ
アイデア = 予測結果を変えたい
? X<10
Class= POSITIVE Class= NEGATIVE
X=11
YES NO
Decision boundary
Actionable FEATURE TWEAKING
アイデア =決定境界の反対側にシフト
? X<10
Class= POSITIVE Class= NEGATIVE
X=11-2
YES NO
Wants
Decision boundary
Actionable FEATURE TWEAKING
アイデア:変更コストが最小の操作を選ぶ
Feature i
Feature j
Class:
Positive
Class:
Negative
ε
ε
ε
ε
Decision boundary
ε
全変数を正規化することで、逸脱パラメータ ε は一つでよい
ε-satisfactory instance
決定境界の反対側に ε だけ逸脱するインスタンス候補のうち
変更コストが最も小さい(=最小距離)インスタンスを選ぶ
Wants
Actionable FEATURE TWEAKING
アルゴリズム
1. 森モデルによって「望ましくない」ラベルと予測された事例 Xi を拾う
2. 事例 Xi を「望ましくない」ラベルと予測した木を列挙する
3. 列挙した木から、「望ましい」ラベルを予測するパスを列挙する
4. 列挙したパスのうちいずれかについて、事例 Xi から最小の変更量で条件を満たす Xi’ を、変更候補とする
5. 変更候補 Xi’ が森モデルによって「望ましい」ラベルと予測されれば、採択する
Prediction by ensemble trees
Actionable FEATURE TWEAKING
多クラス分類にも自然に拡張可能
Setosa
Versicolor Virginica Versicolor Virginica
Actionable FEATURE TWEAKING
Pythonでの実装と解説記事
http://setten-qb.hatenablog.com/entry/2017/10/22/232016
参考
R版を作った
1. Ensemble Treesからのルールを抽出する
• randomForest 版は実装済み、XGBoost 版は途中まで
2. 推薦パターンを計算する
3. 推薦パターンを可視化する
人工データの負例を正例と予測するように変更する例
●変更元 → ●変更提案 ( ○正例 )
作った: FEATURE TWEAKING
Rの実装コード → https://github.com/katokohaku/feature_tweaking
論文中の適用例
Actionable FEATURE TWEAKING
Image from: https://www.youtube.com/watch?v=KIP2N5HZRW8
“スパム” → “スパムじゃない” に変える
使ってみる:
Rなら{kernlab}パッケージのspamデータ
“スパム” → “スパムじゃない” に変える
手順
1. データのスケーリング
2. randomForestで学習(変数も間引き等を含む)
3. ルールの抽出とε-satisfactory instanceの計算
4. 分析と可視化
5. スケーリングされたデータの復元
使ってみる:
Rの実装コード → https://github.com/katokohaku/feature_tweaking
“スパム” → “スパムじゃない” に変える
使ってみる:
各事例で、どの変数をどちらに動かすか?(=提案パターン)
“スパム” → “スパムじゃない” に変える
使ってみる:
各提案でどちらに動かしたか?全部で何回変更されたか?
e.g. “!” や “$”の多いメールから数を減らせと提案
まとめ
予測結果に基づいて、個別の事例に対する改善案を推薦する
推薦パターンを集計することで、対象集団全体での変数の意味を評価する
所感
予測モデルは構築されていることが前提
 ensemble tree-basedな手法による十分な予測精度が必要
重い
 事前にしっかり特徴選択してないと、suggestが多すぎて死ぬ
 元論文のアルゴリズムのままだと計算コストが高すぎるので、実装時に見直す必要がある
因果関係ではないことに注意
 関連項目の洗い出しができたら、要因分析をすればよいのでは?
操作・介入できない変数に対する配慮は別途必要
 年齢や性別などは提案されても変えようがない
 モデル自体を層別化するとか、禁止リスト等で対処したい
Actionable FEATURE TWEAKING
参考
• 元論文
• arXiv:1706.06691 [stat.ML]
• https://arxiv.org/abs/1706.06691
• 原著者による論文紹介の動画
• https://www.youtube.com/watch?v=KIP2N5HZRW8
• 接点QBさんによる紹介とpython実装記事
• http://setten-qb.hatenablog.com/entry/2017/10/22/232016

More Related Content

What's hot

不均衡データのクラス分類
不均衡データのクラス分類不均衡データのクラス分類
不均衡データのクラス分類
Shintaro Fukushima
 
第14章集団学習
第14章集団学習第14章集団学習
第14章集団学習
Kei Furihata
 
前回のCasual Talkでいただいたご要望に対する進捗状況
前回のCasual Talkでいただいたご要望に対する進捗状況前回のCasual Talkでいただいたご要望に対する進捗状況
前回のCasual Talkでいただいたご要望に対する進捗状況
JubatusOfficial
 
第1回 Jubatusハンズオン
第1回 Jubatusハンズオン第1回 Jubatusハンズオン
第1回 Jubatusハンズオン
Yuya Unno
 

What's hot (20)

「樹木モデルとランダムフォレスト-機械学習による分類・予測-」-データマイニングセミナー
「樹木モデルとランダムフォレスト-機械学習による分類・予測-」-データマイニングセミナー「樹木モデルとランダムフォレスト-機械学習による分類・予測-」-データマイニングセミナー
「樹木モデルとランダムフォレスト-機械学習による分類・予測-」-データマイニングセミナー
 
不均衡データのクラス分類
不均衡データのクラス分類不均衡データのクラス分類
不均衡データのクラス分類
 
NL20161222invited
NL20161222invitedNL20161222invited
NL20161222invited
 
Random forest の解説
Random forest の解説Random forest の解説
Random forest の解説
 
アンサンブル木モデル解釈のためのモデル簡略化法
アンサンブル木モデル解釈のためのモデル簡略化法アンサンブル木モデル解釈のためのモデル簡略化法
アンサンブル木モデル解釈のためのモデル簡略化法
 
Rによる分類木 入門
Rによる分類木 入門Rによる分類木 入門
Rによる分類木 入門
 
20130716 はじパタ3章前半 ベイズの識別規則
20130716 はじパタ3章前半 ベイズの識別規則20130716 はじパタ3章前半 ベイズの識別規則
20130716 はじパタ3章前半 ベイズの識別規則
 
Rで学ぶロバスト推定
Rで学ぶロバスト推定Rで学ぶロバスト推定
Rで学ぶロバスト推定
 
[DL輪読会]Set Transformer: A Framework for Attention-based Permutation-Invariant...
[DL輪読会]Set Transformer: A Framework for Attention-based Permutation-Invariant...[DL輪読会]Set Transformer: A Framework for Attention-based Permutation-Invariant...
[DL輪読会]Set Transformer: A Framework for Attention-based Permutation-Invariant...
 
第14章集団学習
第14章集団学習第14章集団学習
第14章集団学習
 
ゼロから始める深層強化学習(NLP2018講演資料)/ Introduction of Deep Reinforcement Learning
ゼロから始める深層強化学習(NLP2018講演資料)/ Introduction of Deep Reinforcement Learningゼロから始める深層強化学習(NLP2018講演資料)/ Introduction of Deep Reinforcement Learning
ゼロから始める深層強化学習(NLP2018講演資料)/ Introduction of Deep Reinforcement Learning
 
前回のCasual Talkでいただいたご要望に対する進捗状況
前回のCasual Talkでいただいたご要望に対する進捗状況前回のCasual Talkでいただいたご要望に対する進捗状況
前回のCasual Talkでいただいたご要望に対する進捗状況
 
Deep forest (preliminary ver.)
Deep forest  (preliminary ver.)Deep forest  (preliminary ver.)
Deep forest (preliminary ver.)
 
[DL輪読会]The Neural Process Family−Neural Processes関連の実装を読んで動かしてみる−
[DL輪読会]The Neural Process Family−Neural Processes関連の実装を読んで動かしてみる−[DL輪読会]The Neural Process Family−Neural Processes関連の実装を読んで動かしてみる−
[DL輪読会]The Neural Process Family−Neural Processes関連の実装を読んで動かしてみる−
 
Active Learning from Imperfect Labelers @ NIPS読み会・関西
Active Learning from Imperfect Labelers @ NIPS読み会・関西Active Learning from Imperfect Labelers @ NIPS読み会・関西
Active Learning from Imperfect Labelers @ NIPS読み会・関西
 
ユニットリストのおすすめの使い方
ユニットリストのおすすめの使い方ユニットリストのおすすめの使い方
ユニットリストのおすすめの使い方
 
20190725 taguchi decision_tree_for_pubshare
20190725 taguchi decision_tree_for_pubshare20190725 taguchi decision_tree_for_pubshare
20190725 taguchi decision_tree_for_pubshare
 
Jubatus Casual Talks #2: 大量映像・画像のための異常値検知とクラス分類
Jubatus Casual Talks #2: 大量映像・画像のための異常値検知とクラス分類Jubatus Casual Talks #2: 大量映像・画像のための異常値検知とクラス分類
Jubatus Casual Talks #2: 大量映像・画像のための異常値検知とクラス分類
 
Rainbow: Combining Improvements in Deep Reinforcement Learning (AAAI2018 unde...
Rainbow: Combining Improvements in Deep Reinforcement Learning (AAAI2018 unde...Rainbow: Combining Improvements in Deep Reinforcement Learning (AAAI2018 unde...
Rainbow: Combining Improvements in Deep Reinforcement Learning (AAAI2018 unde...
 
第1回 Jubatusハンズオン
第1回 Jubatusハンズオン第1回 Jubatusハンズオン
第1回 Jubatusハンズオン
 

More from Satoshi Kato

More from Satoshi Kato (9)

How to generate PowerPoint slides Non-manually using R
How to generate PowerPoint slides Non-manually using RHow to generate PowerPoint slides Non-manually using R
How to generate PowerPoint slides Non-manually using R
 
Dimensionality reduction with t-SNE(Rtsne) and UMAP(uwot) using R packages.
Dimensionality reduction with t-SNE(Rtsne) and UMAP(uwot) using R packages. Dimensionality reduction with t-SNE(Rtsne) and UMAP(uwot) using R packages.
Dimensionality reduction with t-SNE(Rtsne) and UMAP(uwot) using R packages.
 
Exploratory data analysis using xgboost package in R
Exploratory data analysis using xgboost package in RExploratory data analysis using xgboost package in R
Exploratory data analysis using xgboost package in R
 
Introduction of inspectDF package
Introduction of inspectDF packageIntroduction of inspectDF package
Introduction of inspectDF package
 
Genetic algorithm full scratch with R
Genetic algorithm full scratch with RGenetic algorithm full scratch with R
Genetic algorithm full scratch with R
 
Multiple optimization and Non-dominated sorting with rPref package in R
Multiple optimization and Non-dominated sorting with rPref package in RMultiple optimization and Non-dominated sorting with rPref package in R
Multiple optimization and Non-dominated sorting with rPref package in R
 
Introduction of "the alternate features search" using R
Introduction of  "the alternate features search" using RIntroduction of  "the alternate features search" using R
Introduction of "the alternate features search" using R
 
forestFloorパッケージを使ったrandomForestの感度分析
forestFloorパッケージを使ったrandomForestの感度分析forestFloorパッケージを使ったrandomForestの感度分析
forestFloorパッケージを使ったrandomForestの感度分析
 
Oracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslassoOracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslasso
 

Intoroduction & R implementation of "Interpretable predictions of tree-based ensembles via actionable feature tweaking