Statistics
4
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-06-18

AuthorBanglore Vijay Kumar Vishwas, Sri Ram Macharla

"Time Series Forecasting Using Generative AI introduces readers to Generative Artificial Intelligence (Gen AI) in time series analysis, offering an essential exploration of cutting-edge forecasting methodologies." The book covers a wide range of topics, starting with an overview of Generative AI, where readers gain insights into the history and fundamentals of Gen AI with a brief introduction to large language models. The subsequent chapter explains practical applications, guiding readers through the implementation of diverse neural network architectures for time series analysis such as Multi-Layer Perceptrons (MLP), WaveNet, Temporal Convolutional Network (TCN), Bidirectional Temporal Convolutional Network (BiTCN), Recurrent Neural Networks (RNN), Long Short-Term Memory (LSTM), Deep AutoRegressive(DeepAR), and Neural Basis Expansion Analysis(NBEATS) using modern tools. Building on this foundation, the book introduces the power of Transformer architecture, exploring its variants such as Vanilla Transformers, Inverted Transformer (iTransformer), DLinear, NLinear, and Patch Time Series Transformer (PatchTST). Finally, The book delves into foundation models such as Time-LLM, Chronos, TimeGPT, Moirai, and TimesFM enabling readers to implement sophisticated forecasting models tailored to their specific needs. This book empowers readers with the knowledge and skills needed to leverage Gen AI for accurate and efficient time series forecasting. By providing a detailed exploration of advanced forecasting models and methodologies, this book enables practitioners to make informed decisions and drive business growth through data-driven insights. Who this book is for: Data Scientists, Machine learning engineers, Business Aanalysts, Statisticians, Economists, Financial Analysts, Operations Research Analysts, Data Analysts, Students.

AI Reading Assistant

Summary and highlights from this book's index; jump to passages in the text

Passage locations
Tags
No tags
ISBN: 8868812754
Publisher: Apress
Publish Year: 2025
Language: 英文
Pages: 226
File Format: PDF
File Size: 12.6 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
Time Series Forecasting Using Generative AI Leveraging AI for Precision Forecasting Banglore Vijay Kumar Vishwas Sri Ram Macharla
Time Series Forecasting Using Generative AI: Leveraging AI for Precision Forecasting ISBN-13 (pbk): 979-8-8688-1275-0 ISBN-13 (electronic): 979-8-8688-1276-7 https://doi.org/10.1007/979-8-8688-1276-7 Copyright © 2025 by Banglore Vijay Kumar Vishwas and Sri Ram Macharla This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically, the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisition Editor: Celestin Suresh John Editorial Assistant: Kripa Joseph Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https://www.apress. com/gp/services/source-code. If disposing of this product, please recycle the paper Banglore Vijay Kumar Vishwas San Diego, CA, USA Sri Ram Macharla Montville, NJ, USA
To my parents Rathnamma and Vijay Kumar, who nurtured the seeds of knowledge planted within me. —Vishwas To my Mom and Dad Mrs. Satyavathi Macharla, Retd. Mgr ECIL Mr. Narayana Murthy Macharla, Retd. Mgr ECIL And in memory of my grandfather Mr. M.V.S.N. Murthy. 100% of the royalty I receive from the sale of this book will be donated to St. Jude Children's Research Hospital. —Sri Ram Macharla
v About the Authors ��������������������������������������������������������������������������������ix About the Technical Reviewer �������������������������������������������������������������xi Acknowledgments �����������������������������������������������������������������������������xiii Introduction ����������������������������������������������������������������������������������������xv Chapter 1: Time Series Meets Generative AI ����������������������������������������1 What Sparked Interest in Time Series? �����������������������������������������������������������������1 Introduction to Time Series Analysis ���������������������������������������������������������������������2 1�1 Characteristics of Time Series Data ����������������������������������������������������������3 1�2 Time Series Forecasting Methods �������������������������������������������������������������4 1�3 Introduction to Generative AI ���������������������������������������������������������������������8 1�4 Evolution from AI to Generative AI �������������������������������������������������������������9 1�5 Generative AI with Time Series ����������������������������������������������������������������13 1�6 Introduction to Large Language Models ��������������������������������������������������15 1�7 Summary �������������������������������������������������������������������������������������������������16 1�8 References ����������������������������������������������������������������������������������������������16 Chapter 2: Neural Networks for Time Series ��������������������������������������17 2 Introduction to Perceptron �������������������������������������������������������������������������������17 2�1 Technical Overview of a Perceptron ��������������������������������������������������������19 2�2 What Is Multilayer Perceptron? ���������������������������������������������������������������21 2�3 CNN-Based Architecture for Time Series �������������������������������������������������27 2�5 Neural Networks for Sequential Data ������������������������������������������������������50 Table of Contents
vi 2�6 Neural Networks Based on Autoregression ���������������������������������������������64 2�7 Neural Basis Expansion Analysis �������������������������������������������������������������74 2�8 Summary �������������������������������������������������������������������������������������������������80 2�9 References ����������������������������������������������������������������������������������������������80 Chapter 3: Transformers for Time Series ��������������������������������������������83 3 Introduction to Transformers ����������������������������������������������������������������������������83 3�1 Technical Overview of Transformers ��������������������������������������������������������84 3�2 Vanilla Transformer ����������������������������������������������������������������������������������94 3�3 Inverted Transformers ���������������������������������������������������������������������������102 3�4 DLinear ��������������������������������������������������������������������������������������������������109 3�5 NLinear ��������������������������������������������������������������������������������������������������118 3�6 Patch Time Series Transformer ��������������������������������������������������������������122 3�7 Summary �����������������������������������������������������������������������������������������������129 3�8 References ��������������������������������������������������������������������������������������������130 Chapter 4: Time-LLM: Reprogramming Large Language Model �������131 4 Fine-Tuning vs� Reprogramming ��������������������������������������������������������������������132 4�1 Technical Overview of Time-LLM �����������������������������������������������������������133 4�2 Time-LLM in Action ��������������������������������������������������������������������������������138 4�3 Summary �����������������������������������������������������������������������������������������������153 4�4 Reference ����������������������������������������������������������������������������������������������154 Chapter 5: Chronos: Pre-trained Probabilistic Time Series Model ���155 5 Introduction ����������������������������������������������������������������������������������������������������155 5�1 Technical Overview of Chronos �������������������������������������������������������������156 5�2 Time Series Tokenization �����������������������������������������������������������������������157 5�3 Training ��������������������������������������������������������������������������������������������������158 5�4 Inference �����������������������������������������������������������������������������������������������159 Table of ConTenTs
vii 5�5 Chronos in Action�����������������������������������������������������������������������������������159 5�6 Summary �����������������������������������������������������������������������������������������������167 5�7 Reference ����������������������������������������������������������������������������������������������167 Chapter 6: TimeGPT: The First Foundation Model for Time Series ����169 6 Introduction ����������������������������������������������������������������������������������������������������169 6�1 Technical Overview of TimeGPT �������������������������������������������������������������171 6�2 TimeGPT in Action ����������������������������������������������������������������������������������173 6�3 Summary �����������������������������������������������������������������������������������������������182 6�4 References ��������������������������������������������������������������������������������������������182 Chapter 7: MOIRAI: A Time Series LLM for Universal Forecasting ����183 7 Introduction ����������������������������������������������������������������������������������������������������183 7�1 Challenges with Building a Universal Forecasting Model ����������������������184 7�2 Technical Overview of MOIRAI ���������������������������������������������������������������186 7�3 MOIRAI in Action ������������������������������������������������������������������������������������188 7�4 Summary �����������������������������������������������������������������������������������������������194 7�5 Reference ����������������������������������������������������������������������������������������������194 Chapter 8: TimesFM: Time Series Forecasting Using Decoder-Only Foundation Model�������������������������������������������������������195 8 Introduction ����������������������������������������������������������������������������������������������������195 8�1 Technical Overview of TimesFM ������������������������������������������������������������196 8�2 TimesFM in Action ���������������������������������������������������������������������������������199 8�3 Summary �����������������������������������������������������������������������������������������������209 8�4 Conclusion ���������������������������������������������������������������������������������������������209 8�5 Reference ����������������������������������������������������������������������������������������������210 Index �������������������������������������������������������������������������������������������������211 Table of ConTenTs
ix Banglore Vijay Kumar Vishwas is a seasoned Principal Data Scientist and AI researcher with over 11 years of experience in the IT industry. He is currently based in San Diego, California. Vishwas holds a Master of Technology in Software Engineering from Birla Institute of Technology and Science, Pilani, India. He specializes in developing innovative solutions for large enterprises, with expertise in machine learning, deep learning, time series forecasting, natural language processing, reinforcement learning, generative AI, and AI agents. He is the author of Hands-on Time Series Analysis with Python published by Apress. He is the inventor of a patented method that utilizes AI to minimize emissions from gas turbines. Sri Ram Macharla is a consultant and architect in the areas of AI and ML with over 19 years of experience in IT. He holds an MTech from BITS Pilani and has experience working with clients in domains such as finance, retail, life sciences, defense, and manufacturing. Additionally, he has worked as a mentor, corporate trainer, and guest faculty teaching AI and ML. He has papers published and works as a reviewer with leading journals and publishers. He is passionate about mathematical modeling and applying AI for social good. He is currently affiliated with Involgixs Inc. About the Authors
xi Sai Chiligireddy is an Engineering Manager at Amazon with a decade of experience in software engineering, specializing in generative AI, cloud, and distributed systems. Beyond his professional role, Sai is passionate about mentorship. He actively supports new engineering managers, senior engineers, and university students, mentoring them on career development and technical expertise. About the Technical Reviewer
xiii Acknowledgments This book would not have existed without the tenacious support of my incredible family. To my parents, Vijay Kumar and Rathnamma, whose love and guidance have been my guiding light. Thank you for your endless belief in me. Your sacrifices and constant support have paved the way for success in my life. To my wife, Janani, my rock and my biggest cheerleader, thank you for your unwavering love, constant encouragement, and indomitable support throughout this challenging journey. Thank you for your patience and understanding. To my brother, Shreyas, thank you for our unbreakable bond and the unflinching support that has always been there for me. And finally, to my son, Hiyan, the most amazing little human I know, may you always chase your dreams with boundless enthusiasm and perhaps one day write your own book. —Vishwas I would like to thank my spouse, Meena, and son, Sudhish, for taking up my responsibilities around the house while I was busy working on the book. Writing a book of this sort is impossible without the motivation and support of friends and well wishers. Thank you Dr. Damahe, Raju Gandhi, Aaron Maxwell, and Ganesh Samarthyam; your articles and responses to my mails were motivating. To my former colleagues – Dr. Anji Pasala, Sridhar Murthy, G. Madhu, S. Karthikeyan, and Hari Sharma – for the opportunities, support, and guidance. To my friends – Focus group, Appalachari group, Sudhir Sriramoju, Irfan Chavda, Jaime, N. Uday, Naveed, Mallik Katta, Anuj Mohan, Naga Kishore, S. Koley, Chaitu Tanuku, Madhu Kanala, and Balu Nayak – always appreciate and thank you for the
xiv support. My sister and brother-in-law, whom I can always fall back on, thank you. Sharad Chilukuri, Director at Involgixs, for encouraging and supporting this initiative. My former and current supervisors – Gladson, Sandhya, Muthu, Odie, Martin, Tim M., Chandan, Ren, Manoj, Saurabh K., K.S.N. Murthy garu, and others – for providing me the opportunity to work on high-impact projects and for the guidance. To the organizations that provided me the opportunity to work on corporate training assignments – thank you for the trust in me. Thank you Dr. Sudhakar, Dr. V. Uday, and Dr. A.V. Ramana for always being around for any technical discussion. Dr. Nicoleta Serban, thank you for the amazing course on time series analysis. It helped in laying a strong foundation. Lastly, I would like to thank my coauthor Vishwas for the numerous arguments and discussions to ensure we revise the content and do our best. —Sriram We would like to express our appreciation to Sudhish Macharla, Praveen Nandan K, and Siva Pichappan for their contributions in proofreading the early draft and testing the code. We express our heartfelt gratitude to T. Sowmya for her invaluable assistance in answering all our questions throughout the development process. We would also like to thank Celestin John for his guidance in refining and approving the proposal. Finally, we extend our appreciation to all the reviewers and the entire production team at Apress for their contributions. —Vishwas and Sriram aCknowledgmenTs
xv Introduction “Guru Brahma, Guru Vishnu, Guru Devo Maheshwara, Guru Sakshat Parabrahma, Tasmai Shri Gurave Namah” – a disciple expressing gratitude and reverence toward their guru (teacher). Grateful to my gurus who guided and supported me in the form of teachers and friends. A couple of years back while working on a project related to time series, we wanted to explore newer techniques in forecasting to improve precision. The advent of GenAI provides us with an opportunity to explore LLM-based models for forecasting. However, there was not enough material to help the team come up to speed. The research papers were difficult to understand for the team who came from diverse levels of mathematical backgrounds, so we had to go through a steep learning curve. We were looking for a resource that would equip us with the theoretical understanding of the models and practical implementation with python sample code. We could not find any, so that gave birth to the idea of writing this book. We present this book that is catered to the needs of working professionals to come up to speed. Those who wish to dive deeper may want to read the reference papers after reading this book. This book is primarily targeted toward intermediate to advanced time series forecasting modelers. So if you are a beginner, we suggest you to pick up a beginner-friendly book like Hands-on Time Series Analysis with Python by Vishwas and Ashish before reading this book. Researchers are suggested to read the provided references after going through this book.
xvi The book starts with a motivation to learn time series forecasting. Chapter 1 introduces different time series techniques, generative AI, large language models, evolution, and milestones to date. Chapters 2 and 3 discuss neural networks and transformer theory and implementation. You can use these chapters to refresh your knowledge and learn to implement them by leveraging modern tools. Chapters 4–8 cover topics related to foundation models for time series forecasting. Each chapter discusses a new foundation model. We begin by understanding the technical overview, relevant concepts, and implementation using Python code and libraries. Techniques that help to understand forecasting by repurposing and reusing foundation models meant for NLP are explained. All chapters (except Chapter 1) discuss how to implement the models with a dataset and full code with explanation. Where possible and applicable, we try to implement the models for both univariate and multivariate scenarios. InTroduCTIon
1© Banglore Vijay Kumar Vishwas and Sri Ram Macharla 2025 B. V. Vishwas and Sri Ram Macharla, Time Series Forecasting Using Generative AI, https://doi.org/10.1007/979-8-8688-1276-7_1 CHAPTER 1 Time Series Meets Generative AI Chapter Goal: Introduction to time series, evolution of artificial intelligence, and a gentle introduction to generative AI and large language models. What Sparked Interest in Time Series? There is a lot of buzz in the IT industry about NLP, computer vision, generative AI, transformers, and AI agents. However, a specific use case encountered while working on a consulting project for a manufacturing client, which was solved using time series techniques, captured interest in time series. For over two decades, a team relied on a legacy approach using moving averages to forecast product demand for the next year. This system, however, often resulted in inaccurate forecasts, leading to significant waste due to under- or overestimation and instances where orders couldn't meet actual demand. A more sophisticated approach was implemented using simple ARIMA (Autoregressive Integrated Moving Average) models to address this issue. This upgrade significantly reduced waste and, to our knowledge, has eliminated instances of underestimation since its implementation. While
2 this project was less complex than other initiatives using computer vision and NLP, the time series solution delivered immediate cost savings and empowered the team to make informed decisions on time. This success also garnered significant recognition from senior management. Introduction to Time Series Analysis Time series analysis is a statistical and advanced mathematical technique for analyzing time-dependent data. It is used in various fields such as finance, economics, healthcare, environmental monitoring, marketing and sales, energy and utilities, manufacturing, telecommunications, engineering, and many more to identify patterns within data over time. The goal of time series analysis is to identify the underlying patterns, trends, and seasonality in the data and use this information for making informed predictions about future values. Let’s put this in context through some real-world examples. Example 1: Predict inventory for supply chain optimization. Example 2: Predictive or preventive maintenance is a proactive way to maintain equipment health, machinery, or other assets in optimal condition to prevent breakdown. Example 3: Forecast pandemic spread. Example 4: Identify patterns for the bullwhip effect and cart loading (refer to the “Summary” section). Chapter 1 time SerieS meetS Generative ai
3 1.1 Characteristics of Time Series Data a) Time dependence: Data points are ordered in time and have a natural temporal sequence, which means that prior observations frequently influence the value of each observation. b) Autocorrelation: Statistical measure that describes the relationship between an observation in time series and its own past values. c) Stationarity: Statistical properties of time series do not change over time. d) Nonstationarity: Statistical properties, like mean and variance, change over time, indicating that values at time point (t) can be influenced by preceding values at times like t − 1 or t − 2. e) Seasonality: Recurrent fluctuations at fixed intervals (e.g., daily, monthly, yearly), influenced by factors like time of year, month, or day which are predictable and repetitious. Examples are retail sales increasing during popular holidays. f ) Trends: Long-term movement in the data indicates direction and movement over time. Examples are rising global temperatures and housing prices post pandemic. g) Cyclic patterns: Recurrent phenomena without fixed periods, attributed to complex circumstances that are unpredictable and challenging to identify. Examples are forest growth and fire cycles. Chapter 1 time SerieS meetS Generative ai
4 h) Irregularity or noise (irregular component): Random variations without a recurring pattern, attributed to unforeseen events or anomalies. Examples are rapid stock market fluctuations before and after a political event. i) Frequency: Data is sampled at regular time intervals (e.g., hourly, daily, monthly). j) Duration: Length of time between observations. 1.2 Time Series Forecasting Methods Various techniques and algorithms are available to perform time series forecasting based on the data characteristics learned in the above section. They can be “broadly” classified into two categories – univariate and multivariate. 1.2.1 Univariate Univariate time series analysis focuses on the study of a single time series to understand its underlying patterns and make forecasts. Let’s understand some popular techniques: a) Moving Average (MA): The Moving Average model computes the average of a fixed number of previous observations to predict future values. b) Autoregressive (AR): Autoregressive models are a class of models that describe a linear relationship between an observation at a particular time and a certain number of lagged observations (i.e., past values) of the same series. Chapter 1 time SerieS meetS Generative ai
5 c) Autoregressive Moving Average (ARMA): This model is a combination of AR (Autoregressive) and MA (Moving Average), and this combination is done to improve the approximation. d) Autoregressive Integrated Moving Average (ARIMA): This model is a combination of three models – AR (Autoregressive), MA (Moving Average), and Integrated (the number of times differencing is done to make data stationary). e) Seasonal Autoregressive Integrated Moving Average (SARIMA): SARIMA is an extension of ARIMA that can handle seasonal effects present in the data. f ) Exponential Smoothing: Exponential smoothing methods forecast future values by weighting past observations exponentially. g) SES: Suitable for data without trend or seasonality. h) Holt’s Linear Trend Model: Extends SES to capture linear trends. i) Holt-Winters Seasonal Model: Extends Holt’s model to capture seasonality. j) Fourier Analysis: Fourier Analysis decomposes a time series into sinusoidal components. It is useful for identifying cyclical patterns. k) Kalman Filter: The Kalman filter is an algorithm that uses a series of measurements over time, containing statistical noise and other inaccuracies, to estimate unknown variables. Chapter 1 time SerieS meetS Generative ai
6 l) Hidden Markov Models: Models time series data as sequences of hidden states with observable outcomes, useful for sequential data with unknown state transitions. 1.2.2 Multivariate Multivariate time series analysis extends the techniques used in univariate time series to multiple interrelated time series. Exogenous variables which are external factors affecting the target variable are included to make models robust. Examples are sales of the book impacted by exogenous variables such as target audience, reviews, and current topics in trend. a) Seasonal Autoregressive Integrated Moving Average with Exogenous Regressors (SARIMAX): SARIMAX is an extension of ARIMA which can handle seasonal effects and also include external influencing factors into the model. b) Vector Autoregression (VAR): VAR models generalize the univariate autoregressive model to capture the linear interdependencies among multiple time series. c) Vector Autoregressive Moving Average (VARMA): VARMA models extend VAR models by including moving average terms. d) Vector Autoregression Moving Average with Exogenous Regressors (VARMAX): This model is an extended version of VAR and VARMA models by incorporating exogenous variables. Chapter 1 time SerieS meetS Generative ai
7 e) Vector Error Correction Model (VECM): VECM is used for nonstationary time series that are cointegrated. It extends the VAR model to include error correction terms, capturing long-term equilibrium relationships. f ) Generalized Autoregressive Conditional Heteroskedasticity Models (GARCH): GARCH models are designed to capture the changing variances over time, especially useful for modeling financial time series data which often exhibit volatility clustering which are periods of oscillation followed by a period of relative calm. g) Convolutional Neural Networks (CNNs): CNNs can be adapted to capture spatial dependencies in multivariate time series by treating time series data as images or sequences. h) Recurrent Neural Network (RNN), Gated Recurrent Unit (GRU), Long Short-Term Memory (LSTM): A type of neural network that is well suited for sequence prediction problems. These neural networks can capture long-term dependencies in multivariate time series. i) Transformers: Originally developed for natural language processing, transformers can be adapted for multivariate time series by capturing relationships between different variables and leveraging attention mechanisms. Chapter 1 time SerieS meetS Generative ai