Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
149 views
Time Series Forecasting With DeepAR
Uploaded by
ante mitar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Time Series Forecasting With DeepAR For Later
Download
Save
Save Time Series Forecasting With DeepAR For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
149 views
Time Series Forecasting With DeepAR
Uploaded by
ante mitar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Time Series Forecasting With DeepAR For Later
Carousel Previous
Carousel Next
Save
Save Time Series Forecasting With DeepAR For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 6
Search
Fullscreen
Time Series Forecasting with DeepAR ee) Nov 20,2020: minread With enormous source and volume of time-series data, detecting timely patterns in data is becoming a crucial part of analyzing and decision making in many businesses. Knowing the future beforehand helps decision-makers to plan their strategies in accordance with the intent of customers gaining a massive advantage. Betterment with forecasting models has increased in complexity along with the capabilities to capture previously unnoticed correlations. In this blog, we are going to discuss the Deep Autoregressive model (DeepAR), which is one of the built-in algorithms for Amazon Sagemaker. Amazon SageMaker First, let us get some information on Amazon SageMaker before we jump into DeepAR. Every developer and data scientist goes through hours just installing frameworks and libraries required for specific projects however end up yet wrangling the installation manager. To take away these hurdles in ML development steps, Amazon Sagemaker has been around the corner. Amazon SageMaker is a fully managed service that provides the ability to build, train, and deploy models quickly. It is a web-based visual interface that makes ML development steps easier and faster at a lower cost. Amazon SageMaker notebooks are Jupyter notebooks in an EC2 instance dedicated to run your environments, and codes for feature engineering to building a model. The notebook instance is automatically configured with AWS configuration for reaching access from notebook instances to other AWS services. ‘The EC2 instance can be selected and resized according to the feature engineering and training jobs demands. The AWS console logs all training jobs and we can see where it is, where the model is, and also the dataset used. SageMaker creates RESTful API no matter where the model was trained, the pre-trained model can host on SageMaker using Docker containers. Amazon has come with Amazon SageMaker Studio thatprovides experiment management to easily view and track progress against projects. DeepAR In this blog post, we are going to forecast time-series based on the past trends of multiple factors with the help of the DeepAR algorithm. AWS’s DeepAR algorithm is a time-series forecasting using Recurrent Neural Network (RNN) having the capability of producing point and probabilistic forecasts. ‘The dataset we will be using is the electricity load profile of Nepal consumed for the year 2016, recorded at an interval of an hour. This is an actual dataset taken from Nepal Electricity Authority, where the load is in Megawatt units. Since our dataset has only one time-series, we will not be dealing with a “scale” problem but DeepAR is also capable of handling multiple time-series in a single model creating a global model. It even has the potential to solve a cold start problem i.e to generate forecasts for new time-series that do not have historical time series but are similar to the ones it has been trained on. Let’s get started, Loading the dataset The electricity dataset found was stored monthly in a .csv format according to the Nepali calendar, After cleaning the data and reshaping the granularity to hourly, the preprocessed data is stored in a pickle format. Let’s take a quick look at our dataset. data = pd.read_pickle(*elec_df.pkl") data.nead() Load Date 2016.04-1302:00:00 717.49 2016-04-13 05:00:00 707.64 2016-04-13 04:00:00 706.44 2016-04-13 06:00:00 737.34 Splitting the dataset Splitting a dataset is different when working with time-series. Unlike other datasets, we are not going to split 80-20 as we would.start_dataset = pd.Timestamp("2010-04-13 @1:¢0:00", freq=freq) end_training = pd. Timestamp("2017-@4-@6 01:20:00", freq-freq) training data - [ { "start": str(start_dataset), “target”: data[start_dataset:end_training - 1].Load.values.round(2).tolist() The training dataset is prepared by removing certain data points from each sample. While for the test set a full dataset can be used. testdata = [ { start": str(start_dataset), “target”: data[start_dataset:end_training + prediction_length].Load.values.round(2).tolist() Writing in JSON format ‘The DeepAR accepts input in the form of JSON lines: one sample per line, such as. [{'start’: 2016-04-13 01:00:00", ‘target’: [682.14, 717.49, 707.64, 706.44, 737.34, 1520.08, 1568.08,......1}] def unite_dicts_to_file(path, data): with open(path, ‘wb") as fp: for din data: 4p.write(json.dunps(d) encode("ut¥-8")) fp.write(”\n" .encede(‘ut#-8")) soet Ane write dicts to file("train hourly. json", training data) write dicts to file("test_hourly.json", test_data) The JSON format is then uploaded to the s3 bucket. Training Job Configuration For built-in algorithms, we need to select containers as the same region we run in and then create an estimator.Inage_nane ~ sagemsker amazon. anazon_estimator.get_inage_uri(region, "forecasting-deepar", “letest") ae eee Ssagensker_session-sogenaker session, fae Tecate tees role-roie, train_instance_count-2,] ‘train_instance_type='m.né.xlarge’, base_job_nane-"deepar-electricity-nea-hourly" , s_output_path Training the model Just fit the input data into the estimator that we recently configured. After the training is completed, the training model is provided with different metrics like RMSE, mean_absolute_QuantileLoss, a loss for different quantiles, ete. atime in/” format (s3_data_path), format (s3_data_path) 2 "{}/test! estimator. fit(inputs-data_channels, wait-True) 2020-26-03 2020-26-03 e2 Starting - Starting the training joo. :05 Starting - Launching requested ML instances 2020-06-03 14 Starting - Preparing the instances for training... 2020-06-03 58 Dounloading - Downloading input data... 2020-@6-03 05:55:21 Training - Downloading the training image... Deploying the model Now we will be required to create an endpoint hosting our model and create a predictor to send requests to. predictor = estimator deploy( initial_instance_count=1, instancé_type="ml.m4.xlarge’, predictor_cls-DeeparPredictor) Getting Prediction To get the prediction we are sending JSON formatted samples and a list of quantiles as an optional configuration. The inference format for DeepAR can be found here.context_ts, target_ts, forecast_day = get_data for_inference(test, ©) predictions - predictor.predict(ts-context ts, quantiles-[@.1, 8.2, 0.3, @.4, 8.5, 0.6, 8.7, @.8, 0.9]) Plotting predicted results Plotting is a way that everyone loves and understands what is happening. Let’s plot our prediction along with ground truth value to see how well the trained model is predicting. 2017-08-06 2017-0407 2017-08-08 2017-0809 2017-0410 «2017-0411 2017.0812 2017-04-13. Timestamp Conclusion Using deepAR we can focus on experimenting with our time series to get the best possible results, without worrying about the internal infrastructure. We can get the job done very quickly as there is no need to write any training code. All we need to do is prepare the data and do the necessary tunings to refine the model if needed. The results are even better when we have hundreds of related time series, and we will also have a single model for all the time series (although this is not the case here, but that’s how it is in the real world data). Tcouldn’t have written this article without the support of Ayush Bhattarai. Tanks! Originally posted on https://Awww. gritfeat.com/time-series-forecasting-with-deepar/Sign up for Analytics Vidhya News Bytes By Analytics Vidhya Latest news from Analytics Vidhya on our Hackathons and some of our best articles! Take a look. Emails willbe sent to ante.mitar@gmailcom. Not you? AWS — MachineLearning Forecasting -Timeseries_-Deepar About Help Legal Get the Medium app wo eee an
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6134)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (935)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4973)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1988)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1994)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
Introduction To Graph Theory. Implementation of The Graph Using The Python Language.
PDF
No ratings yet
Introduction To Graph Theory. Implementation of The Graph Using The Python Language.
18 pages
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
List of Exoplanets Discovered in 2021
PDF
No ratings yet
List of Exoplanets Discovered in 2021
5 pages
The Graph Theory - An Introduction in Python
PDF
No ratings yet
The Graph Theory - An Introduction in Python
10 pages
List of Exoplanets Discovered in 2015
PDF
No ratings yet
List of Exoplanets Discovered in 2015
6 pages
List of Exoplanets Discovered in 2016
PDF
No ratings yet
List of Exoplanets Discovered in 2016
32 pages
AUTOARIMA Python
PDF
No ratings yet
AUTOARIMA Python
16 pages
Getting Started With Graph Analysis in Python With Pandas and Networkx
PDF
No ratings yet
Getting Started With Graph Analysis in Python With Pandas and Networkx
8 pages
How To Develop LSTM Models For Time Series Forecasting
PDF
100% (1)
How To Develop LSTM Models For Time Series Forecasting
188 pages
A Deep Dive On Vector Autoregression in R by Justin Eloriaga Towards Data Science
PDF
No ratings yet
A Deep Dive On Vector Autoregression in R by Justin Eloriaga Towards Data Science
18 pages
House Price Prediction With Machine Learning in Python
PDF
No ratings yet
House Price Prediction With Machine Learning in Python
16 pages
Hidden Gems of Python
PDF
No ratings yet
Hidden Gems of Python
8 pages
How To Use Facebooks Neuralprophet and Why It Is So Powerful
PDF
No ratings yet
How To Use Facebooks Neuralprophet and Why It Is So Powerful
18 pages
How To Connect and Use A Geospatial Database in Python
PDF
No ratings yet
How To Connect and Use A Geospatial Database in Python
5 pages
Weather Forecasting - Implementation and Analysis of Different Machine Learning Models
PDF
No ratings yet
Weather Forecasting - Implementation and Analysis of Different Machine Learning Models
21 pages
Time Series Decomposition - ETS Model Using Python
PDF
No ratings yet
Time Series Decomposition - ETS Model Using Python
6 pages
Time Series Forecasting Using Autoarima Python
PDF
No ratings yet
Time Series Forecasting Using Autoarima Python
9 pages
2
PDF
No ratings yet
2
2 pages
Ay1 Lec16
PDF
No ratings yet
Ay1 Lec16
55 pages
Time Series Predictions Using Arima & Sarimax
PDF
No ratings yet
Time Series Predictions Using Arima & Sarimax
7 pages
ARIMA Wikipedia
PDF
No ratings yet
ARIMA Wikipedia
7 pages
Tsar Bomba
PDF
No ratings yet
Tsar Bomba
15 pages
Ay1 - Lecture 20: Dark Matter, Dark Energy, and The Concordance Cosmology
PDF
No ratings yet
Ay1 - Lecture 20: Dark Matter, Dark Energy, and The Concordance Cosmology
28 pages
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)