# pip install neuralforecast   (needs PyTorch)
import pandas as pd
from neuralforecast import NeuralForecast
from neuralforecast.models import TimesNet

URL = "https://raw.githubusercontent.com/zhouhaoyi/ETDataset/main/ETT-small/ETTh1.csv"
raw = pd.read_csv(URL, parse_dates=["date"])
df = raw.rename(columns={"date": "ds", "OT": "y"}).assign(unique_id="ETTh1")[["unique_id", "ds", "y"]]
H = 96
train, test = df.iloc[:-H], df.iloc[-H:]

# top_k: how many dominant periods (found with an FFT) to fold the series by
model = TimesNet(h=H, input_size=336, top_k=3, num_kernels=6, hidden_size=64, conv_hidden_size=64,
                 scaler_type="standard", max_steps=1000, random_seed=1)
nf = NeuralForecast(models=[model], freq="h")
nf.fit(df=train)
fc = nf.predict()
print(f"TimesNet MAE over 96 hours: {abs(test['y'].values - fc['TimesNet'].values).mean():.3f}")
