SlideShare a Scribd company logo
Ch7. Liner Regression
Ch8. Logistic Regression
MLaPP輪講
2015/08/25
そもそも回帰とは?
2つの変数の相関に基づいて予測する方法
例(1.2.2)
市場の状態から明日の株価の予測
YouTubeの閲覧履歴から年齢を予測
制御信号からロボットアームの手先位置推定
幾つかの診療基準から前立腺癌(の指標)を予測
天気、時間、ドアセンサからある部屋の室温を推定
未来や直接扱えないデータを扱えるようになる!
By Wikipedia
線形回帰? ロジスティック回帰?
線形回帰
• 変数の相関関係が線形
• 例:最小二乗法
ロジスティック回帰
• ある値を境に出力が変化
線形回帰
Figure.7.2(a)
ロジスティック回帰
Figure 1.19(b)
目次:Ch7
1. Introduction
2. Model specification
3. Maximum likelihood estimation (least
squares)
4. Robust liner regression
5. Ridge regression
6. Bayesian liner regression
7.1 Introduction
• 線形回帰は統計学や(教師あり)機械学習
の”馬車馬”!!
– 単純なのにうまく説明できる
• カーネルや基底関数を拡張すると、非線
形なモデルも扱うことができる
• Gaussian outputをベルヌーイやマルチ
ヌーイ分布に書き直すことができ、分類
問題を扱える
7.2 Model specification
• 線形回帰は次式のようなモデル(1.4.5)
Chapter 1 に
チラッとでてた!
7.2 Model specification
• 線形回帰は次式のようなモデル(1.4.5節)
• xの代わりに非線形関数のφ(x)を使うことも!!
– 基底関数の拡張と呼ばれている
• 線形パラメータwを含むので、これはまだ線形回帰
その話はまた後で。。。
ここで
(7.1)
(7.2)
(7.3)
7.2 Model specification
(7.2)
(7.3)
• dを増加させることで複雑な関数を作れる
– Figure 1.18は(7.3)式のdを変化させている
Figure. 1.18
7.2 Model specification
• 多入力でも回帰できる
– 重回帰モデル
• Figure7.1は2入力の例
• 最大尤度推定(MLE)=最小二乗法
• 超有名手法、線形回帰といえば最小二乗!
• 定義式:
• 訓練データは一様分布(iid)を仮定すると、
対数尤度を次式の様にかける
• そうすると最大対数尤度を負の対数尤度最
小化問題(NLL)として解くことができる
7.3 最大尤度推定(最小二乗法)
7.3 最大尤度推定(最小二乗法)
• NLLは時々便利!
– 最小化問題を解く最適化プログラムが多い
• 対数尤度の式にガウス分布を仮定する
7.3 最大尤度推定(最小二乗法)
• RSS:残差二乗和、SSE(Sum of
Squared Error)
• SSE/N:平均二乗誤差、MSE(Mean
Squared Error)
• l2の残差の二乗として書くこともできる
– wのMLEはRSSの最小化->最小二乗法
7.3 最大尤度推定(最小二乗法)
• (a)
– 赤丸:訓練データ
– 青バツ:推定値
– 青線:推定誤差
• (b)線形回帰のNLL平面
青破線からデータを生成して訓練
データに用いる
回帰直線を予測
回帰直線を使って
x軸からy軸を推定
実値-推定値で誤差を算出
誤差の二乗和が小さくなる回帰式を再度算出
7.3.1 MLEの導出
• NLLを識別に適した形式に書き換える
(二乗和行列)
4.10式より勾配は次式で与えられる(切片と傾きについて偏微分)
g(w)=0とすると
(正規方程式)
wについて解くと、通常の最小二乗(OLS)を得る
7.4 ロバスト線形回帰
• 一般的な回帰モデルにはガウス分布を用いる
– 誤差が直接影響するため回帰直線から離れた点
は影響力大->外れ値に弱い
• 外れ値に強いモデルを使って見る
– 裾の重い(heavy tail)分布を用いる
Table 7.1
7.4 ロバスト線形回帰
• 例:ラプラス分布
– 尤度:
Figure 2.7を改変
7.4 ロバスト線形回帰
7.5 リッジ回帰
• 最尤推定はoverfittingしやすい
– ガウス事前分布のMAP推定で解決を試みる
– ガウス尤度はロバスト尤度より扱いやすい
• Overfittingしやすいのは次数を増やせば
誤差を小さくすることができるから
– 7.2 節参照
– リッジ回帰は「モデルの次数が増えるとペナ
ルティを課そう」という考え
7.5.1Basic idea
• 事前分布:
• MAP推定問題
最尤推定の項 罰則項
次式の最小化と等価
Wは次式で与えられる
7.6 ベイズ線形回帰
• リッジ回帰は点推定だった
– wやσ2の完全な事後分布を知りたい時もあるよね
– 最初に分散は既知だと仮定して計算
• 次式に着目
– ガウス尤度モデルを仮定
• ロバスト尤度モデルを扱うこともできるが、難しい
Ch7 まとめ
• 最小二乗法:残差二乗和を最小化
• ロバスト線形回帰:外れ値に対応
• リッジ回帰
• ベイズ線形回帰
最尤推定の項 罰則項
最小二乗法 ロバスト
線形回帰
リッジ回帰 ベイズ線形回帰
目的 最大尤度の推定 外れ値に対応 過剰適合の改善 パラメータの事
後分布を求める
手法 残差二乗和を
最小化
裾の広いモデル
で回帰
MAP推定を使う ベイズ推定
(名前の通り)
目次:Ch8
1. Introduction
2. Model specification
3. Model fitting
4. Bayesian logistic regression
5. Online learning and stochastic
optimization
6. Generative vs discriminative
classifiers
8.1 Introduction
• 識別モデルについてのアプローチ
• 生成モデルと比較して直接的に直接的に
p(y|x)をモデル化
– 識別的アプローチと呼ばれる
8.2 Model specification
• ロジスティック回帰は次式のバイナリ分
類モデルに対応
8.3 Model fitting
8.4 Bayesian logistic regression
8.5 Online learning and
stochastic optimization
8.6 Generative vs discriminative
classifiers
Ch8 まとめ
Ch7,Ch8まとめ
• 線形回帰
– 訓練データは一様分布を仮定
– 負の対数尤度の最小化問題を解く!
残差2乗和を最小化
– ロバスト線形回帰、リッジ回帰、ベイズ線形
回帰
• ロジスティック回帰
– 識別問題を取り上げた
– シグモイド関数を利用
– MLE、最急勾配法、(準)ニュートン法、多ク
ラス、ベイズ

More Related Content

Featured

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
ThinkNow
 
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
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
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
Neil 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 2024
Albert 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 Insights
Kurio // 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 2024
Search 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 summary
SpeakerHub
 
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 Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit 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 management
MindGenius
 
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 Work
GetSmarter
 

Featured (20)

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...
 
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
 

MlaPP 7章 「線形回帰」 8章 「ロジスティック回帰」

Editor's Notes

  1. MLaPP 1.2.2 Regression参照
  2. MLaPP 1.4.5Liner regression および1.4.6 Logistic regression参照
  3. Model Specification : モデル定式化 参照URL:http://www.slideshare.net/ryuhmd/mlapp-chapter-1
  4. 正規分布のパラメータxを非線形関数ファイxにして扱うこともできる。 Basic functionの拡張ということで知られているが、wが線形なので線形回帰。
  5. 入力変数Xの次元を増加させると複雑なモデルに対応できる
  6. 入力変数は多入力でも回帰できる。 左図は2変数1次式、右図は2変数2次式。W_0は1変数での切片と同じ役割。
  7. 上限の無い最大化問題は解きにくく、対数の最小化問題は解が得られる!->-log(x) =1/log(x)だから、0以下にならない!
  8. \ell (\boldsymbol{\theta}) &=& \sum ^{N}_{i=1} \log \left[ \left( \frac{1}{2\pi \sigma ^2} \right) ^{\frac{1}{2}} \exp \left( -\frac{1}{2\sigma ^2} (y_i - \bold{w}^{\rm T} \bold{x}_i ) ^2 \right) \right] \\ &=& \sum ^{N}_{i=1} \left[ \left( -\frac{1}{2\sigma ^2} (y_i - \bold{w}^{\rm T} \bold{x}_i ) ^2 \right) - \frac{1}{2} \log \left( 2\pi \sigma ^2 \right) \right] \\ &=& \frac{-1}{2\sigma ^2} RSS(\bold{w}) - \frac{N}{2} \log (2 \pi \sigma ^2)\\ RSS(\bold{w}) &\triangleq& \sum ^{N}_{i=1}(y_i - \bold{w}^{\rm T} \bold{x}_i)^2
  9. RSS(\bold {w}) = || \epsilon || ^2_2 = \sum ^{N}_{i=1} \epsilon ^2 _{i} \\ {\rm wehre} \hspace{0.5em}\epsilon _i = (y_i - \bold{w}^{\rm T} \bold{x}_i)
  10. 幾何学的解法、凸関数については割愛 NLL(\bold{w} ) = \frac{1}{2} (\bold{y – X w}) ^{T} (\bold{y – X w) = \frac{1}{2} \bold{w}^{T} (\bold{X ^{T} X})\bold{w} - \bold{w}^{T} (\bold{X^{T}y}) NLL(\bold{w} ) = \frac{1}{2} (\bold{y - X w})^{T} (\bold{y - X w}) = \frac{1}{2} \bold{w}^{T} (\bold{X}^{T} \bold{X}})\bold{w} - \bold{w}^{T} (\bold{X}^{T}\bold{y}) {\rm where} \hspace{0.5em} \bold{X}^{T} \bold{X} = \sum ^{N}_{i=1} x_i x_i^{T} = \sum ^{N}_{i=1} \begin{bmatrix}x^2_{i,1} & \cdots &x_{i,1}x_{i,D} \\& \ddots & \\ x_{i,D}x_{i,1} & \cdots &x^2_{i,D} \end{bmatrix} \bold{g}(\bold{w}) = [\bold{X}^{T}\bold{Xw}-\bold{X}^{T}\bold{y}] = \sum ^{N}_{i=1} \bold{x}_i (\bold{w}^{T} \bold{x}_i - y_i) \widehat{\bold{w}}_{\rm OLS} =(\bold{X}^{T} \bold{X})^{-1}\bold{X}^{T}\bold{y}
  11. 参照:http://www.yukms.com/biostat/haga/download/archive/likelihood/Likelihood.pdf
  12. ラプラス分布とかt分布とか
  13. λがモデル複雑性を左右し、スムージングの役割を果たす。 p(w) = \prod_j \mathcal{N} (w_j | 0,\tau ^2) \newcommand{\argmax}{\mathop{\rm arg~max}\limits} \argmax_{\bold w} \sum ^{N}_{i=1} \log \mathcal{N}(y_i | w_0 + \bold{w}^{T}\bold{x}_i ,\sigma ^2) + \sum ^{D}_{j=1} \log \mathcal{N}(w_j | 0,\tau ^2) J(\bold{w}) = \frac{1}{N} \sum ^{N}_{i=1}(y_i -(w_0 + \bold{w}^{T} \bold{x}_i))^2 + \lamda || \bold{w} ||^2_{2} {\rm where} \lambda 􏰥\triangleq \sigma^2/\tau^2 \hspace{0.5em}{\rm and}\hspace{0.3em} ||\bold{w}||^2_2 = 􏰀 \sum _{j}w^2_j = \bold{w}^T \bold{w}
  14. 入力に集中した場合、各jで=0なので、出力の平均値は、正または負である可能性が等しい。 そこで私たちは、フォームp(μ)のμに不適切な事前分布を置いてみる、その上で、次式を取得するためにそれを統合します p(\bold{y}|\bold{X},\bold{w},\mu,\sigma^2) &=& \mathcal{N}(\bold{y}|\mu+\bold{Xw},\sigma^2 \bold{I}_N)\\ &\propto& \exp \left(-\frac{1}{2\sigma^2}(\bold{y}-\mu\bold{1}_{N})^{T}(\bold{y}-\mu\bold{1}_{N} -\bold{Xw})\right)
  15. 最小二乗法の目的は最大尤度を推定すること->残差二乗和を最小化することで解決