-
Hey Hello, I got the model running locally and it works very well with sample data. However when I pass in my application specific row count time series data, I get wonky unexpected results. I am trying to figure out why this is occuring. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
When I use this sample data C:\ONEAPE\iCEDQ\icedq.2\engines\forecast_engine\data\sorted_time_series_july_modified.csv However, when I use data with oscillation, it seems to work a lot better. https://drive.google.com/file/d/1lJzPCAWI03EX-12SxqgnBiOp3OOCi2n9/view?usp=sharing Here is my code for context: import numpy as np
import pandas as pd
import torch
from chronos import ChronosPipeline
import plotly.graph_objects as go
# Load the ChronosPipeline
pipeline = ChronosPipeline.from_pretrained(
"amazon/chronos-t5-large",
device_map="cuda",
torch_dtype=torch.bfloat16,
)
# Read the CSV file
csv_path3 = r"C:\ONEAPE\iCEDQ\icedq.2\engines\forecast_engine\data\Sales - Sales.csv"
df = pd.read_csv(csv_path3)
# Prepare the context and make predictions
context = torch.tensor(df["target"])
prediction_length = 50
forecast = pipeline.predict(context, prediction_length)
# Calculate forecast statistics
forecast_index = list(range(len(df), len(df) + prediction_length)) # Convert to list
low, median, high = np.quantile(forecast[0].numpy(), [0.1, 0.5, 0.9], axis=0)
# Create the Plotly figure
fig = go.Figure()
# Add historical data
fig.add_trace(go.Scatter(
x=list(df.index), # Convert to list
y=df["target"],
mode='lines',
name='Historical Data',
line=dict(color='royalblue')
))
# Add median forecast
fig.add_trace(go.Scatter(
x=forecast_index,
y=median,
mode='lines',
name='Median Forecast',
line=dict(color='tomato')
))
# Add prediction interval
fig.add_trace(go.Scatter(
x=forecast_index + forecast_index[::-1],
y=high.tolist() + low.tolist()[::-1],
fill='toself',
fillcolor='rgba(255,99,71,0.3)',
line=dict(color='rgba(255,99,71,0)'),
name='80% Prediction Interval'
))
# Update layout
fig.update_layout(
title='Time Series Forecast',
xaxis_title='Time',
yaxis_title='Value',
legend_title='Legend',
hovermode='x unified'
)
# Add gridlines
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray')
# Show the interactive plot
fig.show() |
Beta Was this translation helpful? Give feedback.
-
@nsgoneape the issue with your first series, is that its variance is rather small compared to its mean. This makes the model run into some loss of precision issues (see Sec. 5.7 in the paper, especially Fig. 16(b)). Simply shifting the series down by it's minimum value, and applying the opposite shift to the resulting forecasts, recovers the intended behaviour in this case. See my updated snippet:
Edit: expanding the answer One option to enforce monotonicity is to model the differenced series, using
This is what I get with |
Beta Was this translation helpful? Give feedback.
-
This great. The solution works with the tiny model. However, and this is interesting, it does not seems to perform as well with the large model. Here are the two results, the only difference being the model choice. As this is rowcount data, it will always increase linearly. |
Beta Was this translation helpful? Give feedback.
-
@nsgoneape one option to enforce monotonicity is to model the differenced series, using
This is what I get with |
Beta Was this translation helpful? Give feedback.
@nsgoneape the issue with your first series, is that its variance is rather small compared to its mean. This makes the model run into some loss of precision issues (see Sec. 5.7 in the paper, especially Fig. 16(b)).
Simply shifting the series down by it's minimum value, and applying the opposite shift to the resulting forecasts, recovers the intended behaviour in this case. See my updated snippet: