๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Machine Learning/Azure ML

Azure Machine Learning

๋ฐ˜์‘ํ˜•

Azure ์ฒดํ—˜ ๊ณ„์ • ๊ฐ€์ž…ํ•จ : 12๊ฐœ์›” ์ธ๊ธฐ๋ฌด๋ฃŒ + 30์ผ ํฌ๋ ˆ๋”ง \224,930

 

12๊ฐœ์›” ๋ฌด๋ฃŒ ์ œํ’ˆ

 

ํ•ญ์ƒ ๋ฌด๋ฃŒ? ์ œํ’ˆ

 

Azure Machine Learning ์„œ๋น„์Šค ์„ค๋ช…์„œ

https://docs.microsoft.com/ko-kr/azure/machine-learning/service/

Azure Machine Learning ์„œ๋น„์Šค ์„ค๋ช…์„œ - ์ž์Šต์„œ, API ์ฐธ์กฐ

Azure Machine Learning Service๋Š” ์‹ ์†ํ•˜๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ์ค€๋น„ํ•˜๊ณ , ๊ธฐ๊ณ„ ํ•™์Šต ๋ชจ๋ธ์„ ํ•™์Šต ๋ฐ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋Š” SDK ๋ฐ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ž๋™ ํฌ๊ธฐ ์กฐ์ • ์ปดํ“จํŒ… ๋ฐ ํŒŒ์ดํ”„๋ผ์ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ์‚ฐ์„ฑ์„ ๊ฐœ์„ ํ•˜๊ณ  ๋น„์šฉ์„ ์ค„์ด์„ธ์š”. PyTorch, TensorFlow ๋ฐ scikit-learn๊ณผ ๊ฐ™์€ ์˜คํ”ˆ ์†Œ์Šค Python ํ”„๋ ˆ์ž„์›Œํฌ์™€ ํ•จ๊ป˜ ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์„ธ์š”. ๋น ๋ฅธ ์‹œ์ž‘ ๋ฐ ์ž์Šต์„œ๋ฅผ ์‹œ์ž‘ํ•ด ๋ณด์„ธ์š”.

docs.microsoft.com

Azure Machine Learning Service

- ์‹ ์†ํ•˜๊ฒŒ ๋ฐ์ดํ„ฐ ์ค€๋น„, ๊ธฐ๊ณ„ ํ•™์Šต ๋ชจ๋ธ์„ ํ•™์Šต ๋ฐ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋Š” SDK ๋ฐ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณต

- ์ž๋™ ํฌ๊ธฐ ์กฐ์ • ์ปดํ“จํŒ… ๋ฐ ํŒŒ์ดํ”„๋ผ์ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ์‚ฐ์„ฑ์„ ๊ฐœ์„ 

- PyTorch, TensorFlow ๋ฐ scikit-learn๊ณผ ๊ฐ™์€ ์˜คํ”ˆ ์†Œ์Šค Python ํ”„๋ ˆ์ž„์›Œํฌ์™€ ํ•จ๊ป˜ ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

 

https://portal.azure.com

Microsoft Azure์— ๋กœ๊ทธ์ธ

๋กœ๊ทธ์ธ Microsoft Azure(์œผ)๋กœ ๊ณ„์† ๊ณ„์ •์ด ์—†์œผ์‹ญ๋‹ˆ๊นŒ? ์ƒˆ๋กœ ๋งŒ๋“œ์„ธ์š”! ๋ณธ์ธ ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๊นŒ? ©2019 Microsoft ์‚ฌ์šฉ ์•ฝ๊ด€ ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ

portal.azure.com

* Azure Portal์— ๋กœ๊ทธ์ธ ํ›„ [+ ๋ฆฌ์†Œ์Šค ๋งŒ๋“ค๊ธฐ] -> Machine Learning service workspace (Machine Learning ์„œ๋น„์Šค ์ž‘์—… ์˜์—ญ) -> ๋งŒ๋“ค๊ธฐ

 

ํ•„๋“œ

์„ค๋ช…

์ž‘์—… ์˜์—ญ ์ด๋ฆ„

์ž‘์—… ์˜์—ญ์„ ์‹๋ณ„ํ•˜๋Š” ๊ณ ์œ ํ•œ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. ์ด ์˜ˆ์ œ์—์„œ๋Š” docs-ws๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฆ„์€ ๋ฆฌ์†Œ์Šค ๊ทธ๋ฃน ์ „์ฒด์—์„œ ๊ณ ์œ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๊ฐ€ ๋งŒ๋“  ์ž‘์—… ์˜์—ญ๊ณผ ๊ตฌ๋ณ„๋˜๊ณ  ๊ธฐ์–ตํ•˜๊ธฐ ์‰ฌ์šด ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜์„ธ์š”.

๊ตฌ๋…

์‚ฌ์šฉํ•  Azure ๊ตฌ๋…์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

๋ฆฌ์†Œ์Šค ๊ทธ๋ฃน

๊ตฌ๋…์—์„œ ๊ธฐ์กด ๋ฆฌ์†Œ์Šค ๊ทธ๋ฃน์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์—ฌ ์ƒˆ ๋ฆฌ์†Œ์Šค ๊ทธ๋ฃน์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋ฆฌ์†Œ์Šค ๊ทธ๋ฃน์€ Azure ์†”๋ฃจ์…˜์— ๊ด€๋ จ๋œ ๋ฆฌ์†Œ์Šค๋ฅผ ๋ณด์œ ํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ์ž…๋‹ˆ๋‹ค. ์ด ์˜ˆ์—์„œ๋Š” docs-aml์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

Location

์‚ฌ์šฉ์ž ๋ฐ ๋ฐ์ดํ„ฐ ๋ฆฌ์†Œ์Šค์™€ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์œ„์น˜๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. ์ž‘์—… ์˜์—ญ์ด ๋งŒ๋“ค์–ด์ง€๋Š” ์œ„์น˜์ž…๋‹ˆ๋‹ค.

 

* ๋งŒ๋“ค๊ธฐ - ์ž‘์—… ์˜์—ญ ๋งŒ๋“œ๋Š” ๋ฐ ๋ช‡ ๋ถ„ ์ •๋„ ์†Œ์š”๋จ

* ๋ฐฐํฌ์ƒํƒœ ํ™•์ธ : ๋„๊ตฌ ๋ชจ์Œ์—์„œ ์•Œ๋ฆผ ์•„์ด์ฝ˜(์ข…๋ชจ์–‘)์„ ์„ ํƒ

 

Azure Notebook์—์„œ ์‹œ์ž‘ - ๋ˆŒ๋Ÿฌ์„œ ๋…ธํŠธ๋ถ ์‹คํ–‰ํ•˜๊ณ  ํŠœํ† ๋ฆฌ์–ผ์„ ์‹ค์Šต. Python 3.6 ์‚ฌ์šฉ.

 

https://docs.microsoft.com/ko-kr/azure/machine-learning/service/tutorial-data-prep

ํšŒ๊ท€ ๋ชจ๋ธ ์ž์Šต์„œ: ๋ฐ์ดํ„ฐ ์ค€๋น„ - Azure Machine Learning service

์ด ์ž์Šต์„œ์˜ 1๋ถ€์—์„œ๋Š” Azure Machine Learning SDK๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํšŒ๊ท€ ๋ชจ๋ธ๋ง์„ ์œ„ํ•ด Python์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ค€๋น„ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์›๋‹ˆ๋‹ค.

docs.microsoft.com

ํƒ์‹œ ์šดํ–‰ ๋น„์šฉ ์˜ˆ์ธก - ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„, ์Šน๊ฐ ์ˆ˜ ์œ„์น˜ ์„ ํƒ์ด ํฌํ•จ๋จ

 

A. Regression modeling์„ ์œ„ํ•œ ๋ฐ์ดํ„ฐ ์ค€๋น„

1. ๋ฐ์ดํ„ฐ ๋กœ๋“œ

- auto_read_file() method๋Š” ์ž…๋ ฅ ํŒŒ์ผ ํ˜•์‹์„ ์ž๋™์œผ๋กœ ์ธ์‹ํ•จ

- Dataflow ๊ฐœ์ฒด๋Š” ๋ฐ์ดํ„ฐ ํ”„๋ ˆ์ž„ํ•˜๊ณ  ๋น„์Šทํ•˜๊ณ ,

represents a series of lazily-evaluated, immutable operations on data.

Operations can be added by invoking the different transformation and filtering methods available.

The result of adding an operation to a Dataflow is always a new Dataflow object.

 

2. ๋ฐ์ดํ„ฐ ์ •๋ฆฌ(ํ˜•์‹ ๋ฐ ํ•„ํ„ฐ ๋ณ€ํ™˜, ์—ด ๋ถ„ํ•  ๋ฐ ์ด๋ฆ„ ๋ฐ”๊พธ๊ธฐ)

- ์ „์ฒด Null ๋ฐ์ดํ„ฐ ์ œ๊ฑฐ(๊ธฐ๊ณ„ ํ•™์Šต ๋ชจ๋ธ์˜ ์ •ํ™•๋„๋ฅผ ๋†’์ด๋Š” ๋ฐ ๋„์›€์ด ๋จ)

- ์œ ํšจํ•œ ์—ด ์ •ํ•˜๊ณ  ์—ด ์ด๋ฆ„ ๋ณ€๊ฒฝ

- ํ˜•์‹ ๋ณ€๊ฒฝ : ์œ„๊ฒฝ๋„ 10์ง„ ํ˜•์‹์œผ๋กœ ๋ณ€๊ฒฝ, distance ์ˆซ์ž ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜

- ๋‰ด์š•์‹œ๊ฐ€ ์•„๋‹Œ ์ขŒํ‘œ & ๋ˆ„๋ฝ๋œ ์ขŒํ‘œ (๋„์‹œ ๋ฐ–) ํ•„ํ„ฐ๋ง ํ•จ (์ฃผ๊ด€์  ๋ถ„์„) : ์ตœ์†Œ, ์ตœ๋Œ€ ๊ฒฝ๊ณ„ ์ •์˜๋กœ ํ•„ํ„ฐ๋งํ•จ.

- store_forward ๊ฐ’ ๋ˆ„๋ฝ๋œ ๋ถ€๋ถ„์€ "N"์œผ๋กœ ๋ฐ”๊พผ๋‹ค.

- ๋‚ ์งœ/์‹œ๊ฐ„ ๊ฐ’์„ ๊ฐ๊ฐ ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„ ์—ด๋กœ ๋ถ„ํ• 

 

3. ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜ ( ์›๋ž˜ ๋‚ ์งœ ํ˜•์‹ : 2013-08-01 08:14:37 )

- ์Šน์ฐจ&ํ•˜์ฐจ ๋‚ ์งœ๋ฅผ ์š”์ผ, ์›”๊ฐ„ ์ผ์ž, ์›” ๊ฐ’์œผ๋กœ ์ถ”๊ฐ€ ๋ถ„ํ• ํ•จ. ์›๋ž˜ ๋‚ ์งœ๋Š” ์‚ญ์ œ (pickup_datetime, dropoff_datetime)

(์‹œ๊ฐ„, ๋ถ„ ๋ฐ ์ดˆ ๊ฐ™์€ ์„ธ๋ฐ€ํ•œ ์‹œ๊ฐ„ ๊ธฐ๋Šฅ์€ ๋ชจ๋ธ ํ•™์Šต์— ์œ ์šฉ)

(์ƒˆ๋กœ์šด ์‹œ๊ฐ„ ๊ธฐ๋ฐ˜ ๊ธฐ๋Šฅ์„ ๋งŒ๋“ค๋ฉด ๊ธฐ๊ณ„ ํ•™์Šต ๋ชจ๋ธ ์ •ํ™•๋„๊ฐ€ ํ–ฅ์ƒ๋จ. ์˜ˆ๋ฅผ ๋“ค์–ด ํ‰์ผ์— ๋Œ€ํ•œ ์ƒˆ ๊ธฐ๋Šฅ์„ ์ƒ์„ฑํ•˜๋ฉด ํ‰์ผ๊ณผ ํƒ์‹œ ์š”๊ธˆ ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋ฉฐ, ํŠน์ • ์š”์ผ์—๋Š” ์ˆ˜์š”๊ฐ€ ๋งŽ์•„ ์š”๊ธˆ์ด ๋” ๋น„์‹ผ ๊ฒฝ์šฐ๊ฐ€ ์ž์ฃผ ์žˆ๋‹ค.)

 

- ์ตœ์ข… ํ•„ํ„ฐ : distance > 0, cost > 0

โ˜… ์ด ๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉด ๊ธฐ๊ณ„ ํ•™์Šต ๋ชจ๋ธ ์ •ํ™•๋„๊ฐ€ ๋Œ€ํญ ํ–ฅ์ƒ๋จ

โ˜… ๋น„์šฉ ๋˜๋Š” ๊ฑฐ๋ฆฌ๊ฐ€ 0์ธ ๋ฐ์ดํ„ฐ ์š”์†Œ๋Š” ์˜ˆ์ธก ์ •ํ™•๋„๋ฅผ ๋–จ์–ดํŠธ๋ฆฌ๋Š” ์ค‘๋Œ€ํ•œ ์ด์ƒ๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ๋•Œ๋ฌธ

 

- ๋จธ์‹ ๋Ÿฌ๋‹ ๋ชจ๋ธ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์™„์ „ํžˆ ๋ณ€ํ™˜ & ์ค€๋น„๋œ dataflow ๊ฐœ์ฒด๊ฐ€ ์ƒ๊ฒผ๋‹ค : dflows.dprep์œผ๋กœ ์ €์žฅ

import os file_path = os.path.join(os.getcwd(), "dflows.dprep") final_df.save(file_path)

 

B. ML ๋ชจ๋ธ ์ž๋™ ํ•™์Šต

1. ๋ฐ์ดํ„ฐ ํƒ์ƒ‰ (ํ•™์Šต ๋ฐ ํ…Œ์ŠคํŠธ ์„ธํŠธ๋กœ ๋ฐ์ดํ„ฐ ๋ถ„ํ• ; Split the data into train and test sets)

- ์ด์ „์— ๋งŒ๋“  dataflow ๊ฐœ์ฒด dflows.dprep ํŒŒ์ผ์„ ์—ด์–ด์„œ ๊ฒฐ๊ณผ๋ฅผ ๊ฒ€ํ† ํ•จ

import azureml.dataprep as dprep file_path = os.path.join(os.getcwd(), "dflows.dprep") dflow_prepared = dprep.Dataflow.open(file_path) dflow_prepared.get_profile()

 

- dflow_x : ์‹คํ—˜์šฉ ๋ฐ์ดํ„ฐ

- dflow_y : ์˜ˆ์ธก๊ฐ’ - ๋น„์šฉ

dflow_X = dflow_prepared.keep_columns(['pickup_weekday','pickup_hour', 'distance','passengers', 'vendor']) dflow_y = dflow_prepared.keep_columns('cost')

 

- sklearn ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ train_test_split ํ•จ์ˆ˜ ์‚ฌ์šฉํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ํ•™์Šต, ํ…Œ์ŠคํŠธ ์„ธํŠธ๋กœ ๋ถ„ํ• ํ•œ๋‹ค. ์ด ํ•จ์ˆ˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ชจ๋ธ ํ•™์Šต์šฉ x(๊ธฐ๋Šฅ) ๋ฐ์ดํ„ฐ ์„ธํŠธ ๋ฐ ํ…Œ์ŠคํŠธ์šฉ y(์˜ˆ์ธก ๊ฐ’) ๋ฐ์ดํ„ฐ ์„ธํŠธ๋กœ ๋ถ„๋ฆฌํ•œ๋‹ค. test_size ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ํ…Œ์ŠคํŠธ์— ํ• ๋‹นํ•  ๋ฐ์ดํ„ฐ ๋ฐฑ๋ถ„์œจ์„ ์ •์˜. random_state ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ํ•™์Šต-ํ…Œ์ŠคํŠธ ๋ถ„ํ• ์ด ํ•ญ์ƒ ๊ฒฐ์ •์ ์ด ๋˜๋„๋ก ์ž„์˜ ์ƒ์„ฑ๊ธฐ์— ์‹œ๋“œ๋ฅผ ์„ค์ •ํ•œ๋‹ค.

from sklearn.model_selection import train_test_split x_df = dflow_X.to_pandas_dataframe() y_df = dflow_y.to_pandas_dataframe() x_train, x_test, y_train, y_test = train_test_split(x_df, y_df, test_size=0.2, random_state=223) # flatten y_train to 1d array y_train.values.flatten()

 

- ์ด ๋‹จ๊ณ„์˜ ๋ชฉ์  : ๋ฐ์ดํ„ฐ ์š”์†Œ์—์„œ ์‹ค์ œ ์ •ํ™•๋„๋ฅผ ์ธก์ •ํ•˜๊ธฐ ์œ„ํ•ด ๋ชจ๋ธ ํ•™์Šต์— ์‚ฌ์šฉ๋˜์ง€ ์•Š์€ ์™„๋ฃŒ๋œ ๋ชจ๋ธ์„ ํ…Œ์ŠคํŠธํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

- ์ฆ‰, ์ž˜ ํ•™์Šต๋œ ๋ชจ๋ธ์€ ์•„์ง ํ™•์ธ๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ์—์„œ ์ •ํ™•ํ•œ ์˜ˆ์ธก์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

- ์ด์ œ ๋ชจ๋ธ์„ ์œ„ํ•œ ์ž๋™ ํ•™์Šต์— ํ•„์š”ํ•œ ํŒจํ‚ค์ง€ ๋ฐ ๋ฐ์ดํ„ฐ๊ฐ€ ์ค€๋น„๋˜์—ˆ๋‹ค.

 

The purpose of this step is to have data points to test the finished model that haven't been used to train the model, in order to measure true accuracy. In other words, a well-trained model should be able to accurately make predictions from data it hasn't already seen. You now have the necessary packages and data ready for autotraining your model.

 

2. ์ž๋™์œผ๋กœ ๋ชจ๋ธ ํ•™์Šต (Automatically train a model)

1. Define settings for the experiment run. Attach your training data to the configuration, and modify settings that control the training process.

(experiment ์‹คํ–‰์„ ์œ„ํ•œ ์„ค์ •์„ ์ •์˜ํ•˜๊ณ  training ๋ฐ์ดํ„ฐ๋ฅผ configuration์— ์—ฐ๊ฒฐ, training process๋ฅผ ์ œ์–ดํ•˜๋Š” settings๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค. )

 

2. Submit the experiment for model tuning. After submitting the experiment, the process iterates through different machine learning algorithms and hyperparameter settings, adhering to your defined constraints. It chooses the best-fit model by optimizing an accuracy metric.

(๋ชจ๋ธ ํŠœ๋‹์„ ์œ„ํ•œ ์‹คํ—˜์„ ์ œ์ถœ ํ•œ ํ›„, process๋Š” ๋‹ˆ๊ฐ€ ์ •์˜ํ•œ constraints๋ฅผ ์ค€์ˆ˜ํ•˜๋Š” different ๊ธฐ๊ณ„ํ•™์Šต ์•Œ๊ณ ๋ฆฌ์ฆ˜ & hyperparameter settings์„ ๋ฐ˜๋ณตํ•œ๋‹ค. ์ •ํ™•๋„ ๋ฉ”ํŠธ๋ฆญ์„ ์ตœ์ ํ™”ํ•˜์—ฌ ๊ฐ€์žฅ ์ ํ•ฉํ•œ ๋ชจ๋ธ์„ ์„ ํƒํ•œ๋‹ค.)

 

์ž๋™ ์ƒ์„ฑ ๋ฐ ํŠœ๋‹์„ ์œ„ํ•œ ์„ค์ • ์ •์˜ (Define settings for autogeneration and tuning)

 

Define the experiment parameter and model settings for autogeneration and tuning.

์ž๋™์ƒ์„ฑ๊ณผ ํŠœ๋‹์„ ์œ„ํ•œ ์‹คํ—˜ ๋งค๊ฐœ๋ณ€์ˆ˜ํ•˜๊ณ  ๋ชจ๋ธ์— ๋Œ€ํ•œ ์„ค์ •์„ ์ •์˜ํ•œ๋‹ค.

View the full list of settings.

 

Submitting the experiment with these default settings will take approximately 10-15 min,

๊ธฐ๋ณธ ์„ค์ •์„ ์‚ฌ์šฉํ•ด์„œ ์‹คํ—˜์„ ์ œ์ถœํ•˜๋Š”๋ฐ, ์•ฝ 10~15๋ถ„

 

but if you want a shorter run time, reduce either iterations or iteration_timeout_minutes.

iterations / iteration_timeout_minutes ์ค‘ ํ•˜๋‚˜๋ฅผ ์ค„์ด๋ฉด ์‹คํ–‰ ์‹œ๊ฐ„์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.

 

 

automl_settings = { "iteration_timeout_minutes" : 10, "iterations" : 30, "primary_metric" : 'spearman_correlation', "preprocess" : True, "verbosity" : logging.INFO, "n_cross_validations": 5 }

 

AutoMLConfig์— ๋Œ€ํ•œ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ •์˜๋œ ํ•™์Šต ์„ค์ •์„ ์‚ฌ์šฉํ•œ๋‹ค. (automl_settings)

๋˜ํ•œ ํ•™์Šต ๋ฐ์ดํ„ฐ ๋ฐ ๋ชจ๋ธ์˜ ์œ ํ˜•์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. (์šฐ๋ฆฌ๋Š” regression)

from azureml.train.automl import AutoMLConfig # local compute automated_ml_config = AutoMLConfig(task = 'regression', debug_log = 'automated_ml_errors.log', path = project_folder, X = x_train.values, y = y_train.values.flatten(), **automl_settings)

 

์ž๋™ ํšŒ๊ท€ ๋ชจ๋ธ ํ•™์Šต

 

์‹คํ—˜์„ ์‹œ์ž‘ํ•˜์—ฌ ๋กœ์ปฌ๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ •์˜๋œ automated_ml_config ๊ฐœ์ฒด๋ฅผ ์‹คํ—˜์— ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. ์‹คํ—˜ํ•˜๋Š” ๋™์•ˆ ์ง„ํ–‰๋ฅ ์„ ํ™•์ธํ•˜๋ ค๋ฉด ์ถœ๋ ฅ์„ True๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

from azureml.core.experiment import Experiment experiment=Experiment(ws, experiment_name) local_run = experiment.submit(automated_ml_config, show_output=True)

 

ํ‘œ์‹œ๋˜๋Š” ์ถœ๋ ฅ์€ ์‹คํ—˜์ด ์‹คํ–‰๋จ์— ๋”ฐ๋ผ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์—…๋ฐ์ดํŠธ๋œ๋‹ค.

๊ฐ ๋ฐ˜๋ณต์˜ ๊ฒฝ์šฐ ๋ชจ๋ธ ์œ ํ˜•, ์‹คํ–‰ ์ง€์† ๋ฐ ํ•™์Šต ์ •ํ™•๋„๊ฐ€ ํ‘œ์‹œ๋จ

PIPELINE, DURATION, METRIC, BEST

ํ•„๋“œ BEST๋Š” ๋ฉ”ํŠธ๋ฆญ ์œ ํ˜•์— ๋”ฐ๋ผ ์ตœ์ ์˜ ์‹คํ–‰ ํ•™์Šต ์ ์ˆ˜๋ฅผ ์ถ”์ ํ•œ๋‹ค.

 

3. ๊ฒฐ๊ณผ ํƒ์ƒ‰

Jupyter ์œ„์ ฏ์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์‹คํ—˜ ๊ธฐ๋ก์„ ๊ฒ€์‚ฌํ•˜์—ฌ ์ž๋™ ํ•™์Šต ๊ฒฐ๊ณผ๋ฅผ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

 

์˜ต์…˜ 1: ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ ์ฃผ๋Š” Jupyter ์œ„์ ฏ ์ถ”๊ฐ€

Jupyter Notebook์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์ด Jupyter Notebook ์œ„์ ฏ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ๊ฒฐ๊ณผ์— ๋Œ€ํ•œ ๊ทธ๋ž˜ํ”„ ๋ฐ ํ…Œ์ด๋ธ”์„ ํ™•์ธ

from azureml.widgets import RunDetails RunDetails(local_run).show()

 

์˜ต์…˜ 2: Python์—์„œ ๋ชจ๋“  ์‹คํ–‰ ๋ฐ˜๋ณต ๊ฐ€์ ธ์˜ค๊ธฐ ๋ฐ ๊ฒ€์‚ฌ (Option 2: Get and examine all run iterations in Python)

๋˜๋Š” ๊ฐ ์‹คํ—˜์˜ ๊ธฐ๋ก์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  ๊ฐ ๋ฐ˜๋ณต ์‹คํ–‰์— ๋Œ€ํ•œ ๊ฐœ๋ณ„ ๋ฉ”ํŠธ๋ฆญ์„ ์‚ดํŽด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ ๊ฐœ๋ณ„ ๋ชจ๋ธ ์‹คํ–‰์— ๋Œ€ํ•ด RMSE(root_mean_squared_error)๋ฅผ ๊ฒ€์‚ฌํ•˜์—ฌ ๋Œ€๋ถ€๋ถ„์˜ ๋ฐ˜๋ณต์ด ์ ์ ˆํ•œ ์—ฌ๋ฐฑ($3~4) ๋‚ด์—์„œ ํƒ์‹œ ์š”๊ธˆ์„ ์˜ˆ์ธกํ•˜๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

children = list(local_run.get_children()) metricslist = {} for run in children: properties = run.get_properties() metrics = {k: v for k, v in run.get_metrics().items() if isinstance(v, float)} metricslist[int(properties['iteration'])] = metrics rundata = pd.DataFrame(metricslist).sort_index(1) rundata

 

4. ์ตœ์  ๋ชจ๋ธ ๊ฒ€์ƒ‰

๋ฐ˜๋ณต ์ค‘์—์„œ ์ตœ์ ์˜ ํŒŒ์ดํ”„๋ผ์ธ์„ ์„ ํƒํ•œ๋‹ค.

automl_classifier์— ๋Œ€ํ•œ get_output ๋ฉ”์„œ๋“œ๋Š” ๋งˆ์ง€๋ง‰ ๋งž์ถค ํ˜ธ์ถœ์— ๋Œ€ํ•œ ์ตœ์ ์˜ ์‹คํ–‰ ๋ฐ ๋งž์ถค ๋ชจ๋ธ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

get_output์— ๋Œ€ํ•œ ์˜ค๋ฒ„๋กœ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ๊ธฐ๋ก๋œ ๋ฉ”ํŠธ๋ฆญ ๋˜๋Š” ํŠน์ • ๋ฐ˜๋ณต์— ๋Œ€ํ•œ ์ตœ์ ์˜ ์‹คํ–‰ ๋ฐ ๋งž์ถค ๋ชจ๋ธ ๊ฒ€์ƒ‰ ๊ฐ€๋Šฅ

best_run, fitted_model = local_run.get_output() print(best_run) print(fitted_model)

 

5. ์ตœ์  ๋ชจ๋ธ ์ •ํ™•๋„ ํ…Œ์ŠคํŠธ

์ตœ์  ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ ์„ธํŠธ์—์„œ ์˜ˆ์ธก์„ ์‹คํ–‰ํ•˜์—ฌ ํƒ์‹œ ์š”๊ธˆ์„ ์˜ˆ์ธกํ•œ๋‹ค.

predict ํ•จ์ˆ˜๋Š” ์ตœ์  ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๊ณ  x_test ๋ฐ์ดํ„ฐ ์„ธํŠธ์—์„œ y(trip ๋น„์šฉ) ๊ฐ’์„ ์˜ˆ์ธกํ•œ๋‹ค.

y_predict์—์„œ ์ฒซ 10๊ฐœ์˜ ์˜ˆ์ธก ๋น„์šฉ ๊ฐ’์„ ์ถœ๋ ฅ

y_predict = fitted_model.predict(x_test.values) print(y_predict[:10])

 

์‹ค์ œ ๋น„์šฉ ๊ฐ’๊ณผ ๋น„๊ตํ•˜์—ฌ ์˜ˆ์ธก ๋น„์šฉ ๊ฐ’์„ ์‹œ๊ฐํ™”ํ•˜๋Š” ์‚ฐ์ ๋„(a scatter)๋ฅผ ๋งŒ๋“ ๋‹ค.

๋‹ค์Œ ์ฝ”๋“œ์—์„œ๋Š” distance ๊ธฐ๋Šฅ(feature)์„ x-์ถ•์œผ๋กœ, trip cost๋ฅผ y-์ถ•์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

๊ฐ trip ๊ฑฐ๋ฆฌ ๊ฐ’์—์„œ ์˜ˆ์ธก ๋น„์šฉ์˜ ์ฐจ์ด๋ฅผ ๋น„๊ตํ•˜๊ธฐ ์œ„ํ•ด ์ฒ˜์Œ 100๊ฐœ์˜ ์˜ˆ์ธก ๋ฐ ์‹ค์ œ ๋น„์šฉ ๊ฐ’์ด separate series๋กœ ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค.

๋„ํ‘œ๋ฅผ ์‚ดํŽด๋ณด๋ฉด ๊ฑฐ๋ฆฌ/๋น„์šฉ ๊ด€๊ณ„๊ฐ€ ๊ฑฐ์˜ ์„ ํ˜•์ด๊ณ , ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ์˜ˆ์ธก ๋น„์šฉ ๊ฐ’์ด ๋™์ผํ•œ ์—ฌํ–‰ ๊ฑฐ๋ฆฌ์— ๋Œ€ํ•œ ์‹ค์ œ ๋น„์šฉ ๊ฐ’์— ๋งค์šฐ ๊ฐ€๊น๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

import matplotlib.pyplot as plt fig = plt.figure(figsize=(14, 10)) ax1 = fig.add_subplot(111) distance_vals = [x[4] for x in x_test.values] y_actual = y_test.values.flatten().tolist() ax1.scatter(distance_vals[:100], y_predict[:100], s=18, c='b', marker="s", label='Predicted') ax1.scatter(distance_vals[:100], y_actual[:100], s=18, c='r', marker="o", label='Actual') ax1.set_xlabel('distance (mi)') ax1.set_title('Predicted and Actual Cost/Distance') ax1.set_ylabel('Cost ($)') plt.legend(loc='upper left', prop={'size': 12}) plt.rcParams.update({'font.size': 14}) plt.show()

 

๊ฒฐ๊ณผ์˜ root mean squared error๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.

y_test ๋ฐ์ดํ„ฐ ํ”„๋ ˆ์ž„์„ ์‚ฌ์šฉํ•˜๊ณ  ์ด๋ฅผ ๋ชฉ๋ก์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์˜ˆ์ธก ๊ฐ’๊ณผ ๋น„๊ตํ•œ๋‹ค.

mean_squared_error ํ•จ์ˆ˜๋Š” ๋‘ ๊ฐœ์˜ ๊ฐ’ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜๊ณ  ๋‘ ๋ฐฐ์—ด ๊ฐ„์˜ ํ‰๊ท  ์ œ๊ณฑ ์˜ค์ฐจ๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.

๊ฒฐ๊ณผ์˜ ์ œ๊ณฑ๊ทผ์„ ๊ตฌํ•˜๋ฉด y ๋ณ€์ˆ˜(๋น„์šฉ)์™€ ๋™์ผํ•œ ๋‹จ์œ„์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜ํƒ€๋‚œ๋‹ค.

์ด๋Š” ๋Œ€๋žต์ ์œผ๋กœ ์‹ค์ œ ์š”๊ธˆ๊ณผ ํƒ์‹œ ์š”๊ธˆ ์˜ˆ์ธก ๊ฐ„ ์ฐจ์ด๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. $3.2??

from sklearn.metrics import mean_squared_error from math import sqrt rmse = sqrt(mean_squared_error(y_actual, y_predict)) rmse

 

3.2204936862688798

 

์ „์ฒด y_actual ๋ฐ y_predict ๋ฐ์ดํ„ฐ ์„ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ MAPE(์ ˆ๋Œ€ ํ‰๊ท  ๋ฐฑ๋ถ„์œจ ์˜ค์ฐจ)๋ฅผ ๊ณ„์‚ฐํ•˜๋ ค๋ฉด ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

์ด ๋ฉ”ํŠธ๋ฆญ์€ ๊ฐ ์˜ˆ์ธก ๋ฐ ์‹ค์ œ ๊ฐ’ ์‚ฌ์ด ์ ˆ๋Œ€๊ฐ’ ์ฐจ์ด๋ฅผ ๊ณ„์‚ฐํ•˜๋ฉฐ ๋ชจ๋“  ์ฐจ์ด๋ฅผ ํ•ฉ์‚ฐํ•œ๋‹ค.

๊ทธ๋Ÿฐ ๋‹ค์Œ, ์‹ค์ œ ๊ฐ’์˜ ํ•ฉ๊ณ„์— ๋Œ€ํ•œ ๋ฐฑ๋ถ„์œจ๋กœ ํ•ด๋‹น ํ•ฉ์‚ฐ์„ ํ‘œํ˜„ํ•œ๋‹ค.

sum_actuals = sum_errors = 0 for actual_val, predict_val in zip(y_actual, y_predict): abs_error = actual_val - predict_val if abs_error < 0: abs_error = abs_error * -1 sum_errors = sum_errors + abs_error sum_actuals = sum_actuals + actual_val mean_abs_percent_error = sum_errors / sum_actuals print("Model MAPE:") print(mean_abs_percent_error) print() print("Model Accuracy:") print(1 - mean_abs_percent_error)

 

Model MAPE: 0.10545153869569586 Model Accuracy: 0.8945484613043041

 

์ตœ์ข… ์˜ˆ์ธก ์ •ํ™•๋„ ๋ฉ”ํŠธ๋ฆญ์—์„œ ๋ชจ๋ธ์€ ๋ฐ์ดํ„ฐ ์„ธํŠธ์˜ ๊ธฐ๋Šฅ์—์„œ ํƒ์‹œ ์š”๊ธˆ์„ ์˜ˆ์ธกํ•˜๋Š” ๋ฐ ์ ํ•ฉํ•˜๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. (์ผ๋ฐ˜์ ์œผ๋กœ +- $3.00 ๋‚ด).

๊ธฐ์กด์˜ Machine Learning ๋ชจ๋ธ ๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค๋Š” ๋ฆฌ์†Œ์Šค๊ฐ€ ์ƒ๋‹นํžˆ ๋งŽ์ด ํ•„์š”ํ•˜๋ฉฐ, ์ˆ˜์‹ญ ๊ฐ€์ง€ ๋ชจ๋ธ์„ ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋น„๊ตํ•˜๋Š” ๋ฐ ๋งŽ์€ ๋„๋ฉ”์ธ ์ง€์‹๊ณผ ์‹œ๊ฐ„์ด ํ•„์š”ํ•œ๋ฐ, ์ž๋™ํ™”๋œ ๊ธฐ๊ณ„ ํ•™์Šต์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์‹œ๋‚˜๋ฆฌ์˜ค์— ๋Œ€ํ•œ ๋‹ค๋ฅธ ์—ฌ๋Ÿฌ ๋ชจ๋ธ์„ ์‹ ์†ํ•˜๊ฒŒ ํ…Œ์ŠคํŠธํ•˜๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์ด๋‹ค.

 

 

๋ฐ˜์‘ํ˜•

'Machine Learning > Azure ML' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๋ฐ์ดํ„ฐ ๋กœ๋“œ  (0) 2019.07.22
Azure ML ์ˆœ์„œ  (0) 2019.06.25
AKS ํด๋Ÿฌ์Šคํ„ฐ ๋งŒ๋“ค๊ธฐ  (0) 2019.06.25