Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Modern Time Series Forecasting with Python

You're reading from   Modern Time Series Forecasting with Python Explore industry-ready time series forecasting using modern machine learning and deep learning

Arrow left icon
Product type Paperback
Published in Nov 2022
Publisher Packt
ISBN-13 9781803246802
Length 552 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Manu Joseph Manu Joseph
Author Profile Icon Manu Joseph
Manu Joseph
Arrow right icon
View More author details
Toc

Table of Contents (26) Chapters Close

Preface 1. Part 1 – Getting Familiar with Time Series
2. Chapter 1: Introducing Time Series FREE CHAPTER 3. Chapter 2: Acquiring and Processing Time Series Data 4. Chapter 3: Analyzing and Visualizing Time Series Data 5. Chapter 4: Setting a Strong Baseline Forecast 6. Part 2 – Machine Learning for Time Series
7. Chapter 5: Time Series Forecasting as Regression 8. Chapter 6: Feature Engineering for Time Series Forecasting 9. Chapter 7: Target Transformations for Time Series Forecasting 10. Chapter 8: Forecasting Time Series with Machine Learning Models 11. Chapter 9: Ensembling and Stacking 12. Chapter 10: Global Forecasting Models 13. Part 3 – Deep Learning for Time Series
14. Chapter 11: Introduction to Deep Learning 15. Chapter 12: Building Blocks of Deep Learning for Time Series 16. Chapter 13: Common Modeling Patterns for Time Series 17. Chapter 14: Attention and Transformers for Time Series 18. Chapter 15: Strategies for Global Deep Learning Forecasting Models 19. Chapter 16: Specialized Deep Learning Architectures for Forecasting 20. Part 4 – Mechanics of Forecasting
21. Chapter 17: Multi-Step Forecasting 22. Chapter 18: Evaluating Forecasts – Forecast Metrics 23. Chapter 19: Evaluating Forecasts – Validation Strategies 24. Index 25. Other Books You May Enjoy

To get the most out of this book

You should have basic familiarity with Python programming, as the entire code that we use for the practical sections is in Python. Familiarity with major libraries in Python, such as pandas and scikit-learn, are not essential (because the book covers some basics) but will help you get through the book much faster. Familiarity with PyTorch, the framework the book uses for deep learning, is also not essential but would accelerate your learning by many folds. Any of the software requirements shouldn’t stop you because, in today’s internet-enabled world, the only thing that is standing between you and a world of knowledge is the search bar in your favorite search engine.

Another key aspect to get the most out of this book is to run the associated notebooks as you go along the lessons. Also, feel free to experiment with different variations that the book doesn’t go into. That is a surefire way to internalize what’s being talked about in the book. And for that, we need to set up an environment, as you’ll see in the following section.

Setting up an environment

The easiest way to set up an environment is by using Anaconda, a distribution of Python for scientific computing. You can use Miniconda, a minimal installer for Conda, as well if you do not want the pre-installed packages that come with Anaconda:

  1. Install Anaconda/Miniconda: Anaconda can be installed from https://www.anaconda.com/products/distribution. Depending on your operating system, choose the corresponding file and follow the instructions. Alternatively, you can install Miniconda from here: https://docs.conda.io/en/latest/miniconda.html#latest-miniconda-installer-links.
  2. Open conda prompt: To open Anaconda Prompt (or Terminal on Linux or macOS), do the following:
    • Windows: Open the Anaconda Prompt (Start | Anaconda Prompt)
    • macOS: Open Launchpad and then open Terminal. Type conda activate.
    • Linux: Open Terminal. Type conda activate.
  3. Navigate to the downloaded code: Use operating system-specific commands to navigate to the folder where you have downloaded the code. For instance, in Windows, use cd.
  4. Install the environment: Using the anaconda_env.yml file that is included, install the environment:
    conda env create -f anaconda_env.yml

This creates a new environment under the name modern_ts and will install all the required libraries in the environment. This can take a while.

  1. Checking the installation: We can check whether all the libraries required for the book are installed properly by executing a script in the downloaded code folder:
    python test_installation.py
  2. Activating the environment and running notebooks: Every time you want to run the notebooks, first activate the environment using the conda activate modern_ts command and then use the Jupyter Notebook (jupyter notebook) or JupyterLab (jupyter lab), according to your preference.

Download the data

You are going to be using a single dataset throughout the book. The book uses the London Smart Meters dataset from Kaggle for this purpose. Therefore, if you don’t have an account with Kaggle, please go ahead and create one: https://www.kaggle.com/account/login?phase=startRegisterTab.

There are two ways you can download the data-automated and manual.

For the automated way, we need to download a key from Kaggle. Let’s do that first (if you are going to choose the manual way, you can skip this):

  1. Click on your profile picture in the top-right corner of Kaggle.
  2. Select Account, and find the section for API.
  3. Click the Create New API Token button. A file with the name kaggle.json will be downloaded.
  4. Copy the file and place it in the api_keys folder in the downloaded code folder.

Now that we have kaggle.json downloaded and placed in the right folder, let’s look at the two methods to download data:

Method one – automated download

  1. Activate the environment using conda activate modern_ts.
  2. Run the provided script from the root directory of the downloaded code:
    python scripts/download_data.py

That’s it. Now, just wait for the script to finish downloading, unzip it, and organize the files in the expected format.

Method two – manual download

  1. Go to https://www.kaggle.com/jeanmidev/smart-meters-in-london and download the dataset.
  2. Unzip the contents to data/london_smart_meters.
  3. Unzip hhblock_dataset to get the raw files we want to work with.
  4. Make sure the unzipped files are in the expected folder structure (see the next section).

Now that you have downloaded the data, we need to make sure it is arranged in the following folder structure. The automated download does it automatically, but with the manual download, this structure needs to be created. To avoid ambiguity, the expected folder structure can be found as follows:

data
├── london_smart_meters
│   ├── hhblock_dataset
│   │   ├── hhblock_dataset
│   │       ├── block_0.csv
│   │       ├── block_1.csv
│   │       ├── ...
│   │       ├── block_109.csv
│── acorn_details.csv
├── informations_households.csv
├── uk_bank_holidays.csv
├── weather_daily_darksky.csv
├── weather_hourly_darksky.csv

There can be additional files as part of the extraction process. You can remove them without impacting anything. There is a helpful script that checks this structure.

python test_data_download.py

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository. Doing so will help you avoid any potential errors related to the copying and pasting of code.

The code that is provided along with the book is in no way a library but more of a guide for you to start experimenting on. The amount of learning you can derive from the book and code is directly proportional to how much you experiment with the code and stray outside your comfort zone. So, go ahead and start experimenting and putting the skills you pick up in the book to good use.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image