Book Image

Practical Time Series Analysis

By : Avishek Pal, PKS Prakash
Book Image

Practical Time Series Analysis

By: Avishek Pal, PKS Prakash

Overview of this book

Time Series Analysis allows us to analyze data which is generated over a period of time and has sequential interdependencies between the observations. This book describes special mathematical tricks and techniques which are geared towards exploring the internal structures of time series data and generating powerful descriptive and predictive insights. Also, the book is full of real-life examples of time series and their analyses using cutting-edge solutions developed in Python. The book starts with descriptive analysis to create insightful visualizations of internal structures such as trend, seasonality, and autocorrelation. Next, the statistical methods of dealing with autocorrelation and non-stationary time series are described. This is followed by exponential smoothing to produce meaningful insights from noisy time series data. At this point, we shift focus towards predictive analysis and introduce autoregressive models such as ARMA and ARIMA for time series forecasting. Later, powerful deep learning methods are presented, to develop accurate forecasting models for complex time series, and under the availability of little domain knowledge. All the topics are illustrated with real-life problem scenarios and their solutions by best-practice implementations in Python. The book concludes with the Appendix, with a brief discussion of programming and solving data science problems using Python.
Table of Contents (13 chapters)

Preface

This book is about an introduction to time series analysis using Python. We aim to give you a clear overview of the basic concepts of the discipline and describe useful techniques that would be applicable for commonly-found analytics use cases in the industry. With too many projects requiring trend analytics and forecasting based on past data, time series analysis is an important tool in the knowledge arsenal of any modern data scientist. This book will equip you with tools and techniques, which will let you confidently think through a problem and come up with its solution in time series forecasting.

Why Python? Python is rapidly becoming a first choice for data science projects across different industry sectors. Most state-of-the art machine learning and deep learning libraries have a Python API. As a result, many data scientists prefer Python to implement the entire project pipeline that consists of data wrangling, model building, and model validation. Besides, Python provides easy-to-use APIs to process, model, and visualize time series data. Additionally, Python has been a popular language for the development of backend for web applications and hence has an appeal to a wider base of software professionals.

Now, let's see what you can expect to learn from every chapter this book.

What this book covers

Chapter 1, Introduction to Time Series, starts with a discussion of the three different types of datasets—cross-section, time series, and panel. The transition from cross-sectional to time series and the added complexity of data analysis is discussed. Special mathematical properties that make time series data special are described. Several examples demonstrate how exploratory data analysis can be used to visualize these properties.

Chapter 2, Understanding Time Series Data, covers three topics, advanced preprocessing and visualization of time series data through resampling, group-by, and calculation of moving averages; stationarity and statistical hypothesis testing to detect stationarity in a time series; and various methods of time series decomposition for stationarizing a non-stationary time series.

Chapter 3, Exponential Smoothing based Methods, covers smoothing-based models using the Holt-Winters approach for first order to capture levels, second order to smoothen levels and trend, and higher order smoothing is illustrated, which captures level, trend, and seasonality within a time series dataset.

Chapter 4, Auto-Regressive Models, discusses autoregressive models for forecasting. The chapter covers a detailed implementation for moving average (MA), autoregressive (AR), Auto Regressive Moving Average (ARMA), and Auto Regressive Integrated Moving Average (ARIMA) to capture different levels of nuisance within time series data during forecasting.

Chapter 5, Deep Learning for Time Series Forecasting, discusses recent deep learning algorithms that can be directly adapted to develop forecasting models for time series data. Recurrent Neural Networks (RNNs) are a natural choice for modeling sequence in data. In this chapter, different RNNs such as Vanilla RNN, Gated Recurrent Units, and Long Short Term Memory units are described to develop forecasting models on time series data. The mathematical formulations involved in developing these RNNs are conceptually discussed. Case studies are solved using the ‘keras’ deep learning library of Python.

Appendix, Getting Started with Python, you will find a quick and easy introduction to Python. If you are new to Python or looking for how to get started with the programming language, reading this appendix will help you get through the initial hurdles.

What you need for this book

You will need the Anaconda Python Distribution to run the examples in this book and write your own Python programs for time series analysis. This is freely downloadable from https://www.continuum.io/downloads.

The code samples of this book have been written using the Jupyter Notebook development environment. To run the Jupyter Notebooks, you need to install Anaconda Python Distribution, which has the Python language essentials, interpreter, packages used to develop the examples, and the Jupyter Notebook server.

Who this book is for

The topics in this book are expected to be useful for the following people:

  • Data scientists, professionals with a background in statistics, machine learning, and model building and validation
  • Data engineers, professionals with a background in software development
  • Software professionals looking to develop an expertise in generating data-driven business insights

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

A block of code is set as follows:

import os
import pandas as pd
%matplotlib inline
from matplotlib import pyplot as plt
import seaborn as sns

In-text code is highlighted in font and color as here: pandas.DataFrame. File and folder names are also shown in the same style, for example,  Chapter_1_Models_for_Time_Series_Analysis.ipynb or datasets/DJIA_Jan2016_Dec2016.xlsx

At several places in the book, we have referred to external URLs to cite source of datasets or other information. A URL would appear in the following text style: http://finance.yahoo.com

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "In order to download new modules, we will go to Files | Settings | Project Name | Project Interpreter."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply email [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files emailed directly to you. You can download the code files by following these steps:

  1. Log in or register to our website using your email address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Practical-Time-Series-Analysis. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.