# 时点正确性

**时点正确性**（point-in-time correctness）是机器学习训练数据构建的一种性质：每个训练样本只包含其标签被记录的那一刻已知的特征值。它通过 AS OF（时点）连接（AS OF join）实现：把每个标签行匹配到事件时间戳等于或早于该标签时间戳的最新特征值；其目的在于防止数据泄漏，即在训练中使用标签被观测时尚不可用的特征值。<sup>[1](https://docs.databricks.com/gcp/en/machine-learning/feature-store/time-series)</sup>

| 关键事实 | 细节 |
|---|---|
| 定义 | 训练数据反映每个标签观测被记录之时的特征值。<sup>[1](https://docs.databricks.com/gcp/en/machine-learning/feature-store/time-series)</sup> |
| 机制 | AS OF 连接按主键和时间戳键匹配，选择等于或早于标签时间戳的最新特征值；若不存在，则该值为空。<sup>[1](https://docs.databricks.com/gcp/en/machine-learning/feature-store/time-series)</sup> |
| 防止什么 | 数据泄漏；它难以检测，并会对模型性能产生负面影响。<sup>[1](https://docs.databricks.com/gcp/en/machine-learning/feature-store/time-series)</sup> |
| 实测影响 | 若没有它，离线 AUC 可能被抬高 5% 至 20%，而线上表现会崩塌。<sup>[2](https://www.systemoverflow.com/learn/ml-feature-stores/feature-store-architecture/point-in-time-correctness-and-time-travel)</sup> |
| 配套控制 | 时间切分，即在训练之后的时段上测试，是第二道控制；两者合在一起使离线分数与生产环境保持一致。<sup>[3](https://www.thedataengineering.com/mechanisms/specialized-processing/labs/leakage-inflates-the-score-naive-join)</sup> |
| 原生 SQL 支持 | Snowflake ASOF JOIN、Databricks as_of_join 和 DuckDB ASOF 原生提供该算子；Postgres 用 LATERAL 连接表达它。<sup>[4](https://pipecode.ai/blogs/feature-stores-feast-tecton-hopsworks-production-ml)</sup> |
| 特征存储 API | Feast get_historical_features、Tecton get_features_for_events 和 Hopsworks as_of 都实现 AS OF 语义。<sup>[5](https://docs.feast.dev/getting-started/concepts/point-in-time-joins)</sup><sup> • </sup><sup>[6](https://docs.tecton.ai/docs/beta/reading-feature-data/reading-feature-data-for-training/offline-retrieval-methods)</sup><sup> • </sup><sup>[7](https://docs.hopsworks.ai/feature-store-api/3.0/generated/api/query_api/)</sup> |

## 它解决的问题

当训练集通过把每个事件与表中最近的特征值连接来组装时，晚于该事件的数据就会被用上：该值反映的是更晚的计算结果，而不是做出预测时可得的内容。如果未来值包含关于标签的线索，模型就会把这些线索学进去：离线时分数看起来非常出色，但一旦部署就会失效，因为部署环境里只有历史值可用。<sup>[3](https://www.thedataengineering.com/mechanisms/specialized-processing/labs/leakage-inflates-the-score-naive-join)</sup>

[Databricks](https://www.edgepedia.org/zh/databricks) 的文档用房间传感器数据给出了一个具体例子。某个训练行可能显示 CO2 读数为 630，并与 8:50 记录的真实标签配对，但该 CO2 读数取自 8:52。这一行看起来有效，然而未来数据正泄漏进训练集，这会损害模型性能。<sup>[1](https://docs.databricks.com/gcp/en/machine-learning/feature-store/time-series)</sup>

这种失效模式只是更广泛的泄漏分类法中的一项。按照卡普尔（Kapoor）和纳拉亚南（Narayanan）的分类，并在泄漏文献中进一步发展：当测试集包含训练期之前的数据时，就会发生时序泄漏，这意味着模型动用了做出预测时不可用的未来信息；即使切分保持样本互不重叠，也可能落入这一错误，而修复办法是结构性的，例如基于时间的划分或分块交叉验证。<sup>[8](https://dataeval.readthedocs.io/en/latest/concepts/Leakage.html)</sup> 在推荐系统评估中，一项在四个流行数据集上对四个基线模型的研究发现，由于未遵守全局时间线而产生的泄漏，使模型推荐了在测试时点尚不可用的未来物品；并且随着训练中泄漏的未来数据量不同，模型的相对性能排序变得不可预测。<sup>[9](https://arxiv.org/abs/2010.11060)</sup>

## AS OF 连接如何工作

连接规则说起来很简单：对于时刻 T 的标签，每个特征都解析为在 T 或之前已知的最新值，且特征事件时间戳小于或等于样本时间戳。<sup>[10](https://shivamrana.me/2026/07/point-in-time-joins/)</sup><sup> • </sup><sup>[2](https://www.systemoverflow.com/learn/ml-feature-stores/feature-store-architecture/point-in-time-correctness-and-time-travel)</sup> 在时间序列特征表中，时间戳键列确保训练数据集中的每一行代表截至该行时间戳的最新已知特征值；如果到那时还没有记录任何值，则特征值为空。<sup>[1](https://docs.databricks.com/gcp/en/machine-learning/feature-store/time-series)</sup>

两道控制共同起作用：一是按值变为已知的时间进行 AS OF 连接，二是在训练之后的时段上测试的时间切分。在一个包含 200 天内 20,000 次配送、并故意泄漏一个特征的模拟实验中，朴素连接模型在离线时报告的错误低得多，而在更晚的未见时段上错误高得多；AS OF 模型的离线数字更差，却与更晚时段的表现相符。<sup>[3](https://www.thedataengineering.com/mechanisms/specialized-processing/labs/leakage-inflates-the-score-naive-join)</sup>

一个微妙之处在于值何时变为*已知*，而不只是它何时适用。Feast 默认的时点连接只约束特征的事件时间戳；某个值即使在实体 DataFrame 时间戳之后才被回填或修正，仍可能被返回给该时间戳。一个可选启用的 filter_by_created_timestamp 标志会添加 created_timestamp <= entity_timestamp 条件，于是每一行只能看到创建时间戳等于或早于自身时间戳的特征值，从而防止回填值泄漏进训练数据。<sup>[5](https://docs.feast.dev/getting-started/concepts/point-in-time-joins)</sup>

## 在哪里实现

特征存储把时点正确性作为一等原语，因为同一个特征定义必须服务两种读取：离线读取用时点连接重建特征的完整历史，以组装训练集；在线读取则为低延迟服务返回每个实体的单个最新值。<sup>[11](https://temporalbook.icsgen-ai.org/part-8-trustworthy-deployed/module-34-deployment-mlops/section-34.3.html)</sup>

**Feast** 这个开源特征存储会以时点正确的方式，把一个或多个特征视图中的特征连接到实体 DataFrame 上，重现特征在过去某一特定时点的状态。对于每一行，它从实体 DataFrame 时间戳向前回溯，最远到最大 TTL；TTL 是相对于每个实体时间戳的，而不是相对于当前查询时间。早于最早特征行的行，或落在 TTL 窗口之外的行，无法被连接。<sup>[5](https://docs.feast.dev/getting-started/concepts/point-in-time-joins)</sup>

**Tecton** 提供三种离线检索方法，包括用于时点连接的 get_features_for_events，以及 get_features_in_range；后者返回 _valid_from 和 _valid_to 列，为每个连接键定义互不重叠的有效区间。如果在某个时点查询在线存储会返回某个特征值，那么该特征值就被认为在该时点有效。<sup>[6](https://docs.tecton.ai/docs/beta/reading-feature-data/reading-feature-data-for-training/offline-retrieval-methods)</sup>

**Hopsworks** 在特征组上执行时序连接，以创建时点一致的训练数据；它使用 AS OF 左连接（AS OF LEFT JOIN），使每个标签行都在训练数据集中保留一行，特征缺失处为 NULL，以便后续插补。<sup>[12](https://www.hopsworks.ai/dictionary/feature-store)</sup> 一项关于 [Apache Spark](https://www.edgepedia.org/zh/apache-spark) 中时点连接算法的研究比较了多种实现，包括 Databricks 的 Tempo（基于并集）和 TwoSigma 的 Flint（自定义 RDD 功能），发现 Early Stop Sort-Merge（提前停止排序合并）实现在大数据负载下表现最佳，[Hopsworks](https://www.edgepedia.org/zh/hopsworks) 采用了这一实现。<sup>[13](https://www.hopsworks.ai/post/a-spark-join-operator-for-point-in-time-correct-joins)</sup>

现代 SQL 引擎已经吸收了该算子：Snowflake ASOF JOIN、Databricks as_of_join 和 DuckDB ASOF 都是原生的；一条实用规则是，没有时间谓词的训练连接并不一定泄漏数据，因为泄漏发生在训练使用了标签时点或预测时点不可用的特征值之时。<sup>[4](https://pipecode.ai/blogs/feature-stores-feast-tecton-hopsworks-production-ml)</sup><sup> • </sup><sup>[16](https://docs.databricks.com/aws/en/machine-learning/feature-store/time-series)</sup> Databricks 指出，它的时点查找功能有时被称为时间旅行，但与 [Delta Lake](https://www.edgepedia.org/zh/delta-lake) 时间旅行无关。<sup>[1](https://docs.databricks.com/gcp/en/machine-learning/feature-store/time-series)</sup>

## 相关的泄漏控制

时点连接解决特征侧的泄漏；标签侧和切分侧则需要各自的纪律。在时间序列特征工程中，变量可以分为先行特征（在预测时可得）和后续特征（不能直接作为当前时点输入，但其过去值可以馈入只使用先前观测的历史聚合流水线）。<sup>[14](https://www.mdpi.com/2673-2688/7/7/245)</sup> 一套为构建预测模型开发的分类法区分了直接结果编码、依赖执行的指标，以及来自时间上更晚构建的未来信息泄漏；这些都会产生人为抬高的准确率，并在部署时失效。<sup>[15](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0340167)</sup>

还有一种泄漏形式，任何对数据集的静态分析都看不出来：针对同一个留出集反复评估。每一次用分数来选择下一个模型，都会把一丝测试集信息传入建模过程，因此经过多轮迭代，留出集实际上被拟合了。<sup>[8](https://dataeval.readthedocs.io/en/latest/concepts/Leakage.html)</sup> 更广泛意义上的分布漂移规模由雷希特（Recht）等人测量：他们按照原始收集协议重建了 ImageNet 和 CIFAR-10 测试集，发现多种模型的准确率下降了 11 到 14 个百分点。<sup>[8](https://dataeval.readthedocs.io/en/latest/concepts/Leakage.html)</sup>

## References

1. [Point-in-time feature joins, Databricks documentation](https://docs.databricks.com/gcp/en/machine-learning/feature-store/time-series)
2. [Point in Time Correctness and Time Travel, System Overflow](https://www.systemoverflow.com/learn/ml-feature-stores/feature-store-architecture/point-in-time-correctness-and-time-travel)
3. [Leakage inflates the score (naive join versus as-of join), The Data Engineering](https://www.thedataengineering.com/mechanisms/specialized-processing/labs/leakage-inflates-the-score-naive-join)
4. [Feature Stores Compared: Feast vs Tecton vs Hopsworks for Production ML, PipeCode](https://pipecode.ai/blogs/feature-stores-feast-tecton-hopsworks-production-ml)
5. [Point-in-time joins, Feast documentation](https://docs.feast.dev/getting-started/concepts/point-in-time-joins)
6. [Offline Retrieval Methods, Tecton documentation](https://docs.tecton.ai/docs/beta/reading-feature-data/reading-feature-data-for-training/offline-retrieval-methods)
7. [Query API, Hopsworks documentation](https://docs.hopsworks.ai/feature-store-api/3.0/generated/api/query_api/)
8. [Data Leakage, DataEval documentation](https://dataeval.readthedocs.io/en/latest/concepts/Leakage.html)
9. [A Critical Study on Data Leakage in Recommender System Offline Evaluation, arXiv](https://arxiv.org/abs/2010.11060)
10. [Point-in-Time Joins, Engineers of AI](https://shivamrana.me/2026/07/point-in-time-joins/)
11. [Feature/Online Stores and Data Contracts, Building Temporal AI](https://temporalbook.icsgen-ai.org/part-8-trustworthy-deployed/module-34-deployment-mlops/section-34.3.html)
12. [Feature Store: The Definitive Guide, Hopsworks](https://www.hopsworks.ai/dictionary/feature-store)
13. [A Spark Join Operator for Point-in-Time Correct Joins, Hopsworks](https://www.hopsworks.ai/post/a-spark-join-operator-for-point-in-time-correct-joins)
14. [LLM-Guided Automated Feature Engineering for Time Series Data with Temporal Leakage Control, MDPI](https://www.mdpi.com/2673-2688/7/7/245)
15. [A taxonomy for detecting and preventing temporal data leakage in machine learning-based build prediction, PLOS One](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0340167)
16. [Point-in-time feature joins, Databricks on AWS](https://docs.databricks.com/aws/en/machine-learning/feature-store/time-series)

---
*Initially written Oct 26, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › 数据库与数据系统 › 数据挖掘、数据仓库与大数据

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/point-in-time-correctness

English original: https://www.edgepedia.org/point-in-time-correctness
