SlideShare ist ein Scribd-Unternehmen logo
1 von 28
32bit Windows で頑張る 
Random Forest 
第43回R勉強会@東京(#TokyoR) 
@fqz7c3
自己紹介 
 twitter : fqz7c3 
 趣味:音楽、囲碁、映画、アニメ、フットサル 
 仕事: ビジネスとデータ分析の橋渡し 
R :通算で2年ほど、前処理は基本Perlで。 
機械学習:1年半ぐらい前に言葉を知りました 
レベル:「ランダムフォレスト最強」な人 
 間違い等ございましたらご指摘ください 
2 / 27
「ランダムフォレスト最強」な人 
 データサイエンティストレベル表shakezoさんブログより 
レベル2の人達は集計分析に加えて、最低限の機械学習や統計学の手法を 
知っています。SVMやランダムフォレストなどのメジャーな手法を覚え、 
データ分析が面白くなってくる頃です。しかしながらRやSPSSなどの専用ソ 
フトを常にデフォルト設定のパラメータで分析していたり、特徴量選択や前 
処理の重要性を甘く見る傾向があります。 
近いうちに現実のデータはirisのように 
甘くないことを知ることになるでしょう。 
ありがちな発言 
「ランダムフォレスト最強」 
http://d.hatena.ne.jp/shakezo/20130715/1373874047 
3 / 27
Random Forest 
 一つのデータセットから微妙に違う決定木を複数 
作って、その多数決で答えを求めるアルゴリズム 
データ 
・ 
・ 
・ 
復元抽出& 
決定木作成 
判定 
A 
B 
A 
C 
A 
A 
各判定の結果 
多数決最終判定結果 
4 / 27
やっぱり最強!? 
 速くて精度が良い 
 一応、変数の重要度が分かる 
 ビジネス上の関係者に理解してもらいやすい 
Leo Breiman先生 
ありがとう! 
5 / 27
Rで使う 
 randomForestパッケージが有名 
調整する 
主なパラメータ 
説明(デフォルト値) 
ntree 生成する木の数(500) 
mtry 
各木で用いる変数の数 
(分類: 全変数の1/3、回帰:全変数の二乗根) 
nodesize 
各ノードでの分岐の打ち切り数 
(分類: 1、回帰: 5以下) 
maxnodes 終端ノード数の上限値(NULL) 
6 / 27
ntreeを増やすと 
 木の多様性が増し精度向上が期待される 
 しかし、メモリが足りなくなることがある。。 
 特に32bit Windowsでは2GBの壁もあり、つらい。。 
7 / 27
対処策 
 trainデータのダウンサンプリング 
 randomforestのモデルを合体(combine) 
 maxnodesの設定 
8 / 27
対処策 
 trainデータのダウンサンプリング 
 randomforestのモデルを合体(combine) 
 maxnodesの設定 
9 / 27
maxnodes 
 木の終端ノード数の上限を設定するパラメータ 
値を小さくすると階層の浅い小さな木になる 
過学習を防ぐために使うのが本来の用途(たぶん) 
1 
2 3 
1 2 
2 3 
maxnodes=3 の場合maxnodes=2 の場合 
10 / 27
maxnodes 
 デフォルトがNULL 
非常に複雑な大きな木ができる 
大きな木ができても保持できる様に、大量のメモリを確保 
しようとして失敗するっぽい(未確認) 
maxnodesを適切に設定すれば 
メモリ使用量を抑えられそう! 
11 / 27
maxnodes設定の流れ 
ntree少なめで実行 
終端ノードを数える 
maxnodesを設定して 
再度実行 
12 / 27
ntree少なめで実行 
 ntree=100 
実行できたが、 
OOBエラーが 
下がりきっていない 
⇒ntreeを増やすことで 
精度向上の可能性 
13 / 27
終端ノードを数える 
 森を見る 
14 / 27
終端ノードを数える 
 森を見る 
最も大きい木のノード数 
ntreeで指定した木の本数 
rfmodel$forest$nodestatus に 
各木の全ノードについて、 
それぞれ分岐であるか、終端ノードであるかの 
情報が入っている 
15 / 27
終端ノードを数える 
 nodestatusの見方 
 1:分岐ノード 
-1:終端ノード 
 0:空 
-1の個数を数えれば 
終端ノードの数が分かる! 
16 / 27
終端ノードを数える 
 (参考)木のイメージ 
1 
2 
4 5 
3 
17 / 27
終端ノードを数える 
 (参考)木のイメージ 
1 
2 
3 
6 7 
4 5 
8 9 
18 / 27
終端ノードを数える 
 木ごとの終端ノードを数える 
19 / 27
終端ノードを数える 
 終端ノード数のヒストグラム 
正規分布っぽい? 
20 / 27
終端ノードを数える 
 終端ノード数のサマリー 
とりあえず、 
maxnodes=3500で 
やってみよう! 
21 / 27
maxnodesを設定して再度実行 
 ntree=1000,maxnodes=3500 
動いた! 
22 / 27
maxnodesを設定して再度実行 
 OOBエラーの推移 
今度は 
下がりきってる! 
23 / 27
maxnodesを設定して再度実行 
 OOBエラーの比較 
ntree=100 
9.38% ntree=1000 
9.08% 
0.3%改善された! 
24 / 27
maxnodesを設定して再度実行 
 ついでに、終端ノード数のヒストグラム 
正規分布ですね! 
25 / 27
まとめ 
 maxnodesの設定でメモリ使用量を抑えられる! 
 その結果、ntreeを増やすことができ精度が向上! 
 これでRandom Forestはさらに強くなる! 
26 / 27
参考資料 
 利用したデータ 
 UCI Machine Learning Repository のBank Marketing Data Set 
http://archive.ics.uci.edu/ml/datasets/Bank+Marketing 
 下記論文からの引用 
[Moro et al., 2014] S. Moro, P. Cortez and P. Rita. A Data-Driven Approach to Predict the 
Success of Bank Telemarketing. Decision Support Systems, Elsevier, 62:22-31, June 2014 
 randomForestについて 
 マニュアル 
http://cran.r-project.org/web/packages/randomForest/randomForest.pdf 
 forestの中身の見方 
https://stat.ethz.ch/pipermail/r-help/2003-April/032256.html 
27 / 27
Enjoy!

Weitere ähnliche Inhalte

Empfohlen

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Empfohlen (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

32bit Windowsで頑張るRandom Forest