Time-Anchor ModernBERT 32M实战教程:用Python预测东京气温的64小时变化

📅 2026/8/7 19:35:34
Time-Anchor ModernBERT 32M实战教程:用Python预测东京气温的64小时变化
Time-Anchor ModernBERT 32M实战教程用Python预测东京气温的64小时变化【免费下载链接】time-anchor-modernbert-32m项目地址: https://ai.gitcode.com/hf_mirrors/K-Iwa/time-anchor-modernbert-32mTime-Anchor ModernBERT 32M是一款基于32M参数ModernBERT骨干构建的紧凑型时间序列模型总参数达33.4M包含时间序列输入/输出头。通过一次调用该模型可返回概率预测、变量/时间影响和锚定预测三大核心结果为东京气温等时间序列数据预测提供强大支持。快速安装Time-Anchor ModernBERT 32M要开始使用Time-Anchor ModernBERT 32M进行东京气温预测首先需要安装相关依赖包。在命令行中执行以下简单命令即可完成安装pip install time-anchorpredict_time_anchor函数支持接受Hugging Face Hub模型ID或本地 checkpoint 目录方便用户灵活使用模型。获取东京气温数据进行气温预测前需要获取东京的历史气象数据。可以通过Open-Meteo的API获取指定时间段的每小时气温数据代码如下import pandas as pd url ( https://archive-api.open-meteo.com/v1/archive ?latitude35.69longitude139.69start_date2024-10-01end_date2024-12-31 hourlytemperature_2m,relative_humidity_2m,surface_pressure,wind_speed_10mformatcsv ) weather pd.read_csv(url, skiprows3) temperature weather.iloc[:, 1].astype(float32)实现东京气温64小时预测使用Time-Anchor ModernBERT 32M模型对东京气温进行64小时预测非常简单只需调用predict_time_anchor函数并传入相应参数from time_anchor import predict_time_anchor result predict_time_anchor( K-Iwa/time-anchor-modernbert-32m, target_contexttemperature[:1440], prediction_length64, quantile_levels(0.1, 0.5, 0.9), ) print(pd.DataFrame(result.forecast_rows))该模型在东京每小时气温64小时预测任务中表现出色中位数MAE为0.57°C且所有实际值都在q10–q90范围内。分析气象变量影响Time-Anchor ModernBERT 32M还能分析不同气象变量在不同时间步对气温预测的影响帮助用户深入了解气温变化的驱动因素result predict_time_anchor( K-Iwa/time-anchor-modernbert-32m, target_contexttemperature[:168], explanatory_contexts[weather.iloc[:168, i].astype(float32) for i in (2, 3, 4)], gaf{enabled: True, topk_time_steps: 0}, ) print(pd.DataFrame(result.variable_impact_rows))通过分析可知对于每小时的时间索引所有变量的影响总和为1便于直观比较各变量的重要性。使用锚定预测提高精度如果已知未来某些时间点的气温值可以使用锚定预测功能来提高整体预测精度。例如在相关案例中固定六个已知月份的数据可将中位数预测MAE从46减少到10千名乘客此处以航空乘客数据为例说明锚定预测效果。以下是锚定预测的代码示例result predict_time_anchor( K-Iwa/time-anchor-modernbert-32m, target_contextpassengers[:-24], # 此处passengers为相关时间序列数据实际使用时替换为气温数据 prediction_length24, anchor{ mode: observed, positions: [4, 8, 12, 16, 20, 24], values: [396, 559, 405, 461, 606, 432], # 实际使用时替换为已知的气温值 }, ) print(pd.DataFrame(result.forecast_rows))positions参数为基于1的预测范围步长锚定预测仅使用目标历史数据当传入explanatory_contexts时需禁用锚定。模型详细参数Time-Anchor ModernBERT 32M模型的主要参数如下骨干网络ModernBERT编码器10层隐藏层3846个头部参数总量33.4M其中ModernBERT骨干31.9M名称中的“32M”时间序列头1.5Mfloat32safetensors最大上下文长度3,463步预测范围64步训练分位数0.1 – 0.9九个级别归因方法Generalized Attention Flow (GAF) via barrier-method max-flow锚定模式observed,auto,forward,inverted,sparse,hierarchical,hybrid通过CLI进行预测除了使用Python代码还可以通过命令行界面CLI进行预测time-anchor-infer --checkpoint K-Iwa/time-anchor-modernbert-32m \ --input data.csv --target-column Target \ --exogenous-columns Feature1,Feature2,Feature3该命令会生成output/forecast.csv、output/variable_impact.csv和output/result.json文件。添加--no-impact可仅进行预测或使用--anchor-mode observed --anchor-positions 12,24 --anchor-values 0.2,0.4进行锚定预测。要使用该模型可通过以下命令克隆仓库git clone https://gitcode.com/hf_mirrors/K-Iwa/time-anchor-modernbert-32mTime-Anchor ModernBERT 32M为时间序列预测提供了强大且易用的工具无论是新手还是普通用户都能快速上手并应用于东京气温等实际场景的预测任务中。【免费下载链接】time-anchor-modernbert-32m项目地址: https://ai.gitcode.com/hf_mirrors/K-Iwa/time-anchor-modernbert-32m创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考