什么是时间序列预测?(What is Time Series Forecasting?)
你有没有想过,为什么妈妈总是能提前知道天气变化,让你带上雨伞?为什么便利店在夏天会进更多的冰淇淋,而冬天却减少?又为什么老师能猜到你这次考试可能考得不太理想,需要多花点时间学习?这些看似神奇的事情,其实背后都藏着一个共同的秘密——时间序列预测(Time Series Forecasting)。
你有没有想过,为什么妈妈总是能提前知道天气变化,让你带上雨伞?为什么便利店在夏天会进更多的冰淇淋,而冬天却减少?又为什么老师能猜到你这次考试可能考得不太理想,需要多花点时间学习?这些看似神奇的事情,其实背后都藏着一个共同的秘密——时间序列预测(Time Series Forecasting)。
在我们生活的每一天,世界都在不停地变化着。温度会变高变低,股票会涨涨跌跌,你的身高会一点点长高,游戏里的金币会越来越多。这些变化不是杂乱无章的,而是有规律可循的。就像你每天早上七点起床,晚上九点睡觉一样,很多事情都会按照一定的时间顺序发生,并且呈现出某种可以预测的模式。
Have you ever wondered why your mom always knows when the weather is about to change, so she reminds you to bring an umbrella? Or why the convenience store stocks more ice cream in summer but less in winter? And why your teacher can guess that you might not do well on this test and need to spend more time studying? These seemingly magical things actually hide a common secret — Time Series Forecasting.
In our daily lives, the world is constantly changing. Temperatures rise and fall, stocks go up and down, your height gradually increases, and the coins in your game keep accumulating. These changes are not random but follow certain patterns. Just like you wake up at seven in the morning and go to bed at nine at night, many things happen in a certain time sequence and show predictable patterns.
1.1 什么是时间序列数据?(What is Time Series Data?)
要理解时间序列预测,我们首先需要了解什么是时间序列数据(Time Series Data)。简单来说,时间序列数据就是按照时间顺序排列的一串数字或记录。每一笔数据都对应着一个特定的时间点,就像你日记本里的每一页都记录着某一天发生的事情一样。
To understand time series forecasting, we first need to understand what Time Series Data is. Simply put, time series data is a sequence of numbers or records arranged in chronological order. Each piece of data corresponds to a specific point in time, just like every page in your diary records what happened on a particular day.
让我们来看几个具体的例子:
你的身高记录(Your Height Records)
想象一下,你的妈妈每个月都会在墙上记录你的身高。一月份你长到了120厘米,二月份长到了120.5厘米,三月份是121厘米,四月份是121.5厘米,五月份是122厘米……把这些数字按照时间顺序排列起来,就形成了一条身高时间序列(Height Time Series)。
Imagine your mom records your height on the wall every month. In January you were 120 cm tall, in February you grew to 120.5 cm, in March it was 121 cm, in April 121.5 cm, and in May 122 cm... Arranging these numbers in chronological order forms a Height Time Series.
如果我们在纸上画出来,横轴代表时间(月份),纵轴代表身高(厘米),我们就会看到一条缓缓上升的曲线。这条曲线告诉我们:你正在长大!而且,根据这条曲线的趋势,我们甚至可以猜到你明年这个时候大概会有多高。这就是时间序列预测的一个最简单的应用!
If we draw this on paper, with the horizontal axis representing time (months) and the vertical axis representing height (centimeters), we would see a gently rising curve. This curve tells us that you are growing up! And based on the trend of this curve, we can even guess how tall you might be next year. This is one of the simplest applications of time series forecasting!
每天的温度变化(Daily Temperature Changes)
再比如,每天早上、中午和晚上,你都会看到天气预报员报道当天的温度。这些温度数据按时间顺序排列起来,也是一条时间序列。如果我们把这些数据画在图上,就会发现:在一天之内,温度通常是早上较低、中午最高、傍晚又开始下降的规律。
Another example: every morning, noon, and evening, you see the weather forecaster report the day's temperature. These temperature readings arranged in chronological order also form a time series. If we plot these data on a graph, we discover: within a single day, temperature typically follows a pattern — lowest in the morning, highest at noon, and dropping again in the evening.
更重要的是,如果我们收集了一整年的温度数据,就会发现更神奇的规律:夏天温度高,冬天温度低。一年四季,周而复始,年复一年,都是如此。这种在一个更长的时间周期内重复出现的规律,科学家们称之为季节性模式(Seasonal Pattern)。
More importantly, if we collect a full year of temperature data, we discover an even more amazing pattern: high temperatures in summer, low temperatures in winter. The four seasons repeat themselves, year after year. This kind of pattern that repeats over a longer time cycle is called Seasonal Pattern by scientists.
冰淇淋的销量曲线(Ice Cream Sales Curve)
夏天到了,小明发现街角的冰淇淋店总是排着长长的队。到了冬天,同一家店的生意却冷清许多。这是为什么呢?
Summer arrives, and Xiao Ming notices that the ice cream shop on the corner always has a long line. But in winter, the same shop's business becomes quite cold. Why is this?
其实,冰淇淋的销量也是一个典型的时间序列数据。如果我们把过去一年每个月的冰淇淋销量画成图表,就会看到一个明显的季节性模式:夏季销量最高,冬季销量最低。这种模式每年都会重复出现。
In fact, ice cream sales are also a typical time series data. If we graph the ice cream sales for each month over the past year, we see a clear Seasonal Pattern: highest in summer, lowest in winter. This pattern repeats every year.
正是因为有了这种规律,冰淇淋店的老板就可以提前做好准备:夏天多进货、准备更大的冰柜;冬天减少进货、节约成本。这就是基于时间序列预测的商业决策(Business Decisions Based on Time Series Forecasting)!
Because of this pattern, the ice cream shop owner can prepare in advance: stock up more in summer, prepare bigger freezers; reduce inventory in winter, save on costs. This is Business Decision Based on Time Series Forecasting!
```mermaid graph LR A[时间 Time] --> B[温度 Temperature] A --> C[销量 Sales] A --> D[身高 Height] B --> E[夏天高 Summer High] B --> F[冬天低 Winter Low] C --> G[冰淇淋销量 Ice Cream Sales] D --> H[逐渐增高 Gradually Increasing] style A fill:#f9f,color:#000 style E fill:#ff9,color:#000 style F fill:#9cf,color:#000 style G fill:#ff9,color:#000 style H fill:#9f9,color:#000 ```
1.2 时间序列的三大要素(Three Key Elements of Time Series)
通过对上面例子的分析,我们可以发现,任何时间序列数据都有三个核心要素:时间点(Time Points)、数值(Values)和模式(Patterns)。这三个要素就像时间序列的DNA,决定了数据的特征和规律。
Through analyzing the examples above, we can discover that any time series data has three core elements: Time Points, Values, and Patterns. These three elements are like the DNA of time series, determining the characteristics and regularities of the data.
时间点(Time Points)
时间点是指数据记录发生的具体时刻。时间点可以是秒、分钟、小时这样的短周期,也可以是日、周、月、季度、年度这样的长周期。时间点的选择取决于我们要分析的问题本身。
Time Points refer to the specific moments when data is recorded. Time points can be short cycles like seconds, minutes, or hours, or longer cycles like days, weeks, months, quarters, or years. The choice of time points depends on the problem we are analyzing.
比如说,如果你想分析股票价格在一天内的波动情况,你就需要每分钟甚至每秒记录一次数据;但如果你想分析一个国家的GDP变化,按季度或年度记录就够了。
For example, if you want to analyze stock price fluctuations within a single day, you need to record data every minute or even every second. But if you want to analyze changes in a country's GDP, recording quarterly or annually is sufficient.
在数学和统计学中,我们通常用符号 $t$ 来表示时间点,用 $t = 1, 2, 3, \ldots, T$ 来表示一个包含 $T$ 个观测值的时间序列。比如,$y_t$ 就代表在时间点 $t$ 观察到的数值。
In mathematics and statistics, we typically use the symbol $t$ to represent time points, and $t = 1, 2, 3, \ldots, T$ to represent a time series containing $T$ observations. For instance, $y_t$ represents the value observed at time point $t$.
$$y_1, y_2, y_3, \ldots, y_T$$
这个公式描述的就是一个完整的时间序列,其中 $y_1$ 是第一个时间点的数据,$y_2$ 是第二个时间点的数据,以此类推,直到第 $T$ 个时间点的数据 $y_T$。
This formula describes a complete time series, where $y_1$ is the data at the first time point, $y_2$ is the data at the second time point, and so on, until the data $y_T$ at the $T$-th time point.
数值(Values)
数值是时间序列中最重要的部分,它记录了我们在每个时间点所关心的具体数据。数值可以是各种各样的东西:温度、销售额、人数、股票价格、考试成绩……只要是我们想要分析的数量,都可以成为时间序列中的“值”。
Values are the most important part of a time series — they record the specific data we care about at each time point. Values can be all kinds of things: temperature, sales, number of people, stock prices, test scores... Anything we want to analyze can become the "value" in a time series.
在统计学中,数值有时也被称为观测值(Observations)或响应变量(Response Variable)。我们用 $y_t$ 来表示在时间点 $t$ 的观测值,这个记号在时间序列分析中非常常用。
In statistics, values are sometimes called Observations or Response Variables. We use $y_t$ to represent the observation at time point $t$, a notation very commonly used in time series analysis.
数值有高有低、有涨有跌,但它们并不是随机出现的。科学家们发现,时间序列中的数值通常由以下几个部分组成:
Values go up and down, but they don't appear randomly. Scientists have discovered that values in time series are usually composed of several components:
1. 趋势(Trend):长期的变化方向,比如你的身高逐年增长,或者一个城市的人口逐年增加。 Trend: The long-term direction of change, such as your height increasing year by year, or a city's population steadily growing.
2. 季节性(Seasonality):在固定时间周期