SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
ITエンジニアのための
機械学習理理論論⼊入⾨門
第2章
最⼩小⼆二乗法:
機械学習理理論論の第⼀一歩
2.2  オーバーフィッティングの検出
本章のGoal
オーバーフィッティング
を避け、最適な次数Mを決定
する⽅方法を学びます
2.2  オーバーフィッティングの検出
(おさらい)
「2.1.4  サンプルコードによる確認」では
以下のようなグラフを描くことができました。
2.2.1  トレーニングセットとテストセット
次数Mを9にすると、
与えられたトレーニ
ングセットを完全に
再現でき、平⽅方根
平均⼆二乗誤差を0に
することができた!
完璧だ!
2.2.1  トレーニングセットとテストセット
次数Mを9にすると、
与えられたトレーニ
ングセットを完全に
再現でき、平⽅方根
平均⼆二乗誤差を0に
することができた!
完璧だ!
_⼈人⼈人⼈人⼈人⼈人⼈人⼈人⼈人⼈人⼈人_
> そんなことはない <
 ̄Y^Y^Y^Y^Y^Y^Y ̄
2.2.1  トレーニングセットとテストセット
このデータは、
「たまたまこの時に
得られた値」であり、
次にデータを取得し
た時に同じ値が得ら
れるわけではない。
2.2.1  トレーニングセットとテストセット
このデータは、
「たまたまこの時に
得られた値」であり、
次にデータを取得し
た時に同じ値が得ら
れるわけではない。
実際得られる値はバラバラ
2.2.1  トレーニングセットとテストセット
次数が異異なるグラフを⾒見見⽐比べて、より最適そうな
⽅方はどちらか?を判断すればいいのでしょうか?
M=3っぽいなぁ。
2.2.1  トレーニングセットとテストセット
次数が異異なるグラフを⾒見見⽐比べて、より最適そうな
⽅方はどちらか?を判断すればいいのでしょうか?
_⼈人⼈人⼈人⼈人⼈人⼈人⼈人⼈人⼈人⼈人_
> そんなことはない <
 ̄Y^Y^Y^Y^Y^Y^Y ̄
2.2.1  トレーニングセットとテストセット
次数が異異なるグラフを⾒見見⽐比べて、より最適そうな
⽅方はどちらか?を判断すればいいのでしょうか?
1. 複雑なデータを扱う場合はグラフを書くのが困難。
2. そもそも正解の曲線(下図の点線:  y=sin(2πx))
は誰にもわかっていない。
2.2.1  トレーニングセットとテストセット
ここで重要になってくるのが、仮説と検証。
現実的にはデータは限られているので、利利⽤用可能
なすべてのデータをトレーニングセットとテスト
セットに分けておく。
仮説
トレーニングセット
検証
テストセット
学習結果
機械学習を実施
学習結果を評価
2.2.2  テストセットによる検証結果
2.2.2  テストセットによる検証結果
トレーニングセットは
次数を⼤大きくするほど
誤差が減少する。
テストセットは
ある次数から誤差
が減少しない。
(モデルの汎化能
⼒力力は⾼高まらない)
2.2.2  テストセットによる検証結果
トレーニングセットは
次数を⼤大きくするほど
誤差が減少する。
テストセットは
ある次数から誤差
が減少しない。
(モデルの汎化能
⼒力力は⾼高まらない)
トレーニングセット
だけに特化した最適化
が⾏行行われる状況を
オーバーフィッティング
(過学習)と呼ぶ。
2.2.3  クロスバリデーションによる汎化能⼒力力の検証
1. 前ページのグラフから、M=4あたりでオーバー
フィッティングが発⽣生している事がわかる。
M=4であたりからオー
バーフィッティングが
発⽣生しはじめている。
2.2.3  クロスバリデーションによる汎化能⼒力力の検証
1. 前ページのグラフから、M=4あたりでオーバー
フィッティングが発⽣生している事がわかる。
2. トレーニングセットがあればあるほど精度度は⾼高
まるが、現実的にはなかなかそうもいかないこ
とが多い。
2.2.3  クロスバリデーションによる汎化能⼒力力の検証
1. 前ページのグラフから、M=4あたりでオーバー
フィッティングが発⽣生している事がわかる。
2. トレーニングセットがあればあるほど精度度は⾼高
まるが、現実的にはなかなかそうもいかないこ
とが多い。
3. 機械学習で重要なことは、トレーニングセット
に含まれるデータをテストセットに混ぜて使⽤用
してはいけない。これは全く意味が無い。
2.2.3  クロスバリデーションによる汎化能⼒力力の検証
検証対象のデータ量量が少なく、データの
選び⽅方によって⼤大きな誤差が⽣生じる可能性が
ある場合には、貴重なデータを無駄なく
使いつつ、適切切な検証を⾏行行うことができる
クロスバリデーション(交差検証)法を⽤用いる。
ちなみに、サンプルプログラムのように
データが⼤大量量に⽤用意できる場合の⼿手法は
テストサンプル法と呼ぶ。
2.2.3  クロスバリデーションによる汎化能⼒力力の検証
クロスバリデーション法について
クロスバリデーション法の⼿手順
1. 元のデータをn個のブロックに分ける。 (サンプル数に対して適切切に決める)
2. 各ブロックに含まれるデータ量量は同程度度になるように調整する。
3. 各ブロックは層化されていることが望ましい。
1
2
3
n
・
・
・
1
2
3
n
・
・
・
1
2
3
n
・
・
・
1
2
3
n
・
・
・
・・・
1回目 2回目 3回目 n回目
クロスバリデーション法について
4. 1つ⽬目のブロックをテストデータ、それ以外をトレーニングデータ
としてモデルの構築と精度度の算出する。
5. 次に2つ⽬目のブロックを(同上。 (これをnブロック⽬目まで繰り返す。)
6. 最後に各回の精度度の平均を、モデルの推定精度度とする。
1
2
3
n
・
・
・
1
2
3
n
・
・
・
1
2
3
n
・
・
・
1
2
3
n
・
・
・
・・・
1回目 2回目 3回目 n回目
精度1 精度2 精度3 精度n 推定精度
平均
クロスバリデーション法について
ここでn回⽬目に構築された決定⽊木(データセット)を とし、
その精度度を とすると、
交差検証による推定精度度 は次の式で与えられる。
層化 (Stratification)
クロスバリデーション法でもテストサンプル
法でも、元データを分割する場合には層化
(Stratification)を⾏行行う。
層化とは、元データからサンプリングをする
際にサンプリングデータの分布が元データと
同じになるようにすること。
2.2.4  データ数によるオーバーフィッティングの変化
例例題では、トレーニングセットのNが10
なのでパラメータ数が10個以上あれば
すべてのデータを正確に再現できる。
(これがオーバーフィッティング)
Nを増やせば過学習
しないんじゃない?
2.2.4  データ数によるオーバーフィッティングの変化
#------------#
# Parameters #
#------------#
N=10 # サンプルを取得する位置 x の個数
M=[0,1,3,9] # 多項式の次数
02-­‐square_error.py	
  	
  	
  15行目から19行目
例えば100にしてみる。
2.2.4  データ数によるオーバーフィッティングの変化
だいたい⼀一緒!
2.2.4  データ数によるオーバーフィッティングの変化
トレーニング
セットの誤差が
減少していない!
まとめ
1. 機械学習は与えられたデータに基いて最適な
パラメータを決定する仕組み。
2. 得られた結果が「未来の値を予測する」こと
に役⽴立立つかどうかが重要。
3. 検証対象の元データが少ない場合はクロスバ
リデーション法により効率率率よく精度度を⾼高める。
4. データ数が多ければ多いほどオーバーフィッ
ティングは起こりにくく、精度度は⾼高まる。

Weitere ähnliche Inhalte

Empfohlen

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
 

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

Ml4se 2 2_slideshare