End-to-End Forecasting with TimesFM 2.5: Backtesting, Covariates, Anomaly Detection, and Scalable Colab Deployment
https://www.marktechpost.com/2026/08/01/end-to-end-forecasting-with-timesfm-2-5-backtesting-covariates-anomaly-detection-and-scalable-colab-deployment/📌 【TimesFM 2.5 實作指南】從零建構端對端時間序列預測工作流
TL;DR:透過 TimesFM 2.5 實現包含回測、共變量整合與異常檢測的完整預測流程。
在處理真實世界的時間序列任務時,僅僅生成一個預測點值(Point Forecast)是遠遠不夠的。工程師需要的是能夠處理外部因素(如促銷、氣溫)、具備不確定性量化能力,且經過嚴謹回測驗證的穩健系統。
🧩 建立包含多重因素的零售模擬數據集
為了模擬真實場景,本教學展示了如何生成一個包含多個商店的零售數據集,其中融入了以下複雜變數:
- 趨勢(Trend)與季節性(Seasonality,包含週與年)
- 價格效應與促銷活動(Promotions)
- 節日影響與氣溫變化
- 隨機需求雜訊
🚀 TimesFM 2.5 的 Zero-shot 預測與不確定性量化
使用 TimesFM 2.5 模型進行 Zero-shot(零樣本)預測時,不僅能輸出預測值,還能透過機率分位數(Probabilistic Quantiles)生成扇形圖(Fan Chart),藉此視覺化預測的置信區間(Confidence Intervals),幫助評估預測的不確定性。
📊 多維度的效能評估與回測機制
為了確保模型在實務中可靠,教學中實作了多種評估指標與驗證策略:
- 評估指標:包含 MAE、RMSE、MAPE、sMAPE、MASE、Pinball Loss 以及預測區間覆蓋率(Prediction-interval coverage)。
- 滾動原點回測(Rolling-origin Backtesting):不依賴單一的測試集,而是透過多個歷史時間點的切分,觀察模型在不同預測週期下的穩定表現。
- 消融研究(Ablation Study):測試不同的上下文長度(Context-length)對預測準確度與推論時間的影響。
💡 整合外部資訊:透過 XReg 引入共變量
單純依賴歷史數據往往不足以預測未來,教學展示了如何利用 TimesFM 的 XReg 功能整合外部資訊:
- 整合對象:數值型、類別型及靜態共變量(如價格、氣溫、促銷、節日、星期、區域與商店資訊)。
- 融合模式:比較了
xreg + timesfm與timesfm + xreg兩種融合模式,以找出最適合的預測方式。
⚠️ 異常檢測與長時預測策略
除了預測未來,模型還能轉化為監控工具:
- 異常檢測:將觀測值與 TimesFM 預測的機率區間進行對比,並根據偏離程度賦予「警告(Warning)」或「嚴重(Critical)」等級。
- 長時預測策略:對比「直接預測(Direct)」與「遞迴預測(Recursive)」兩種策略在長預測區間內的準確度與誤差累積差異。
🎯 實務啟示:邁向生產級預測系統
這套工作流為工程師提供了一個結構化的基礎,可用於需求預測、營運規劃與異常監控。透過測試模型對缺失值、極短歷史紀錄及正值限制(Positive-value clipping)的魯棒性(Robustness),確保模型在實際部署時能應對各種不穩定輸入。
🔗 來源
- 標題:End-to-End Forecasting with TimesFM 2.5: Backtesting, Covariates, Anomaly Detection, and Scalable Colab Deployment
- 作者/機構:Sana Hassan @ MarkTechPost
- 連結:https://www.marktechpost.com/2026/08/01/end-to-end-forecasting-with-timesfm-2-5-backtesting-covariates-anomaly-detection-and-scalable-colab-deployment/
#TimesFM #TimeSeries #Forecasting #MachineLearning #DeepLearning #AnomalyDetection #RetailTech #ZeroShot #DataScience #Python
原始資料 MarkTechPost · 收集於 2026-08-02
摘要原文
In this tutorial, we build an advanced end-to-end time-series forecasting workflow with TimesFM 2.5 . We begin by configuring the runtime, installing the required dependencies, detecting available hardware, and generating a realistic multi-store retail dataset with trend, seasonality, pricing, promotions, holidays, temperature effects, and random variation. We then load and compile the TimesFM 2.5 model, examine its forecast configuration, and use it for zero-shot point and probabilistic forecasting. As we progress, we evaluate forecast quality with metrics such as MAE, RMSE, sMAPE, MASE, pinball loss, and prediction-interval coverage, while also testing batched inference, rolling-origin backtesting, context-length sensitivity, covariate integration through XReg, anomaly detection, long-horizon forecasting, throughput tuning, and input robustness. By working through these stages, we develop a practical understanding of how we configure, validate, benchmark, and deploy TimesFM for realistic forecasting tasks. We configure the Google Colab environment, install TimesFM and its supporting libraries, detect the available CPU or GPU, and initialize reproducible random seeds. We generate a realistic multi-store retail dataset containing trends, weekly and yearly seasonality, pricing effects, promotions, holidays, temperature variations, and random demand noise. We then load the TimesFM 2.5 model, define its baseline forecast configuration, compile it, and create a reusable function for changing model settings in later experiments. We generate our first zero-shot forecast and visualize the historical data, actual observations, median predictions, and probabilistic quantile bands in a fan chart. We inspect the structure of the point and quantile outputs, define evaluation functions for MAE, RMSE, MAPE, sMAPE, MASE, pinball loss, and prediction-interval coverage, and compare TimesFM against simple forecasting baselines. We also forecast all store series in a single batch, calculate store-level performance metrics, and plot the resulting forecasts and uncertainty intervals across the complete retail dataset. We perform rolling-origin backtesting across multiple historical cutoffs to evaluate TimesFM under several realistic forecasting periods instead of relying on one holdout window. We compare the model with a seasonal-naive baseline, summarize the average error metrics, calculate the improvement in MASE, and visualize performance across backtest folds. We then run a context-length ablation study to determine how different amounts of historical data influence forecast accuracy, interval coverage, and inference time. We incorporate numerical, categorical, and static covariates into the forecasting workflow through TimesFM’s XReg functionality. We compare the xreg + timesfm and timesfm + xreg fusion modes against a univariate forecast while using price, temperature, promotion, holiday, weekday, region, and store information. We evaluate the competing approaches, identify the best-performing covariate mode, and visualize how its predictions respond to known future promotion periods. We create an anomaly-detection workflow by comparing observed values against TimesFM’s predictive quantile intervals and assigning warning or critical severity levels to unusual observations. We inject spikes, outages, and sustained shifts into a retail series, calculate interval-based anomaly scores, and visualize the detected events alongside the expected forecasting range. We also compare direct and recursive long-horizon forecasting to examine how each strategy affects accuracy, uncertainty, and error accumulation over an extended prediction period. We benchmark forecasting throughput across different per-core batch sizes and measure how many time series we process per second. We test model robustness with leading and interior missing values, very short histories, positive-value clipping, mutable input lists, and deterministic repeated inference. We finally generate future forecasts for every store, export the results and experiment summaries to CSV and JSON files, and provide a reusable template for applying TimesFM 2.5 to our own time-series dataset. In conclusion, we completed a comprehensive TimesFM 2.5 forecasting pipeline that extends well beyond generating a basic prediction. We used probabilistic quantiles to measure uncertainty, compare the model against seasonal-naive and last-value baselines, and apply rolling-origin backtesting to obtain a more reliable view of real-world performance. We also explored how context length, batch size, exogenous covariates, compilation flags, and direct or recursive forecasting strategies influence accuracy and computational cost. Through anomaly detection and robustness tests, we examined how the model behaves with missing values, short histories, positive-value constraints, mutable inputs, and long forecast horizons. Finally, we exported forecast, backtest, ablation, and throughput results into reusable files and provided a template for applying the workflow to our own evenly spaced time-series data. We finished with a structured and production-oriented foundation for adapting TimesFM 2.5 to demand forecasting, operational planning, anomaly monitoring, and other large-scale forecasting applications. Check out the Full Codes here . Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter . Wait! are you on telegram? now you can join us on telegram as well. Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us The post End-to-End Forecasting with TimesFM 2.5: Backtesting, Covariates, Anomaly Detection, and Scalable Colab Deployment appeared first on MarkTechPost .
由 tencent/hy3:free 自動生成