Codeless Time Series Analysis with KNIME: A practical guide to implementing forecasting models for time series analysis applications
()
About this ebook
This book will take you on a practical journey, teaching you how to implement solutions for many use cases involving time series analysis techniques.
This learning journey is organized in a crescendo of difficulty, starting from the easiest yet effective techniques applied to weather forecasting, then introducing ARIMA and its variations, moving on to machine learning for audio signal classification, training deep learning architectures to predict glucose levels and electrical energy demand, and ending with an approach to anomaly detection in IoT. There’s no time series analysis book without a solution for stock price predictions and you’ll find this use case at the end of the book, together with a few more demand prediction use cases that rely on the integration of KNIME Analytics Platform and other external tools.
By the end of this time series book, you’ll have learned about popular time series analysis techniques and algorithms, KNIME Analytics Platform, its time series extension, and how to apply both to common use cases.
Related to Codeless Time Series Analysis with KNIME
Related ebooks
Hands-On Artificial Intelligence for Beginners: An introduction to AI concepts, algorithms, and their implementation Rating: 0 out of 5 stars0 ratingsMachine Learning with LightGBM and Python: A practitioner's guide to developing production-ready machine learning systems Rating: 0 out of 5 stars0 ratingsDeep Learning with PyTorch: A practical approach to building neural network models using PyTorch Rating: 0 out of 5 stars0 ratingsGo Machine Learning Projects: Eight projects demonstrating end-to-end machine learning and predictive analytics applications in Go Rating: 0 out of 5 stars0 ratingsThe Pandas Workshop: A comprehensive guide to using Python for data analysis with real-world case studies Rating: 0 out of 5 stars0 ratingsA Handbook of Mathematical Models with Python: Elevate your machine learning projects with NetworkX, PuLP, and linalg Rating: 0 out of 5 stars0 ratingsMachine Learning with the Elastic Stack.: Gain valuable insights from your data with Elastic Stack's machine learning features Rating: 0 out of 5 stars0 ratingsDeep Learning By Example: A hands-on guide to implementing advanced machine learning algorithms and neural networks Rating: 0 out of 5 stars0 ratingsThe Deep Learning Architect's Handbook: Build and deploy production-ready DL solutions leveraging the latest Python techniques Rating: 0 out of 5 stars0 ratingsHands-On Data Preprocessing in Python: Learn how to effectively prepare data for successful data analytics Rating: 0 out of 5 stars0 ratingsPython Machine Learning By Example: The easiest way to get into machine learning Rating: 5 out of 5 stars5/5Feature Engineering Made Easy: Identify unique features from your dataset in order to build powerful machine learning systems Rating: 0 out of 5 stars0 ratingsHands-On Machine Learning with ML.NET: Getting started with Microsoft ML.NET to implement popular machine learning algorithms in C# Rating: 0 out of 5 stars0 ratingsHands-On Neural Network Programming with C#: Add powerful neural network capabilities to your C# enterprise applications Rating: 0 out of 5 stars0 ratingsMachine Learning Fundamentals: Use Python and scikit-learn to get up and running with the hottest developments in machine learning Rating: 0 out of 5 stars0 ratingsTime Series Analysis on AWS: Learn how to build forecasting models and detect anomalies in your time series data Rating: 0 out of 5 stars0 ratingsPractical Data Analysis - Second Edition Rating: 0 out of 5 stars0 ratingsLearning Data Mining with Python Rating: 0 out of 5 stars0 ratingsEngineering MLOps: Rapidly build, test, and manage production-ready machine learning life cycles at scale Rating: 0 out of 5 stars0 ratingsPractical Convolutional Neural Networks: Implement advanced deep learning models using Python Rating: 0 out of 5 stars0 ratingsIntroduction to Machine Learning and Neural Classification Rating: 0 out of 5 stars0 ratings15 Math Concepts Every Data Scientist Should Know: Understand and learn how to apply the math behind data science algorithms Rating: 0 out of 5 stars0 ratings
Data Visualization For You
Data Analytics for Beginners: Introduction to Data Analytics Rating: 4 out of 5 stars4/5How to Lie with Maps Rating: 4 out of 5 stars4/5Data Visualization: A Practical Introduction Rating: 5 out of 5 stars5/5Data Analytics & Visualization All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsEffective Data Storytelling: How to Drive Change with Data, Narrative and Visuals Rating: 4 out of 5 stars4/5Visual Analytics with Tableau Rating: 0 out of 5 stars0 ratingsTeach Yourself VISUALLY Power BI Rating: 0 out of 5 stars0 ratingsHow to be Clear and Compelling with Data: Principles, Practice and Getting Beyond the Basics Rating: 0 out of 5 stars0 ratingsGoogle Analytics 4 Migration Quick Guide 2022: Universal Analytics disappears in July 2023 - are you ready? Rating: 0 out of 5 stars0 ratingsData Structures & Algorithms Interview Questions You'll Most Likely Be Asked Rating: 1 out of 5 stars1/5Learn Power BI: A comprehensive, step-by-step guide for beginners to learn real-world business intelligence Rating: 4 out of 5 stars4/5Salesforce Reporting and Dashboards Rating: 4 out of 5 stars4/5Data Visualization Guide Rating: 0 out of 5 stars0 ratingsThe Big Book of Dashboards: Visualizing Your Data Using Real-World Business Scenarios Rating: 4 out of 5 stars4/5How to Become a Data Analyst: My Low-Cost, No Code Roadmap for Breaking into Tech Rating: 0 out of 5 stars0 ratingsData Visualization with Excel Dashboards and Reports Rating: 4 out of 5 stars4/5Visualizing Graph Data Rating: 0 out of 5 stars0 ratingsLaTeX Graphics with TikZ: A practitioner's guide to drawing 2D and 3D images, diagrams, charts, and plots Rating: 0 out of 5 stars0 ratingsLearning PySpark Rating: 0 out of 5 stars0 ratingsChatgpt | Generative AI - The Step-By-Step Guide For OpenAI & Azure OpenAI In 36 Hrs. Rating: 0 out of 5 stars0 ratingsJupyter Cookbook: Over 75 recipes to perform interactive computing across Python, R, Scala, Spark, JavaScript, and more Rating: 0 out of 5 stars0 ratingsDAX Patterns: Second Edition Rating: 5 out of 5 stars5/5Mastering Python for Data Science Rating: 3 out of 5 stars3/5
Reviews for Codeless Time Series Analysis with KNIME
0 ratings0 reviews
Book preview
Codeless Time Series Analysis with KNIME - KNIME AG
BIRMINGHAM—MUMBAI
Codeless Time Series Analysis with KNIME
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Reshma Raman
Publishing Product Manager: Reshma Raman
Senior Editor: Nithya Sadanandan
Technical Editor: Pradeep Sahu
Copy Editor: Safis Editing
Project Coordinator: Deeksha Thakkar
Proofreader: Safis Editing
Indexer: Manju Arasan
Production Designer: Prashant Ghare
Marketing Coordinator: Priyanka Mhatre
First published: July 2022
Production reference: 1220722
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80323-206-5
www.packt.com
Thanks to my colleagues at KNIME for the technical support and encouragement, especially to Andisa Dewi and Tobias Kötter for the Taxi Demand Prediction application, and Rosaria Silipo, Phil Winters, and Iris Adä for the Anomaly Detection application.
– Maarit Widmann
I would like to thank the KNIME team for including me in this great project. Especially thanks to Rosaria Silipo, for her trust and support, and to my co-authors Maarit and Corey, for taking this long journey with me.
– Daniele Tonini
Contributors
About the authors
Corey Weisinger is a data scientist with KNIME in Austin, Texas. He studied mathematics at Michigan State University focusing on actuarial techniques and functional analysis. Before coming to work for KNIME, he worked as an analytics consultant for the auto industry in Detroit, Michigan. He currently focuses on signal processing and numeric prediction techniques and is the author of the From Alteryx to KNIME guidebook.
Maarit Widmann is a data scientist and an educator at KNIME: the instructor behind the KNIME self-paced courses and a teacher of the KNIME courses. She is the author of the From Modeling to Model Evaluation eBook and she publishes regularly on the KNIME blog and on Medium. She holds a master’s degree in data science and a bachelor’s degree in sociology.
Daniele Tonini is an experienced advisor and educator in the field of advanced business analytics and machine learning. In the last 15 years, he designed and deployed predictive analytics systems, and data quality management and dynamic reporting tools, mainly for customer intelligence, risk management, and pricing applications. He is an Academic Fellow at Bocconi University (Department of Decision Science) and SDA Bocconi School of Management (Decision Sciences & Business Analytics Faculty). He’s also an adjunct professor in data mining at Franklin University, Switzerland. He currently teaches statistics, predictive analytics for data-driven decision making, big data and databases, market research, and data mining.
About the reviewers
Miguel Infestas Maderuelo has a Ph.D. in applied economics and has developed his career around data analytics in different fields (digital marketing, data mining, academic research, and so on). His last project is as a founder of a digital marketing agency, applying analytics on digital data to optimize digital communication.
Rosaria Silipo, Ph.D., now head of data science evangelism at KNIME, has spent 25+ years in applied AI, predictive analytics, and machine learning at Siemens, Viseca, Nuance Communications, and private consulting. Sharing her practical experience in a broad range of industries and deployments, including IoT, customer intelligence, financial services, social media, and cybersecurity, Rosaria has authored 50+ technical publications, including her recent books Guide to Intelligent Data Science (Springer) and Codeless Deep Learning with KNIME (Packt).
Table of Contents
Preface
Part 1: Time Series Basics and KNIME Analytics Platform
Chapter 1: Introducing Time Series Analysis
Understanding TSA
Exploring time series properties and examples
Continuous and discrete time series
Independence and serial correlation
Time series examples
TSA goals and applications
Goals of TSA
Domains of applications and use cases
Exploring time series forecasting techniques
Quantitative forecasting properties and techniques
Summary
Questions
Chapter 2: Introduction to KNIME Analytics Platform
Exploring the KNIME software
Introducing KNIME Analytics Platform for creating data science applications
Introducing KNIME Server for productionizing data science applications
Introducing nodes and workflows
Introducing nodes
Introducing workflows
Searching for and sharing resources on the KNIME Hub
Building your first workflow
Creating a new workflow (group)
Reading and transforming data
Filtering rows
Visualizing data
Building a custom interactive view
Documenting workflows
Configuring the time series integration
Introducing the time series components
Configuring Python in KNIME
Summary
Questions
Chapter 3: Preparing Data for Time Series Analysis
Introducing different sources of time series data
Time granularity and time aggregation
Defining time granularity
Finding the right time granularity
Aggregating time series data
Equal spacing and time alignment
Explaining the concept of equal spacing
Missing value imputation
Defining the different types of missing values
Introducing missing value imputation techniques
Summary
Questions
Chapter 4: Time Series Visualization
Technical requirements
Introducing an energy consumption time series
Describing raw energy consumption data
Clustering energy consumption data
Introducing line plots
Displaying simple dynamics with a line plot
Interpreting the dynamics of a time series based on a line plot
Building a line plot in KNIME
Introducing lag plots
Introducing insights derived from a lag plot
Building a lag plot in KNIME
Introducing seasonal plots
Comparing seasonal patterns in a seasonal plot
Building a seasonal plot in KNIME
Introducing box plots
Inspecting variability of data in a box plot
Building a box plot in KNIME
Summary
Questions
Chapter 5: Time Series Components and Statistical Properties
Technical requirements
Trend and seasonality components
Trend
Seasonality
Decomposition
Autocorrelation
Stationarity
Summary
Questions
Part 2: Building and Deploying a Forecasting Model
Chapter 6: Humidity Forecasting with Classical Methods
Technical requirements
The importance of predicting the weather
Other IoT sensors
The use case
Streaming humidity data from an Arduino sensor
What is an Arduino?
Moving data to KNIME
Storing the data to create a training set
Resampling and granularity
Aligning data timestamps
Missing values
Aggregation techniques
Training and deployment
Types of classic models available in KNIME
Training a model in KNIME
Available deployment options
Building the workflow
Writing model predictions to a database
Summary
Questions
Chapter 7: Forecasting the Temperature with ARIMA and SARIMA Models
Recapping regression
Defining a regression
Introducing the (S)ARIMA models
Requirements of the (S)ARIMA model
How to configure the ARIMA or SARIMA model
Fitting the model and generating forecasts
The data
Summary
Further reading
Questions
Chapter 8: Audio Signal Classification with an FFT and a Gradient-Boosted Forest
Technical requirements
Why do we want to classify a signal?
Windowing your data
Windowing your data in KNIME
What is a transform?
The Fourier transform
Discrete Fourier Transform (DFT)
Fast Fourier Transform (FFT)
Applying the Fourier transform in KNIME
Preparing data for modeling
Reducing dimensionality
Training a Gradient Boosted Forest
Applying the Fourier transform in KNIME
Applying the Gradient Boosted Trees Learner
Deploying a Gradient Boosted Forest
Summary
Questions
Chapter 9: Training and Deploying a Neural Network to Predict Glucose Levels
Technical requirements
Glucose prediction and the glucose dataset
Glucose prediction
The glucose dataset
A quick introduction to neural networks
Artificial neurons and artificial neural networks
The backpropagation algorithm
Other types of neural networks
Training a feedforward neural network to predict glucose levels
KNIME Deep Learning Keras Integration
Building the network
Training the network
Scoring the network and creating the output rule
Deploying an FFNN-based alarm system
Summary
Questions
Chapter 10: Predicting Energy Demand with an LSTM Model
Technical requirements
Introducing recurrent neural networks and LSTMs
Recapping recurrent neural networks
The architecture of the LSTM unit
Forget Gate
Input Gate
Output Gate
Encoding and tensors
Input data
Reshaping the data
Training an LSTM-based neural network
The Keras Network Learner node
Deploying an LSTM network for future prediction
Scoring the forecasts
Summary
Questions
Chapter 11: Anomaly Detection – Predicting Failure with No Failure Examples
Technical requirements
Introducing the problem of anomaly detection in predictive maintenance
Introducing the anomaly detection problem
IoT data preprocessing
Exploring anomalies visually
Detecting anomalies with a control chart
Introducing a control chart
Implementing a control chart
Predicting the next sample in a correctly working system with an auto-regressive model
Introducing an auto-regressive model
Training an auto-regressive model with the linear regression algorithm
Deploying an auto-regressive model
Summary
Questions
Part 3: Forecasting on Mixed Platforms
Chapter 12: Predicting Taxi Demand on the Spark Platform
Technical requirements
Predicting taxi demand in NYC
Connecting to the Spark platform and preparing the data
Introducing the Hadoop ecosystem
Accessing the data and loading it into Spark
Introducing the Spark compatible nodes
Training a random forest model on Spark
Exploring seasonalities via line plots and auto-correlation plot
Preprocessing the data
Training and testing the random forest model on Spark
Building the deployment application
Predicting the trip count in the next hour
Predicting the trip count in the next 24 hours
Summary
Questions
Chapter 13: GPU Accelerated Model for Multivariate Forecasting
Technical requirements
From univariate to multivariate – extending the prediction problem
Building and training the multivariate neural architecture
Enabling GPU execution for neural networks
Setting up a new GPU Python environment
Switching Python environments dynamically
Building the deployment application
Summary
Questions
Chapter 14: Combining KNIME and H2O to Predict Stock Prices
Technical requirements
Introducing the stock price prediction problem
Describing the KNIME H2O Machine Learning Integration
Starting a workflow running on the H2O platform
Introducing the H2O nodes for machine learning
Accessing and preparing data within KNIME
Accessing stock market data from Yahoo Finance
Preparing the data for modeling on H2O
Training an H2O model from within KNIME
Optimizing the number of predictor columns
Training, applying, and testing the optimized model
Consuming the H2O model in the deployment application
Summary
Questions
Final note
Answers
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Other Books You May Enjoy
Preface
This book gives an overview of the basics of time series data and time series analysis and of KNIME Analytics Platform and its time series integration. It shows how to implement practical solutions for a wide range of use cases, from demand prediction to signal classification and signal forecasting, and from price prediction to anomaly detection. It also demonstrates how to integrate other tools in addition to KNIME Analytics Platform within the same application.
The book instructs you on common preprocessing steps of time series data and statistics and machine learning-based techniques for forecasting. These things need to be learned to master the field of time series analysis. The book also points you to examples implemented in KNIME Analytics Platform, which is a visual programming tool that is accessible and fast to learn. This removes the common time and skill barrier of learning to code.
Who this book is for
This book is for data analysts and data scientists who want to develop forecasting applications on time series data. The first part of the book targets beginners in time series analysis by introducing the main concepts of time series analysis and visual exploration and preprocessing of time series data. The subsequent parts of the book challenge both beginners and advanced users by introducing real-world time series analysis applications.
What this book covers
Chapter 1, Introducing Time Series Analysis, explains what a time series is, states some classic time series problems, and introduces the two historical approaches: statistics and machine learning.
Chapter 2, Introduction to KNIME Analytics Platform, explains the basic concepts of KNIME Analytics Platform and its time series integration. This chapter covers installation, an introduction to the platform, and a first workflow example.
Chapter 3, Preparing Data for Time Series Analysis, introduces the common first steps in a time series analysis project. It explores different sources of time series data and shows time alignment, time aggregation, and missing value imputation as common preprocessing steps.
Chapter 4, Time Series Visualization, explores time series visualization. It provides an exploration of the most common visualization techniques to visually represent and display the time series data: from the classic line plot to the lag plot, and from the seasonal plot to the box plot.
Chapter 5, Time Series Components and Statistical Properties, introduces common concepts and measures for descriptive statistics of time series, including the decomposition of a time series, autocorrelation measures and plots, and the stationarity property.
Chapter 6, Humidity Forecasting with Classical Methods, completes a classic time series analysis use case: forecasting. It introduces some simple yet powerful classical methods, which often solve the time series analysis problem quickly without much computational expense.
Chapter 7, Forecasting the Temperature with ARIMA and SARIMA Models, delves into the ARIMA and SARIMA models. It aims at predicting tomorrow’s temperatures with the whole range of ARIMA models: AR, ARMA, ARIMA, and SARIMA.
Chapter 8, Audio Signal Classification with an FFT and a Gradient Boosted Forest, introduces a use case for signal classification. It performs the classification of audio signals via a Gradient Boosted Forest model and the FFT transforms the raw audio signals before modeling.
Chapter 9, Training and Deploying a Neural Network to Predict Glucose Levels, gives an example of a critical prediction problem: predicting the glucose level for a timely insulin intervention. This chapter also introduces neural networks.
Chapter 10, Predicting Energy Demand with an LSTM Model, introduces recurrent neural networks based on Long Short Term Memory (LSTM) layers, which are advanced predictors when temporal context is involved. It tests whether the prediction accuracy improves considerably from an ARIMA model when using a recurrent LSTM-based neural network.
Chapter 11, Anomaly Detection – Predicting Failure with No Failure Examples, tackles the problem of anomaly detection in predictive maintenance by introducing approaches that work exclusively on the data from a correctly working system.
Chapter 12, Predicting Taxi Demand on the Spark Platform, implements a solution to the demand prediction problem via a Random Forest to run on a Spark platform in an attempt to make the solution more scalable.
Chapter 13, GPU Accelerated Model for Multivariate Forecasting, extends the demand prediction problem to a multivariate by taking into account exogenous time series as well, and scalable, by training the recurrent neural network on a GPU-enabled machine.
Chapter 14, Combining KNIME and H2O to Predict Stock Prices, describes the integration of KNIME Analytics Platform with H2O, another open source platform, to implement a solution for stock price prediction.
To get the most out of this book
This book will introduce the basics of the open source visual programming tool KNIME Analytics Platform and time series analysis. Basic knowledge of data transformations is assumed, while no coding skills are required thanks to the codeless implementation of the examples. Python installation is required for using the time series integration in KNIME.
The installation of some use case-specific extensions and integrations will be indicated and instructed in the respective chapters. We will introduce KNIME Server for enterprise features in Chapter 2, Introduction to KNIME Analytics Platform, but all practical examples are implemented in the open source KNIME Analytics Platform.
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 (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Codeless-Time-Series-Analysis-with-KNIME and https://hub.knime.com/knime/spaces/Codeless%20Time%20Series%20Analysis%20with%20KNIME/latest/~GxjXX6WmLi-WjLNx/. If there’s an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/2RomT.
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: For example, the ../sales.csv workflow relative path reads the sales.csv file located in the same workflow group as the executing workflow.
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: If you want to do that, you will need to unlink it via the component’s context menu by selecting Component | Disconnect Link.
Tips or Important Notes
Appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Share Your Thoughts
Once you’ve read Codeless Time Series Analysis with KNIME, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
Part 1: Time Series Basics and KNIME Analytics Platform
By the end of this part, you will know what a time series is, how to preprocess, visualize, and explore it, and how to configure and use KNIME Analytics Platform for time series analysis. The following are the chapters included in this part:
Chapter 1, Introducing Time Series Analysis
Chapter 2, Introduction to KNIME Analytics Platform
Chapter 3, Preparing Data for Time Series Analysis
Chapter 4, Time Series Visualization
Chapter 5, Time Series Components and Statistical Properties
Chapter 1: Introducing Time Series Analysis
In this introductory chapter, we’ll examine the concept of time series, explore some examples and case studies, and then understand how Time Series Analysis (TSA) can be useful in different frameworks and applications. Finally, we’ll provide a brief overview of the forecasting models used over the years, highlighting their key features, which will be further explored in the following chapters.
In this chapter, we will cover the following topics:
Understanding TSA and its importance within data analytics
Time series properties and examples
TSA goals and applications
Overview of the main forecasting techniques used over the years
By the end of the chapter, you will have a good understanding of the key aspects of TSA, gaining the foundation to explore the subsequent chapters of the book with greater confidence.
Understanding TSA
When analyzing business data, it’s quite common to focus on what happened at a particular point in time: sales figures at the end of the month, customer characteristics at the end of the year, conversion results at the end of a marketing campaign, and more. Even in the development of the most sophisticated ML models, in most cases, we collect information that refers to different objects at a specific instant in time (or by taking a few snapshots of historical data). This approach, which is absolutely valid and correct for many applications, not only in business, uses cross-sectional data as the basis for analytics: data collected by observing many subjects (such as individuals, companies, shops, countries, equipment, and more) at one point or period of time.
Although the fact of not considering the temporal factor in the analysis is widespread and rooted in common practice, there are several situations where the analysis of the temporal evolution of a phenomenon provides more complete and interesting results. In fact, it’s only through the analysis of the temporal dynamics of the data that it is possible to identify the presence of some peculiar characteristics of the phenomenon we are analyzing, be it sales/consumption data, rather than a physical parameter or a macroeconomic index. These characteristics that act over time, such as trends, periodic fluctuations, level changes, anomalous observations, turning points, and more can have an effect in the short or long term, and often, it is important to be able to measure them precisely. Furthermore, it is only by analyzing data over time that it is possible to provide a reliable quantitative estimate of what might occur in the future (whether immediate or not). Since economic conditions are constantly changing over time, data analysts must be able to assess and predict the effects of these changes in order to suggest the most appropriate actions to take for the future.
For these reasons, TSA can be a very useful tool in the hands of business analysts and data scientists when it comes to both describing the patterns of a phenomenon along the time axis and providing a reliable forecast for it. Through the use of the right tools, TSA can significantly expand the understanding of any variable of interest (typically numerical) such as sales, financial KPIs, logistic metrics, sensors’ measurements, and more. More accurate and less biased forecasts that have been obtained through quantitative TSA can be one of the most effective drivers of performance in many fields and industries.
In the next sections of this chapter, we will provide definitions, examples, and some additional elements to gain a further understanding of how to recognize some key features of time series and how to approach their analyses in a structured way.
Exploring time series properties and examples
A general definition of a time series is the following:
A Time Series is a collection of observations made sequentially through time, whose dynamics are often characterized by short/long period fluctuations and/or long period direction.
This definition highlights two fundamental aspects of a time series: the fact that observations are a function of time and that, as a consequence of this fact, some typical temporal features are often observed. The fluctuations and the long period direction of the series are just some of these features, as there might be other relevant aspects to take into consideration such as autocorrelation, stationarity, and the order of integration. We will explore these aspects in more detail in future chapters. In this section, we will focus on the distinction between discrete time series and continuous time series, on the concept of independence between observations, and finally, we will show some examples of real-world time series.
Continuous and discrete time series
A Time Series is defined as continuous when observations are collected continuously over time, that is, there can be an infinite number of observations in a given time range. Typically, continuous time series data is sampled at irregular time intervals. Consider the measurement of a patient’s blood pressure in a hospital done at varying time points during the day, not equally spaced. This happens because, in some settings, regular monitoring at fixed intervals is not possible. For instance, in Figure 1.1, there are four medical continuous time series, relative to the health parameters of four patients:
Mean blood pressure
Heart rate
Temperature
Glucose data
As evident from the graphs, there are some temporal ranges where the measures are not present, for example, the temperature and glucose between approximately 20 hours and 30 hours of the monitoring period. There are other time points where data is collected more frequently than in other periods. These time series features are due to the fact that the data has been collected manually by the physician or by the nurse, not at fixed moments of the day. Therefore, this type of time series is inherently irregularly sampled:
Figure 1.1 – Four continuous, irregularly sampled, medical time seriesFigure 1.1 – Four continuous, irregularly sampled, medical time series
A time series is defined as discrete when observations are collected regularly at specific times, typically equally spaced (that is, hourly, daily, weekly, and yearly data points).
A time series of this type can be natively discrete, such as the annual budget data of a company, or it can be created through the aggregation or accumulation of a numerical variable in equal time intervals. For example, the monthly sales of a supermarket or the number of daily passengers in a train station. A continuous time series can be discretized by binning/grouping the original data and, eventually, obtaining a discrete time series.
Classical TSA focuses on discrete time series because they are more common in real-world applications and easier to analyze. Therefore, in this book, we mainly deal with discrete time series, where observations are collected at equal intervals. When we consider irregularly sampled time series, first, we will try to transform them into regularly sampled data points.
Independence and serial correlation
One of the most distinctive characteristics of a time series is the mutual dependence between the observations, generally called serial correlation or autocorrelation.
In many statistical models, observations are assumed to be generated by a random sampling process and to be independent of each other (consider the linear regression model). Typically, this assumption turns out to be inconsistent with time series data, where simply collecting the data sequentially, along the time axis, generally produces observations that are not independent of each other.
Think of the daily sales of an e-commerce company. It’s