How to Build a Forecasting Pipeline with TimeCopilot Using Foundation Models and Automated Anomaly Detection

How to Build a Forecasting Pipeline with TimeCopilot Using Foundation Models and Automated Anomaly Detection


import os, warnings
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
warnings.filterwarnings(“ignore”)
pd.set_option(“display.width”, 160)
pd.set_option(“display.max_columns”, 30)
print(“numpy:”, np.__version__)
import scipy; print(“scipy:”, scipy.__version__)
try:
import torch
HAS_GPU = torch.cuda.is_available()
except Exception:
HAS_GPU = False
print(f”GPU available: {HAS_GPU}”)
df = pd.read_csv(
“https://timecopilot.s3.amazonaws.com/public/data/air_passengers.csv”,
parse_dates=[“ds”],
)
df[“unique_id”] = df[“unique_id”].astype(str)
rng = np.random.default_rng(7)
dates = df[“ds”].unique(); n = len(dates)
synth = pd.DataFrame({
“unique_id”: “Synthetic”,
“ds”: dates,
“y”: (np.linspace(50, 250, n)
+ 40 * np.sin(2 * np.pi * np.arange(n) / 12)
+ rng.normal(0, 8, n)).round(2),
})
anomaly_idx = [30, 75, 120]
synth.loc[anomaly_idx, “y”] *= 2.2
panel = pd.concat([df[[“unique_id”, “ds”, “y”]], synth], ignore_index=True)
print(“\nPanel shape:”, panel.shape)
print(panel.groupby(“unique_id”)[“y”].agg([“count”, “mean”, “min”, “max”]))
H, FREQ = 12, “MS”



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest