SlideShare a Scribd company logo
1 of 25
ベイズ統計セミナー
第4回
Powered by Think Bayes
2018/01/08
(復習)ベイズの定理の考え方に基づいた問題解決手順
1. 問題を解くのに適した仮説集合 𝐻𝑖 とデータ𝐷を設定する
2. 文献や経験値などから各仮説に対する事前確率𝑃(𝐻𝑖)を計算する。
3. 各仮説に対する尤度𝑃(𝐷|𝐻𝑖)を計算する。
4. 𝑃 𝐷|𝐻𝑖 𝑃 𝐻𝑖 を計算する。
5. 4.で計算した値をベースに正規化定数を求め、事後確率を計算する。
(6. 求めた事後確率をベースにどういう風に判断するかを決める)
3.1. サイコロ問題
箱の中には4面のサイコロ、6面のサイコロ、8面のサイコロ、
12面のサイコロ、20面のサイコロが1つずつ入っている。
Bobは目隠しして箱の中からサイコロを一つとってサイコロを
振る。目隠しを外して出た目を確認したところ、6の目が出て
いた。
Bobが振ったサイコロが4面、6面、8面、12面、20面であった
確率はそれぞれいくつか。
1. 問題を解くのに適した仮説集合 𝐻𝑖 とデータ𝐷を設定する。
𝐻 = 4: 振ったサイコロが4面サイコロだった
𝐻 = 6: 振ったサイコロが6面サイコロだった
𝐻 = 8: 振ったサイコロが8面サイコロだった
𝐻 = 12: 振ったサイコロが12面サイコロだった
𝐻 = 20: 振ったサイコロが20面サイコロだった
数値に依存する仮説を立てるとき、𝐻𝑖という
形式でなく等式チックな形で設定することが多い。
そうすることで確率変数としての意識しやすくなり
正規分布やポワソン分布も導入しやすくなる。
𝐷: 振って出るサイコロの目が6。
2. 文献や経験値などから各仮説に対する事前確率𝑃(𝐻𝑖)を計
算する。
事前確率𝑷(𝑯) 尤度 𝑷(𝑫|𝑯) 𝑷 𝑫 𝑯 𝑷(𝑯) 事後確率𝑷(𝑯|𝑫)
𝐻 = 4 1/5
𝐻 = 6 1/5
𝐻 = 8 1/5
𝐻 = 12 1/5
𝐻 = 20 1/5
特に情報がないので
等確率に設定
3. 尤度計算
事前確率𝑷(𝑯) 尤度 𝑷(𝑫|𝑯) 𝑷 𝑫 𝑯 𝑷(𝑯) 事後確率𝑷(𝑯|𝑫)
𝐻 = 4 1/5 0
𝐻 = 6 1/5 1/6
𝐻 = 8 1/5 1/8
𝐻 = 12 1/5 1/12
𝐻 = 20 1/5 1/20
4.5. 事後確率計算
事前確率𝑷(𝑯) 尤度 𝑷(𝑫|𝑯) 𝑷 𝑫 𝑯 𝑷(𝑯) 事後確率𝑷(𝑯|𝑫)
𝐻 = 4 1/5 0 0 0
𝐻 = 6 1/5 1/6 1/30 20/51
𝐻 = 8 1/5 1/8 1/40 5/17
𝐻 = 12 1/5 1/12 1/60 10/51
𝐻 = 20 1/5 1/20 1/100 2/17
箱の中には4面のサイコロ、6面のサイコロ、8面のサイコロ、
12面のサイコロ、20面のサイコロが1つずつ入っている。
Bobは目隠しして箱の中からサイコロを一つとってサイコロ
を6回振る。Aliceは振った時に出た目を記録をしていく。目
隠しを外してAliceの記録を確認したところ6, 8, 7, 7, 5, 4
だった。
Bobが振ったサイコロが4面、6面、8面、12面、20面であっ
た確率はそれぞれいくつか。プログラムを用いて計算せよ。
Note: サイコロ1回振った時の事後確率を6回計算する方法、とサイコロ6回
一気に振って時の事後確率を1回計算する方法があるがどちらも答えは一緒
(計算誤差を除いては…)
ただ、後者の方がやり様によっては計算時間を劇的に短くすることができる。
3.2. 機関車問題
ある鉄道会社は𝑁台の機関車を所有しており、機関車に1 … 𝑁とい
う番号をつけている。
ある日、60番という機関車を目撃した。
このとき、鉄道会社が所有している機関車の台数𝑁を推測せよ。
この問題にベイズ確率の理論を使って解く。
つまり、事後確率を計算してそれを元に値を推定して
いく!という方針で解く。
(復習)ベイズの定理の考え方に基づいた問題解決手順
1. 問題を解くのに適した仮説集合 𝐻𝑖 とデータ𝐷を設定する
2. 文献や経験値などから各仮説に対する事前確率𝑃(𝐻𝑖)を計算する。
3. 各仮説に対する尤度𝑃(𝐷|𝐻𝑖)を計算する。
6. 求めた事後確率をベースに𝑁を推定する。
1. 問題を解くのに適した仮説集合 𝐻𝑖 とデータ𝐷を設定する。
𝐻 = 𝑛: 所有台数𝑁が𝑛。
𝑛は1以上の自然数!(つまり仮説は無限個!)
𝐷: 60番の機関車を見た。
2. 文献や経験値などから各仮説に対する事前確率𝑃(𝐻𝑖)を計
算する。
事前確率𝑷(𝑯) 尤度 𝑷(𝑫|𝑯) 𝑷 𝑫 𝑯 𝑷(𝑯) 事後確率𝑷(𝑯|𝑫)
𝐻 = 1 1/[𝐻の数]
𝐻 = 2 1/[𝐻の数]
…
𝐻 = 60 1/[𝐻の数]
𝐻 = 61 1/[𝐻の数]
… 𝐻が無限個なので「無情報事前確率」
的な手法は使えない!
ここで事前分布の与え方を少し工夫する。
(1) 𝐻には上限がある、と仮定する。たとえば1000台以上の
車両を保持することはない、と(無理やり)仮定する
(2) すでに知られている統計情報を元に事前分布を与える。
(1)の方法で定めた事前確率を用いて計算。上限を 𝑁0 と
して計算。(ここでは 𝑁0は60より大きい数とする)
事前確率𝑷(𝑯) 尤度 𝑷(𝑫|𝑯) 𝑷 𝑫 𝑯 𝑷(𝑯) 事後確率𝑷(𝑯|𝑫)
𝐻 = 1 1/𝑁0 0
𝐻 = 2 1/𝑁0 0
…
𝐻 = 𝑁0 1/𝑁0 1/𝑁0
𝐻 = 𝑁0 + 1 0 0
…
ここから先は全て0.
電車を見かける確率は
等確率。
事後確率のグラフ
𝑁0の定め方によって事後確率の
分布がかなり異なる
6.求めた事後確率をベースに𝑁を推定する。
これまでは「最頻値(もっとも確率が高かった仮説)」を採択してきたが…
この選択がベストとは限らない。
今回は「事後確率ベースの平均値」を計算し、それを𝑁と推定する。
上限𝑁0 推定値𝑵
𝑁0 = 500 207
𝑁0 = 1000 333
𝑁0 = 2000 551
(2)の方法で定めた事前確率を用いて計算。
「車両保持数はべき乗則に従う」という情報を使う。
◦PMF 𝑥 = 𝑀
1
𝑥
𝛼
◦ 𝑀: 定数, 𝛼: パラメータ(𝛼 < 1, 𝛼は1に近い値が設定される)
情報源はこちら。
http://science.sciencemag.org/content/sci/293/5536/1818.full.pdf
事前確率𝑷(𝑯) 尤度 𝑷(𝑫|𝑯) 𝑷 𝑫 𝑯 𝑷(𝑯) 事後確率𝑷(𝑯|𝑫)
𝐻 = 1 𝑀 1
1
𝛼
0
𝐻 = 2 𝑀 1
2
𝛼
0
…
𝐻 = 𝑁0 𝑀 1
𝑁0
𝛼
1/𝑁0
𝐻 = 𝑁0 + 1 𝑀 1
(𝑁0 + 1)
𝛼
1/(𝑁0+1)
…
事後確率のグラフ
𝛼を0.999として計算。
プログラムの都合上
𝐻 = 500, 1000, 2000までで
打ち切った形で計算する。
6.求めた事後確率をベースに𝑁を推定する。
打ち切り𝐻 推定値𝑵
𝐻 = 500 144
𝐻 = 1000 178
𝐻 = 2000 216
3.2. でわかること
事前確率分布の定め方によって推定値はかなり異なってくること
がある(と言うより事実とは乖離しているのでは?と面輪得る値
も…)。特に無情報事前確率だとそれが顕著に出る。
データが多ければ異なり具合は少なくなるが、少ないデータでも
ある程度しっかりした結果が欲しければ、事前確率をもう少しそ
れらしいものに定めてあげる必要がある。
3.3. 信用区間
事後確率の確率質量関数𝑝 𝑥 の𝜶%の信頼区間とは、実区間[𝑎, 𝑏]
のことである。ただし、
𝑎: 𝐹 𝑎 =
1−𝛼
2
を満たす最小の数値
𝑏: 𝐹 𝑏 =
1+𝛼
2
を満たす最大の数値
を指す。
(𝑝 𝑥 の累積分布関数𝐹(𝑥))
ここについてはThinkBayes3.5信用区間を参照…
3.4. 練習問題
Think Bayes3.9練習問題について考察…
参考文献
http://allendowney.blogspot.jp/2011/10/all-your-bayes-are-
belong-to-us.html
http://allendowney.blogspot.jp/2011/10/my-favorite-bayess-
theorem-problems.html
http://allendowney.blogspot.jp/2011/11/somebody-bet-on-
bayes.html
https://github.com/AllenDowney/ThinkBayes

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
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
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
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...
 

ベイズ統計セミナーVol4

Editor's Notes

  1. 推定値としてベスト、というのを「損失関数を最小にする値」として定める、という理論がある。損失関数の定め方によって「ベストな推定値」は最頻値だったり平均値だったり変わってくる。 下部に計算した推定値を載せている。 このケースだと上限によって推定値が大きく異なっている。