专项练习不限时;提交后可以展开未通过的测试点查看输入与期望输出。草稿自动保存。
训练测试集时间穿越检查(第 53 题,10 分)
- 能力项智能训练
- 知识点训练集与测试集的维护
- 编程语言Python (3.11.2) | 判题:10 个测试点,每个 1 分
运行限制:单次运行限时 5 秒,内存上限 128MB。超时显示「运行超时」,内存超限显示「内存超限」,都不计为通过。请仅使用 Python 标准库。
一、题目描述
数字人客服的意图标签不是即时产生的:一条会话结束后,要过 delay_hours 小时才有人工标注结果可用。如果测试样本的时间早于「训练集最晚样本 + 标注延迟」,模型上线时根本拿不到它的标签,这叫时间穿越,线上指标会被高估。
请返回 [违规的测试样本下标, cutoff]:
cutoff= 训练集中最晚的时间戳 +delay_hours × 3600;- 时间戳早于
cutoff的测试样本算违规(等于cutoff不算),下标升序; - 训练集为空时返回
[[], None]。
二、输入说明
train_times、test_times:Unix 时间戳(秒)列表,顺序打乱,可能为空;各不超过 10000 条;delay_hours为非负数,最多一位小数。
三、示例
train_times = [1700000000, 1700036000, 1700100000]
test_times = [1700030000, 1700137000, 1700100100]
delay_hours = 1
返回 = [[0, 2], 1700103600]
训练集最晚是 1700100000,加 1 小时得到 cutoff = 1700103600。第 0、2 条测试样本早于它,违规;第 1 条不违规。
⌁ Python (3.11.2)
# 在这里实现 temporal_leakage;输入输出规格见左侧「题目描述」 def temporal_leakage(train_times, test_times, delay_hours): pass
train_times
[ 1700000000, 1700036000, 1700100000 ]
test_times
[ 1700030000, 1700137000, 1700100100 ]
delay_hours
1
期望输出
[
[
0,
2
],
1700103600
]