Contenu connexe Similaire à Amazon SageMaker를 이용한 예측 분석-남궁영환 솔루션즈 아키텍트, AWS (20) Plus de Amazon Web Services Korea (20) Amazon SageMaker를 이용한 예측 분석-남궁영환 솔루션즈 아키텍트, AWS1. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SageMaker를 이용한
예측 분석
남궁 영환
AI/ML Specialist Solutions Architect
Amazon Web Services
2. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
강연 중 질문하는 방법
Go to Webinar “Questions” 창에 자신이 질문한
내역이 표시됩니다. 기본적으로 모든 질문은
공개로 답변 됩니다만 본인만 답변을 받고 싶으면
(비공개)라고 하고 질문해 주시면 됩니다.
본 컨텐츠는 고객의 편의를 위해 AWS 서비스 설명을 위해 온라인 세미나용으로 별도로 제작, 제공된 것입니다. 만약 AWS
사이트와 컨텐츠 상에서 차이나 불일치가 있을 경우, AWS 사이트(aws.amazon.com)가 우선합니다. 또한 AWS 사이트
상에서 한글 번역문과 영어 원문에 차이나 불일치가 있을 경우(번역의 지체로 인한 경우 등 포함), 영어 원문이 우선합니다.
AWS는 본 컨텐츠에 포함되거나 컨텐츠를 통하여 고객에게 제공된 일체의 정보, 콘텐츠, 자료, 제품(소프트웨어 포함) 또는 서비스를 이용함으로 인하여 발생하는 여하한
종류의 손해에 대하여 어떠한 책임도 지지 아니하며, 이는 직접 손해, 간접 손해, 부수적 손해, 징벌적 손해 및 결과적 손해를 포함하되 이에 한정되지 아니합니다.
고지 사항(Disclaimer)
3. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
• Amazon & AWS의 AI/ML
• Amazon SageMaker
주요 특징
Hyperparameter Tuning
빌트인 알고리즘
• 시계열 예측 분석
• Demo
4. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
인공지능 & 머신러닝 유스케이스의 폭발적인 증가
이미지 인식 및 태깅 (예: 효율적인 사진 정리)
객체 탐지, 트래킹, 내비게이션 (예: 자율 주행 차량 기술)
음성 인식 및 합성 (예: 지능형 음성 비서 기술)
알고리즘 기반 트레이딩 전략 관련 성능 향상
감성 분석 (예: 개인화 및 맞춤형 광고 기술)
AI (Artificial Intelligence) ML (Machine Learning)
5. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon의 머신러닝(ML) 관련 주요 분야
물류 및
재고 관리
검색/추천
기존 상품
관리 효율화
신규 상품
맞춤형 제시
AWS
6. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ML @ AWS
OUR MISSION
전세계 모든 데이터
과학자와 개발자에게 편리한
머신 러닝 연구 개발 환경을
제공
7. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 상에서 머신 러닝을 활용하고 있는 고객
8. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon ML stack
Frameworks
&
Infrastructure
Application
Services
Managed
Platform
Services
KERAS
A W S D E E P L E A R N I N G A M I
A M A Z O N S A G E M A K E R
R E K O G N I T I O N R E K O G N I T I O N V I D E O P O L L Y T R A N S C R I B E T R A N S L A T E C O M P R E H E N D L E X
S P E E C H L A N G U A G E
A W S D E E P L E N S A M A Z O N M A C H I N E
L E A R N I N G
S P A R K & E M R A M A Z O N
M E C H A N I C A L T U R K
G P U ( P 3 I N S T A N C E S ) C P U I O T ( G R E E N G R A S S ) M O B I L E
V I S I O N
9. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SageMaker
10. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
머신 러닝 프로세스
Data Visualization
& Analysis
Business Problem –
Data Collection
Data Integration
Data Preparation
& Cleaning
Feature Engineering
Model Training &
Parameter Tuning
Model Evaluation
Are Business
Goals met?
Model Deployment
Monitoring &
Debugging
– Predictions
YesNo
DataAugmentation
Feature
Augmentation
Re-training
ML problem framing
11. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SageMaker
손쉽게 머신 러닝 모델을 빌드, 트레이닝, 배포할 수 있는 완전 관리형 서비스
머신러닝 모델을 위한
트레이닝 데이터
수집 및 준비
머신 러닝 알고리즘
선정 및 최적화
머신 러닝 모델
트레이닝을 위한
환경 세팅 및 관리
머신 러닝 모델의
트레이닝 & 튜닝
(반복 개선 과정)
머신 러닝 모델의
프로덕션 환경 배포
프로덕션 환경에서
운영, 확장 및 관리
12. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Bring Your Own
Algorithms
ML Algorithms
R
MXNet
TensorFlow
Caffe/Caffe2
PyTorch
Keras
CNTK
…
Amazon SageMaker를 이용한 ML 모델 트레이닝
SageMaker Built-
in Algorithms
k-Means Clustering
PCA
Neural Topic Modelling
Factorization Machines
Linear Learner
XGBoost
Latent Dirichlet Allocation
Image Classification
Seq2Seq
DeepAR Forecasting
BlazingText (word2vec)
Random Cut Forest
k-Nearest Neighbour
Object Detection
SageMaker
Framework SDKs
TensorFlow SDK
MXNet (Gluon) SDK
Chainer SDK
PyTorch SDK
Apache Spark
Estimator
Apache Spark Python library
Apache Spark Scala library
Amazon
EMR
13. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SageMaker: 참조 아키텍처
SageMaker
Notebooks
Training
Algorithm
SageMaker
Training
SageMaker
Hosting AWS
Lambda
API
Gateway
데이터 준비
Training Data
Inference
requests
Amazon
S3
Amazon
S3
트레이닝 & 튜닝 호스팅 & 배포
Raw
Data
Prepared
Data
Algorithm
Container
Trained
Model
Trained
Model
Hyperparameter
Optimization
User
Interactions
14. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Photo credit: https://www.flickr.com/photos/ceasedesist/5821282085
(Licensed for commercial use)
Hyperparameter Tuning
15. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning
Image Classification 알고리즘
최적의 하이퍼파라미터로 트레이닝한 결과
label – bathtub
probability - 0.998812198638916
최초의 하이퍼파라미터로 트레이닝한 결과
16. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning
Learning Rate
Regularization
Option 1: 그리드 탐색 (Grid Search)
17. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning
Option 1: 그리드 탐색 (Grid Search)
gamma : Kernel coefficient for ‘rbf’, ‘poly’, and ‘sigmoid’
C: Penalty parameter
* SVC: Support Vector Clustering
18. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning
Option 2: 랜덤 탐색 (Random Search)
Learning Rate
Regularization
Bergstra, Bengio, “Random Search for Hyper-Parameter Optimization”
https://dl.acm.org/citation.cfm?id=2188395
"그리드 탐색(Grid search)을 이용하는
뉴럴 네트워크와 비교했을 때,
동일한 문제와 모델에 랜덤 탐색
(Random search)을 이용하면
전체적으로 모델의 성능도 더
향상되고 계산 시간도 더 빨라짐 "
19. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning
Option 2: 랜덤 탐색 (Random Search)
20. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning
Option 3: Bayesian Optimization 기법
• A Tutorial on Bayesian Optimization of Expensive Cost Functions, with Application to
Active User Modeling and Hierarchical Reinforcement Learning
(https://arxiv.org/abs/1012.2599)
• Practical Bayesian Optimization of Machine Learning Algorithms
(https://arxiv.org/abs/1206.2944)
• Taking the Human Out of the Loop: A Review of Bayesian Optimization
(https://ieeexplore.ieee.org/document/7352306)
21. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning in Amazon SageMaker
Amazon SageMaker의 Hyperparameter Tuning 기능은
Bayesian Optimization을 포함한 몇 가지 다양한
최적화 기법을 바탕으로 구현되어 있습니다.
22. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning in Amazon SageMaker
Hyperparameter tuning finds the best hyperparameter using Bayesian optimization
모든 ML 알고리즘을 지원합니다:
• SageMaker의 빌트인 알고리즘
• 사용자 정의 알고리즘
• ML 프레임워크를 위해 Amazon SageMaker 상에서 사전에 빌드한 컨테이너
(TensorFlow, MXNet, Chainer) = bring-your-own-container
트레이닝 데이터셋
ML 알고리즘
Objective
선별된
Hyperparameters
가장 좋은 결과를 얻기
위한
Hyperparameter들을
추정
채택된
hyperparameters를
이용한 모델 트레이닝
가장 좋은
모델을
결과로 리턴
Configuration Bayesian Optimization Training Jobs
23. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning in Amazon SageMaker
Configuration
Training Jobs
The result of models
Estimator
24. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning in Amazon SageMaker
Automatic Model Tuning
25. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning in Amazon SageMaker
Automatic Model Tuning
26. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning in Amazon SageMaker
Automatic Model Tuning
27. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hyperparameter Tuning in Amazon SageMaker
Automatic Model Tuning
28. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SageMaker의 빌트인 알고리즘들
29. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
대규모 데이터 및 성능 향상에 최적화된 알고리즘
Amazon SageMaker 는 대용량 데이터 처리/분석 및 최적화된 성능을 지원하는 빌트인
알고리즘을 제공하며 지속적 추가 및 업데이트를 제공합니다.
Amazon provided algorithm Sample Use Cases
K-Means clustering 고객 군 분할; 분류
K-Nearest Neighbors 분류 또는 회귀에 사용되는 비모수 방식의 알고리즘
Principal Component Analysis 특징 차원 감소
Factorization Machines 추천 시스템
Linear regression 가격 예측
Binary classification 탈퇴 고객 예측
Latent Dirichlet Allocation 토픽에 따른 문서 분류
Neural Variational Document Model (NVDM) 자연어 처리를 이용한 문서 분류
XGboost Decision trees; 비정형 파악
Image Classifier (ResNet) 이미지를 구분하는 알고리즘
Object Detection Algorithm (SSD) 하나의 이미지로부터 다양한 물체를 찾아내고 인식하는 알고리즘
Sequence2Sequence 언어 번역
DeepAR RNN을 이용한 시계열 데이터 예측
BlazingText Word2Vec 구현; 자연어 처리를 위해 단어를 벡터로 변환
Random Cut Forest 비정상적인 데이터 추출
30. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Linear Learner
• Classification, Regression 문제에 활용
• 다양한 Objective metric 이용 가능
• Continuous: mean square error, cross entropy loss, absolute error
• Discrete: f1, precision-recall, accuracy
• SGD, Adam, Adagrad, rmsprop 등의 최적화 알고리즘 지원
• Preprocessing 지원
• unbias_data: 평균값을 0으로
• normalize_data: standard deviation을 1로
• 입력 데이터는 섞여(shuffled) 있어야 함.
(레이블 순서대로 정렬된 데이터를 사용할 경우, 정상적인 모델 트레이닝이 안 됨)
• Multi-class Classification 지원
• Auto ML Tuning 관련
• Linear Learner는 Auto ML Tuning 기능과는 별도로 hyperparameter 튜닝을 위한 내부
메카니즘을 보유하고 있음
(기본적으로, 여러 모델을 병렬로 트레이닝해서 Hyperparameter를 튜닝함)
• Auto ML Tuning 기능을 사용할 경우, 기본 Hyperparameter 튜닝 기능은 자동 차단됨
𝑌𝑖 = 𝛽0 + 𝛽1 𝑋𝑖 + 𝜀𝑖
Dependent
Variable
Random
Error term
Population
Y intercept
Population
Slope coefficient
Independent
Variable
https://towardsdatascience.com/linear-regression-in-python-9a1f5f000606
https://seaborn.pydata.org/examples/multiple_regression.html
31. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Factorization Machines
• SVM (Support Vector Machines) 알고리즘의 장점에
Factorization 모델링을 결합한 예측 알고리즘
• 많은 feature들을 가진 sparse 데이터셋을 다룰 때
효과적임 (예. 클릭 예측과 상품 추천)
• Dense한 데이터를 다룰 때에만 GPU를 사용하세요.
• Float32 tensors로 구성된 recordIO-protobuf
포맷을 지원합니다.
• FYI, see “Implementing a Recommender System
with SageMaker, MXNet, and Gluon(GitHub)”
Sparse 데이터 셋 예제
Factorization Machine 모델
ො𝑦 = 𝑤0 +
𝑖
𝑤𝑖 𝑥𝑖 +
𝑖
𝑗>𝑖
< 𝑣𝑖, 𝑣𝑗 > 𝑥𝑖 𝑥𝑗
Cost Function
𝐿 =
1
𝑁
𝑛
𝑦𝑛 − ො𝑦𝑛
2
32. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Boosted Decision Trees
• XGBoost (eXtreme Gradient Boosting)은 오픈 소스 기반의
Gradient boosted trees 알고리즘
• 다양한 분야에서 폭넓게 활용 중 (매출 예측, 웹 문서 구분,
고객 행동 예측, 모션 예측, 광고 클릭률 예측, Malware
구분, 제품 분류, 위험 예측 등)
• 현재는 libSVM 과 CSV 포맷을 지원 (Protobuf 아님)
What is the best split?
Tree ensemble model
?
https://homes.cs.washington.edu/~tqchen/pdf/BoostedTree.pdf
33. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Boosted Decision Trees
Tunable Hyperparameters
각 Parameter들의 의미와 역할을 이해하고 문제에 잘 맞도록 적용하는 것이
중요합니다.
Metric Name Description Optimization Direction
validation:rmse Root mean square error. Minimize
validation:mae Mean absolute error. You must choose one of them as an
objective to optimize when tuning the
algorithm with hyperparameter
values.>Minimize
validation:logloss Negative log-likelihood. Minimize
validation:error Binary classification error
rate, calculated as
#(wrong cases)/#(all
cases).
Minimize
validation:merror Multiclass classification
error rate, calculated as
#(wrong cases)/#(all
cases).
Minimize
validation:mlogloss Negative log-likelihood for
multiclass classification.
Minimize
validation:auc Area under the curve. Maximize
validation:ndcg Normalized Discounted
Cumulative Gain.
Maximize
validation:map Mean average precision. Maximize
Metrics Computed by the XGBoost Algorithm
Parameter Name Parameter Type Recommended Ranges
num_round IntegerParameterRanges [1, 4000]
eta
ContinuousParameterRange
s
MinValue: 0.1, MaxValue: 0.5
gamma
ContinuousParameterRange
s
MinValue: 0, MaxValue: 5
max_depth IntegerParameterRanges [0, 10]
min_child_weight
ContinuousParameterRange
s
MinValue: 0, MaxValue: 120
max_delta_step IntegerParameterRanges [0, 10]
subsample
ContinuousParameterRange
s
MinValue: 0.5, MaxValue: 1
colsample_bytree
ContinuousParameterRange
s
MinValue: 0.5, MaxValue: 1
colsample_bylevel
ContinuousParameterRange
s
MinValue: 0.5, MaxValue: 1
lambda
ContinuousParameterRange
s
MinValue: 0, MaxValue: 1000
alpha
ContinuousParameterRange
s
MinValue: 0, MaxValue: 1000
(Choose one of these metrics as the objective) (alpha, min_child_weight, subsample, eta, and num_round, etc.)
34. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
KNN: K-Nearest Neighbors
• 비모수(non-parametric) 방식의 인덱스 기반 알고리즘
분류(Classification): 샘플 데이터와 가장 가까운 k개의 데이터 포인트를 대상으로 가장 많이
나타난 클래스 레이블을 할당
회귀(Regression): 샘플 데이터와 가장 가까운 k개의 데이터 포인트를 대상으로, 피처 값의
평균을 결과로 리턴
• k-NN 알고리즘은 3단계로 구성되어 있습니다.
샘플링: 초기의 데이터 크기를 메모리에 맞게 줄임 (sample_size)
차원 축소: 데이터의 차원을 줄여나가는 단계
- 목적: 사용되는 메모리 크기 & 추론에 소요되는 시간을 줄이기 위해
- Random projection (sign) 모드, fast Johnson-Lindenstrauss transform(fjlt) 모드를 지원
인덱스 구축: 최종단계에서 구축된 인덱스가 데이터들간의 거리를 효과적으로 Lookup 할 수
있게 함. (인덱스 타입 (index_type) 으로 flat index, inverted index 와 inverted index with
product quantization 세가지 모드를 지원)
• 트레이닝을 위한 데이터는 recordIO-protobuf 와 CSV 포맷을 지원
• Batch transform 모드에서는 application/jsonlines 데이터 포맷을 지원
35. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Random Cut Forest
• 데이터셋내에서 비정상적인 데이터를 찾아내는
Unsupervised learning 방식의 알고리즘
• 시계열 데이터내에서 spikes, 데이터의 주기성을 깨는 데이터,
분류를 할 수 없는 데이터 값들을 검출
• 각 데이터에 대해서 anomaly 스코어를 계산
(스코어가 높을수록 비정상일 확률이 높음을 의미)
• Amazon SageMaker의 RCF는 다차원 데이터를 지원하며
feature 개수, big data, 그리고 instance의 scalability가 뛰어남
• CPU에 최적화 되어 있음
Robust Random Cust Forest Based Anomaly Detection on Streams
http://proceedings.mlr.press/v48/guha16.pdf
36. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DeepAR
• scalar 타입의 시계열(Time-series) 데이터를 RNN
(Recurrent Neural Network)을 기반으로 예측하는 알고리즘
• train과 test의 2 채널을 지원합니다. prediction_length는
고정값입니다.
• 학습을 위한 데이터는 .json 과 .parquet 포맷을 지원합니다.
• CPU와 GPU 모두 지원합니다.
• Category값을 지원하여 (“cat”) 시계열 그룹의 특징들을
학습할 수 있습니다.
zi ,t − 2, xi ,t − 1 zi ,t − 1, xi ,t zi ,t , xi ,t + 1
hi ,t − 1 hi ,t hi ,t + 1
`(zi ,t − 1|✓i ,t − 1) `(zi ,t |✓i ,t ) `(zi ,t + 1|✓i ,t + 1)
zi ,t − 1 zi ,t zi ,t + 1
Input
Network
37. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Time-series Forecasting
38. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Time-series Forecasting - overview
Multi-step 𝒴𝑡+𝑘𝒴:𝑡
Covariates 𝒴𝑡+𝑘𝒴:𝑡, 𝑥:𝑡
(ℎ)
, 𝑥:𝑡
(𝑓)
, 𝑥(𝑠)
Multi time series 𝒴:𝑡
𝑖𝒴:𝑡
One-step-ahead 𝒴𝑡+1𝒴:𝑡 = (𝒴𝑡, ⋯ , 𝒴0)
Probabilistic Forecasting 𝑝 𝒴𝑡+𝑘|𝒴:𝑡𝔼(𝒴𝑡+𝑘|𝒴:𝑡)
39. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Multi-step forecasting variants
Direct
…
Recursive
• AR(autoregressive) 방법과 유사
• 시스템에서 다음 단계의 추정 결과를 ‘Ground Truth’로 간주해서 반복적으로 계산
• 트레이닝/예측의 차이를 보정하기 위한 정교한 트레이닝 기법이 필요 *
* Bengio et al., Scheduled Sampling for Sequence Prediction with Recurrent Neural Networks (2015)
**Taieb and Atiya, A Bias and Variance Analysis for Multi-Step-Ahead Time Series Forecasting (2016)
• 과거 이력을 바탕으로 를 바로 예측
• 과거 이력과 예측하려는 값 사이의 time step들은 무시
• More stable, less biased, more robust**
40. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Multi-step forecasting variants
• Temporal covariates
available in history
• 예: demand, usage,
weather, etc.
• Temporal covariates
available in history &
future
• 예: Holidays, supply,
prices, promotions,
weather, etc.
• ‘What-if’ 시나리오를 참고
• Static covariates
• 예: location, country, store
ID, etc.
y
x
History Future
41. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Probabilistic Forecasting
Point forecast
Parametric
• 가정: 데이터가 특정 확률 분포를 따름을 전제로 함
• 아래의 likelihood loss function을 통해 바로 답을 계산할 수 있는 파라미터셋을 예측
Non-parametric
• 예를 들어, 다음의 확률을 예측하는 Quantile 회귀 함수를 만들고 싶다면?
• 아래와 같은 전체 Quantile 손실 함수값이 최소가 되도록 구현해야 함
Probabilistic forecast
𝑝 𝒴𝑡+𝑘|𝒴:𝑡𝔼(𝒴𝑡+𝑘|𝒴:𝑡)
ℒ =
𝑖=1
𝑁
𝑡=𝑡0
𝑇
log ℓ(𝑧𝑖,𝑡|𝜃(𝐡𝑖,𝑡))
42. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Learning from multiple related timeseries
Neural Network 기법이 시계열 예측 분야에서 뛰어난 성능을 나타냄:
• very long history
• many covariates
• complex and non-linear relationships (spatial and temporal)
• multiple related timeseries
43. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Data Generators for time series training
… 1 4 3 2 -1 0 3 2 6 4 4 …
… 3 2 5 4 6 -2 5 0 -4 2 4 …
Lookback = 4
Step = 2 Delay = 4
2 0 2 4
4 -2 0
Generator
y
x1
y
x1
44. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
From Dense to Recurrent Nets
2 0 2
4 -2 0
y
x1
y x1
2 0 2 4 -2 0
Flatten
45. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
From Dense to Recurrent Nets
y x1
2 0 2 4 -2 0
4
• Flattening the timeseries
loses temporal correlation
• The dense net requires a
lot of date to rediscover
these relationships (it can)
• Is there a way to preserve
temporal information?
46. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
From Dense to Recurrent Nets
2 0 2
4 -2 0
𝑥<𝑡>
𝑥<𝑡+1>
𝑥<𝑡−1>
47. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
The simple recurrent memory cell
𝑥<𝑡>
𝑥<𝑡+1>
𝑥<𝑡−1>
𝑦<𝑡−1>
𝑦<𝑡>
𝑦<𝑡+1>
𝑎<𝑡−1>
𝑎<𝑡>
2 0 2
4 -2 0
4
48. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
The simple recurrent memory cell
4
𝑎<𝑡>
= 𝑔(𝑊𝑎𝑥 𝑥<𝑡>
+ 𝑊𝑎𝑎 𝑎<𝑡−1>
+ 𝑏 𝑎)
𝑦<𝑡>
= 𝑔(𝑊𝑦𝑎 𝑎<𝑡>
+ 𝑏 𝑦)
Vanishing Gradients!
𝑥<𝑡>
𝑥<𝑡+1>
𝑥<𝑡−1>
𝑦<𝑡−1>
𝑦<𝑡>
𝑦<𝑡+1>
𝑎<𝑡−1>
𝑎<𝑡>
2 0 2
4 -2 0
49. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
LSTM: Long Short-Term memory
* Hochreiter, Sepp, and Jürgen Schmidhuber. “Long Short-Term Memory.” Neural Computation 9, no. 8 (November 1, 1997): 1735–80.
https://doi.org/10.1162/neco.1997.9.8.1735.
50. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
LSTM cell
xt
Ht-1
Ct-1
Previous
Cell State
Previous
Hidden State
Output Current Input
Ct
Ht
Ht
Current
Cell State
Current
Hidden State
Output
Current
Hidden State
Output
X +
ot
ft
X
it gt
X
Tanh
Ct
Input Gate Tanh Output GateForget Gate
𝜎 𝜎𝜎
51. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
LSTM Network
LSTM
Cell
LSTM
Cell
LSTM
Cell
LSTM
Cell
LSTM
Cell
Xt-2 xt Xt+2Xt-1 Xt+1
Temporal
Sequence Input
Ht-2
LSTM Layer
Hidden State
Output Ht Ht+2Ht-1 Ht+1
52. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
The Gated Recurrent Unit (GRU) Cell
53. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Summary of RNN types
One to many
𝑎<0>
𝑥
ො𝑦<1>
ො𝑦<2>
ො𝑦<𝑇𝑦>
⋯
𝑥<2>
𝑥<𝑇𝑥>
𝑎<0>
𝑥<1>
ො𝑦
⋯
Many to one
𝑎<0>
𝑥<1>
ො𝑦<𝑇𝑦>
⋯
𝑥<2>
𝑥<𝑇𝑥>
ො𝑦<1>
ො𝑦<2>
Many to many (Seq2Seq) Many to many
(delayed Seq2Seq)
⋯ ⋯𝑎<0>
𝑥<1>
ො𝑦<1>
⋯
𝑥<𝑇𝑥>
ො𝑦<𝑇𝑦>
54. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DeepAR*
* Flunkert, Valentin, David Salinas, and Jan Gasthaus. “DeepAR: Probabilistic Forecasting with Autoregressive Recurrent Networks.”
ArXiv:1704.04110 [Cs, Stat], April 13, 2017. http://arxiv.org/abs/1704.04110.
• Amazon SageMaker 에서 시계열 예측 분석을 위한 RNN 아키텍처
(완전 관리형, 뛰어난 확장성, 높은 정확도)
• 특정 시점 예측 및 확률 기반 예측 (다양한 노이즈 모델들 중 선택 가능) 지원
• 트레이닝 데이터 내의 여러 가지 관련 시계열을 기반으로 한 학습
(cold start problem)
• Recursive Multi-Horizon 및 static categorical variables 지원
• Amazon에서 매우 중요한 의사결정 문제들을 해결하는 과정 중 만들어진
알고리즘
55. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DeepAR*
* Flunkert, Valentin, David Salinas, and Jan Gasthaus. “DeepAR: Probabilistic Forecasting with Autoregressive Recurrent Networks.”
ArXiv:1704.04110 [Cs, Stat], April 13, 2017. http://arxiv.org/abs/1704.04110.
Training Prediction
ancestral
sampling
Encoder DecoderSeq2Seq
t0
likelihood
sampling
likelihoo
d
𝐡𝑖,𝑡0−1
56. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Likelihood model of DeepAR
Neural network predicts all parameters (e.g. mean and variance) of
likelihood function
For the experiments, two choices:
• Gaussian likelihood: real-valued data
• Negative binomial likelihood: positive count data
57. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example Demand Forecasts
• Figure 1: cold start scenario. Since the model shares information across
items, predictions are reasonable even with limited historic data.
• Figure 2 & 3: probabilistic forecasts for products with different
magnitudes by using an appropriate likelihood function (Negative Binomial).
58. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo: Amazon SageMaker
59. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
참고 링크
• Getting started with Amazon SageMaker를 통한 실습:
• https://aws.amazon.com/sagemaker/
• Amazon SageMaker SDK 사용법 익히기:
• For Python: https://github.com/aws/sagemaker-python-sdk
• For Spark: https://github.com/aws/sagemaker-spark
• SageMaker Code Samples / Workshops:
• https://github.com/awslabs/amazon-sagemaker-examples
• https://github.com/awslabs/amazon-sagemaker-workshop
60. © 2018 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
더 나은 세미나를 위해 여러분의 의견을 남겨주세요!
웨비나 종료 후 설문이 시작됩니다.
질문에 대한 답변 드립니다.
발표자료 / 녹화 영상을 제공합니다.
http://bit.ly/awskr-webinar
AWS 데이터 기반 의사결정 웹세미나에
참석해주셔서 대단히 감사합니다.