๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
TIL/Coursera(Google ML Bootcamp)

[Structuring Machine Learning Projects] ML Strategy 2 :: seoftware

by seowit 2021. 9. 13.

๐Ÿ“œ ๊ฐ•์˜ ์ •๋ฆฌ 

 

* Coursera ๊ฐ•์˜ ์ค‘ Andrew Ng ๊ต์ˆ˜๋‹˜์˜ Structuring Machine Learning Projects ๊ฐ•์˜๋ฅผ ๊ณต๋ถ€ํ•˜๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

* ์ด๋ฏธ์ง€ ์ถœ์ฒ˜ : Deeplearning.AI


Error Anaylsis

1. Carrying out Error Anaylsis

๊ณ ์–‘์ด ๋ถ„๋ฅ˜ ๋ฐ์ดํ„ฐ์…‹์— ๊ฐ•์•„์ง€ ์‚ฌ์ง„, great cat(์น˜ํƒ€, ํ‘œ๋ฒ”, ํ˜ธ๋ž‘์ด ๋“ฑ) ์‚ฌ์ง„, ํ๋ฆฟํ•œ ์‚ฌ์ง„๋“ฑ์ด ์„ž์—ฌ์žˆ๋‹ค๊ณ  ํ•˜๋ฉด ํ•™์Šต ์„ฑ๋Šฅ์„ ๋Œ์–ด์˜ฌ๋ฆฌ๋Š”๋ฐ ๋ฐฉํ•ด๊ฐ€ ๋  ๊ฒƒ์ด๋‹ค. ๊ทธ๋ ‡๋‹ค๊ณ  ๋ชจ๋“  ๋ฐ์ดํ„ฐ์˜ ์—๋Ÿฌ๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๊ฑด ์‰ฝ์ง€ ์•Š๋‹ค. ๋”ฐ๋ผ์„œ 100๊ฐœ ์ •๋„์˜ ๋ฐ์ดํ„ฐ์…‹์„ ๋ฝ‘๊ณ  ์•„๋ž˜์™€ ๊ฐ™์€ ํ‘œ์— ์ •๋ฆฌ๋ฅผ ํ•ด์„œ ๋ช‡ ํผ์„ผํŠธ๊ฐ€ ์˜ค๋ฅ˜๊ฐ€ ์žˆ๋Š” ๋ฐ์ดํ„ฐ์…‹์ธ์ง€ ํ™•์ธํ•œ๋‹ค.

 

2.  Cleaning up Incorrectly Labeled Data

๊ทธ๋ ‡๋‹ค๋ฉด ์ž˜๋ชป ๋ผ๋ฒจ๋ง๋œ ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ๋Š” ์–ด๋–ป๊ฒŒ ํ•ด์•ผ๋ ๊นŒ?

๋งŒ์•ฝ ์ž˜๋ชป ๋ผ๋ฒจ๋ง๋œ ๊ฒƒ์ด training set์— ์†ํ•˜๊ณ , ๊ทธ ๋น„์œจ์ด ํฌ์ง€ ์•Š๋‹ค๋ฉด ๊ทธ๋ƒฅ ๋‘ฌ๋„ ๋œ๋‹ค(๋ฌผ๋ก  ์ˆ˜์ •ํ•˜๋ฉด ์ข‹์ง€๋งŒ). ๋”ฅ๋Ÿฌ๋‹ ๋ชจ๋ธ์€ Random error์— robustํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ systematic error์—๋Š” ์•ฝํ•˜๋ฏ€๋กœ ์ฃผ์˜ํ•ด์•ผํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ํฐ ๊ฐ•์•„์ง€์— ๋Œ€ํ•ด ๊ณ„์† 1๋กœ ๋ผ๋ฒจ๋งํ–ˆ๋‹ค๋ฉด ํฐ ๊ฐ•์•„์ง€๋ฅผ ๊ณ ์–‘์ด๋กœ ๋ถ„๋ฅ˜ํ•˜๊ฒŒ ๋œ๋‹ค.

 

1์—์„œ ์–˜๊ธฐํ–ˆ๋˜ ๊ฒƒ์ฒ˜๋Ÿผ Analysis ํ‘œ๋ฅผ ๊ทธ๋ ค๋ณด๊ณ  ์–ด๋–ค ์˜ค๋ฅ˜๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์ด ์—๋Ÿฌ๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋Š”์ง€ ๋ถ„์„ํ•˜๋Š” ๊ณผ์ •์ด ํ•„์š”ํ•˜๋‹ค

์œ„์˜ ์˜ˆ์‹œ๋ฅผ ๋ณด๋ฉด ์—๋Ÿฌ๊ฐ€ 10% ์ผ ๋•Œ๋Š” ๋ผ๋ฒจ๋ง ์ž˜๋ชป๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ๊ทธ ์™ธ์˜ ๊ฒƒ์„ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹์•„๋ณด์ธ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์—๋Ÿฌ๊ฐ€ 2%๊ฐ€ ๋ผ์—ˆ์„ ๋•Œ๋Š” 0.6%๋„ ํฐ ์ˆ˜์น˜์ด๋ฏ€๋กœ ์ž˜๋ชป ๋ผ๋ฒจ๋ง๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์ด ์˜๋ฏธ ์žˆ์–ด์ง„๋‹ค.

โœ” Guideline to correct incorrect dev/test set examples

  1. ์–ด๋–ค ๋ฐฉ์‹์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ ์šฉํ•˜๋˜ dev/test set์— ๋™์ผํ•˜๊ฒŒ ์ ์šฉํ•  ๊ฒƒ
  2. ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ž˜ ๋งž์ถ˜ ๊ฒƒ๋“ค์„ ํฌํ•จํ•ด์„œ ํ‹€๋ฆฐ examples์— ๋Œ€ํ•ด ์‚ดํŽด๋ณผ ๊ฒƒ. ํ‹€๋ฆฐ example์„ ๋ณด๊ณ  ๊ณ ์น˜๋Š” ๊ฒƒ์€ ์‰ฝ๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ํ‹€๋ฆฐ ๊ฒƒ๋งŒ ๊ณ ์น˜๊ฒŒ ๋˜๋ฉด bias estimate์™€ ์˜ค๋ฅ˜๊ฐ€ ๋‚จ๋Š”๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋‹จ์ˆœํžˆ ์šด์œผ๋กœ ๋งž์ถ˜ ๊ฒƒ๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋งž์€ ๊ฒƒ๋„ ๋ด์•ผํ•œ๋‹ค.
  3. Train dataset ๊ณผ Dev/Test dataset์˜ ๋ถ„ํฌ๋Š” ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค.

 

3. Build your First System quickly, then Iterate

์ƒˆ๋กœ์šด ๋จธ์‹ ๋Ÿฌ๋‹ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค๋•Œ๋Š” ์ฒซ๋ฒˆ์งธ ์‹œ์Šคํ…œ์„ ๋น ๋ฅด๊ฒŒ ๋งŒ๋“ค๊ณ  ๋ฐ˜๋ณต ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ผ! 

 

Mismatched Training and Dev/Test set

1. Training and Testing on Different Distributions

Training set์—๋Š” ์šฐ๋ฆฌ๊ฐ€ ๋ชฉํ‘œ๋กœ ํ•˜๋Š” ๋ฐ์ดํ„ฐ์…‹ ๋ง๊ณ ๋„ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋‹ค. ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋‚˜์˜ค๋Š” ์ด๋ฏธ์ง€๋‚˜ ์Œ์„ฑ ๊ฐ™์€ ๊ฒƒ์€ Dev/Test set์— ๋„ฃ์–ด์ฃผ๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์งํ•˜๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ์ž˜ ๋งž์ถ”๊ณ  ์‹ถ์€ ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ฌ์šฉ์ž ๋ฐ์ดํ„ฐ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. Dev/Test์— ๋„ฃ์–ด์ฃผ๊ณ  ๋‚จ์€ ๊ฒƒ์„ Train set์— ํฌํ•จํ•œ๋‹ค. 

 

2. Bias and Variance with Mismatched Data Distributions

์œ„์—์„œ Train set ๊ณผ Dev/Test set์˜ ๋ถ„ํฌ๊ฐ€ ๋‹ฌ๋ผ์ง€๋Š” ๊ฒฝ์šฐ์— ๋Œ€ํ•ด์„œ ๋ดค๋‹ค. Train set๊ณผ Dev/Test set์˜ ๋ถ„ํฌ๊ฐ€ ๋‹ฌ๋ผ์ง€๊ฒŒ ๋˜๋ฉด Bias์™€ Variance๋ฅผ ๋ถ„์„ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ๋‹ฌ๋ผ์ง„๋‹ค.

Train๊ณผ Dev/Test set์˜ distribution์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ Training-dev set์„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. Training-dev set์€ training set์—์„œ shuffleํ•˜์—ฌ ๋žœ๋คํ•˜๊ฒŒ ๋ฝ‘์€ ๊ฐ’์„ dev์šฉ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด Training error์™€ Dev error์˜ ์ฐจ์ด(variance)๊ฐ€ ๋ถ„ํฌ์˜ ์ฐจ์ด์—์„œ ์˜ค๋Š” ์—๋Ÿฌ์ธ์ง€(dev๊ฐ€ ๋” ํ๋ฆฌ๊ณ  ์ €ํ™”์งˆ์ธ ์‚ฌ์šฉ์ž๊ฐ€ ๋„ฃ์–ด์ค€ ์‚ฌ์ง„์ด๋ผ๊ณ  ๊ฐ€์ •)  Overfitting์œผ๋กœ ์ธํ•ด ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์ธ์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 

โœ” ์˜ˆ์‹œ

  • case 1. Train error : 1%, Train-dev error : 9%, Dev error : 10% → Variance problem(overfitting)
  • case 2. Train error : 1%, Train-dev error : 1.5%, Dev error : 10%  → Data mismatch problem

 

์ผ๋ฐ˜ํ™”ํ•˜์—ฌ ๋„์‹ํ™”ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

3. Addressing Data mismatch

bias์™€ variance์— ๋Œ€ํ•œ ์˜ค๋ฅ˜๋ถ„์„ ๋ฐ ํ•ด๊ฒฐ์ฑ…์— ๋Œ€ํ•ด์„œ๋Š” ์ง€๋‚œ ์ •๋ฆฌ ๋•Œ ํ–ˆ์—ˆ๋‹ค. Data mismatch ๋Œ€ํ•œ ๋ฌธ์ œ ํ•ด๊ฒฐ์ฑ…์€ ๋ฌด์—‡์ด ์žˆ์„๊นŒ? → ์˜ค๋ฅ˜๋ถ„์„

Dev set์— ๋Œ€ํ•œ ๋ฌธ์ œ๋ฅผ ๋ถ„์„ํ•˜๊ณ  Train set๊ณผ ๋‹ค๋ฅธ ํŠน์„ฑ ํŒŒ์•…ํ•˜๊ณ  Train set์„ Dev set๊ณผ ์œ ์‚ฌํ•˜๊ฒŒ ๋ณ€ํ˜•ํ•˜๊ธฐ. ๋˜๋Š” Dev set๊ณผ ๋น„์Šทํ•œ ๋ฐ์ดํ„ฐ์…‹ ์ˆ˜์ง‘ํ•˜๊ธฐ. ๋˜๋Š” ์ธ๊ณต ๋ฐ์ดํ„ฐ ํ•ฉ์„ฑ(Artificial Data synthesis)

 

Learning from Multiple Tasks

1. Transfer Learning

๋”ฅ๋Ÿฌ๋‹์˜ ๊ฐ•์  ์ค‘ ํ•˜๋‚˜๋Š” ํ•œ ํƒœ์Šคํฌ์—์„œ ํ•™์Šตํ•œ ๊ฒƒ์„ ๋‹ค๋ฅธ ํƒœ์Šคํฌ์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์ด๋‹ค. ์ด๊ฒƒ์ด Transfer learning(์ „์ดํ•™์Šต)์ด๋‹ค.

  • pre_training : ๋ฐ์ดํ„ฐ ๊ฐœ์ˆ˜๊ฐ€ ๋งŽ์€ ๊ฒฝ์šฐ weight initialize๋ฅผ pre_tranied ๋œ ๊ฐ’์œผ๋กœ ์„ค์ •ํ•˜๊ณ , ์ „์ฒด layer์— ๋Œ€ํ•œ ํ•™์Šต์„ ์ง„ํ–‰ํ•œ๋‹ค.
  • fine-tunning : ๋ฐ์ดํ„ฐ์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ ์€ ๊ฒฝ์šฐ ๋งˆ์ง€๋ง‰ classification layer์˜ weight๋งŒ ํ•™์Šต์„ ์ง„ํ–‰ํ•˜๊ณ , ์•ž ๋ถ€๋ถ„์˜ feature extraction layer๋Š” ํ•™์Šต์„ ํ•˜์ง€ ์•Š๋Š”๋‹ค.

Transfer learning์ด ํšจ๊ณผ์ ์ธ ์ด์œ ๋Š” ๋Œ€์šฉ๋Ÿ‰์˜ ์ด๋ฏธ์ง€์—์„œ feature๋ฅผ ํ•™์Šตํ•œ ๊ฐ€์ค‘์น˜๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋Œ€์šฉ๋Ÿ‰์˜ ์ด๋ฏธ์ง€์—์„œ ์„ ๋ถ„, ์  ๋“ฑ์˜ feature๋ฅผ ํ•™์Šตํ•œ ๊ฑธ ์ ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

Transfer learning์„ ํ•˜๊ธฐ์œ„ํ•œ ์กฐ๊ฑด์€ pre_trained์— ์‚ฌ์šฉํ•œ ๋ฐ์ดํ„ฐ์˜ ํฌ๊ธฐ๊ฐ€ transfer learning์„ ํ•˜๋ ค๊ณ  ํ•˜๋Š” ๋ฐ์ดํ„ฐ ํฌ๊ธฐ๋ณด๋‹ค ์ปค์•ผํ•œ๋‹ค. image์˜ ๊ฒฝ์šฐ์—๋Š” class์˜ ๊ฐœ์ˆ˜์ด๊ณ , ์Œ์„ฑ์˜ ๊ฒฝ์šฐ์—๋Š” ์‹œ๊ฐ„์ด๋‹ค. 

 

2. Multi-task Learning

transfer learning์€ ํƒœ์Šคํฌ ๊ฐ„์˜ sequantialํ•œ ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ๋ฐ˜๋ฉด์—, Multi-task learning์€ ๋™์‹œ์— ์‹œ์ž‘ํ•œ๋‹ค.

Computer vision object detection์„ ์ œ์™ธํ•˜๊ณ ๋Š” transfer learning์ด multi-task learning๋ณด๋‹ค ํ›จ์”ฌ ๋งŽ์ด ์‚ฌ์šฉ๋œ๋‹ค.

 

End-to-end Deep Learning

1. What is end-to-end Deep Learning?

์Œ์„ฑ ์ธ์‹๊ณผ ๊ฐ™์€ ์˜ˆ์‹œ์—์„œ ์ „ํ†ต์ ์ธ ๋ฐฉ๋ฒ•์€ ์œ„์˜ ๋ฐฉ์‹๋Œ€๋กœ feature๋ฅผ ๋ฝ‘์•„๋‚ด๊ณ  ์Œ์†Œํ™”๋ฅผ ์ง„ํ–‰ํ•˜์—ฌ ๋‹จ์–ด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ตœ์ข… ๋ฒˆ์—ญ์„ ํ•˜๋Š” ๊ฒƒ์ด์—ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ง€๊ธˆ์€ ์ธํ’‹๊ณผ ์•„์›ƒํ’‹๋งŒ ์žˆ์„ ๋ฟ์ด๋‹ค. ๋‹ค๋งŒ ๋งŽ์€ ๋ฐ์ดํ„ฐ๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ์ง€๊ธˆ๋„ ์ ์€ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด์„œ๋Š” ์ „ํ†ต์ ์ธ ๋ฐฉ์‹์ด ๋” ์ž˜ ์ž‘๋™ํ•œ๋‹ค.

๋Œ“๊ธ€