Skip to Content
PyTorch 中的 AI 和 ML 编码
book

PyTorch 中的 AI 和 ML 编码

by Laurence Moroney
July 2025
Beginner to intermediate
444 pages
6h 20m
Chinese
O'Reilly Media, Inc.
Content preview from PyTorch 中的 AI 和 ML 编码

第 9 章. 了解序列和时间序列数据

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

时间序列无处不在。你可能在天气预报、股票价格以及摩尔定律等历史趋势中见过它们。如果你对摩尔定律不熟悉,它预测微芯片上的晶体管数量大约每两年翻一番--近 50 年来,事实证明它能准确预测未来的计算能力和成本(见图 9-1)。

Moore’s law
图 9-1. 摩尔定律
注释

图 9-1中的缺口是该时间段的缺失数据,但总体趋势仍然成立。

时间序列数据是一组随时间间隔排列的数值,通常按特定顺序排列,或表示某一事物在某一时间点的数值。在图表中绘制时间序列时,X 轴通常具有时间性。通常情况下,时间轴上会绘制多个值,如图 9-1 所示的示例中,晶体管数量是其中一个图,摩尔定律的预测值是另一个图。这就是所谓的多元时间序列。如果只有一个值--例如,随时间变化的降雨量--则称为变量时间序列。

有了摩尔定律,预测就变得简单了,因为有一个固定而简单的规则可以让我们大致预测未来--这个规则已经沿用了大约 50 年。

但是,像图 9-2 所示的时间序列呢?

图 9-2. 真实世界的时间序列

虽然这个时间序列是人为创建的(本章稍后将介绍如何创建时间序列),但它具有现实世界中复杂时间序列的所有属性,如股票图表或描述季节性降雨的图表。尽管时间序列看似随机,但它们有一些共同的属性,有助于设计可以预测它们的 ML 模型,下一节将对此进行介绍。

时间序列的共同属性

虽然时间序列看起来可能是随机和嘈杂的,但它们通常具有可预测的共同属性。在本节中,我们将探讨其中的一些。

趋势

时间序列通常会朝着一个特定的方向移动 。以摩尔定律为例,我们不难发现,随着时间的推移,Y 轴上的数值不断增加,并呈现上升趋势。图 9-2 中的时间序列也呈上升趋势。当然,情况并不总是这样:尽管有季节性变化,但有些时间序列可能随着时间的推移基本持平,而有些时间序列则可能呈下降趋势。例如,预测每个晶体管价格的摩尔定律反演就是这种情况。

季节性

许多时间序列随着时间的推移具有的重复模式,重复发生的时间间隔被称为季节。例如,天气中的温度。我们通常一年有四个季节,夏季温度最高。因此,如果你绘制几年的天气图,你会发现每四个季节都会出现峰值,这就给了我们季节性的概念。但这种现象并不局限于天气,例如图 9-3 是一个网站的流量图。

图 9-3. 网站流量

它是按周绘制的,你可以看到有规律的下降。你能猜到是什么原因吗?本例中的网站是一个为软件开发人员提供信息的网站,正如你所预料的那样,它在周末的流量较少!因此,时间序列具有五天高、两天低的季节性。数据是在几个月内绘制的,中间大致是圣诞节和新年假期,因此可以看到额外的季节性。如果我绘制的是一些年份的数据,你就会清楚地看到额外的年末跌幅。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

在企业中实施 MLOps

在企业中实施 MLOps

Yaron Haviv, Noah Gift
图解大模型 : 生成式AI 原理与实战

图解大模型 : 生成式AI 原理与实战

Jay Alammar, Maarten Grootendorst

Publisher Resources

ISBN: 9798341662599