A predictive distribution assigns probabilities to possible future values conditional on observed input data. In forecasting, sampled future paths preserve uncertainty rather than returning only one estimate. section 4.2.2
Lag-Llama generates an output distribution by sampling future time steps. Increasing the sample count generally produces a more precise distribution, while the context length controls the historical input window. section 4.2.2
Weekly sales forecast
A zero-shot Lag-Llama workflow loads Walmart weekly sales, formats stores as series, predicts eight weeks on a CPU, and summarizes samples with medians and 95% prediction intervals. section 4.2.2
Listing 4.7 Function to format the output as a DataFrame
import numpy as np
def get_median_and_ci(data,
start_date,
horizon,
freq,
id,
confidence=0.95):
n_samples, n_timesteps = data.shape
medians = np.median(data, axis=0) #1
lower_percentile = (1 - confidence) / 2 * 100 #2
upper_percentile = (1 + confidence) / 2 * 100
lower_bounds =
➥np.percentile(data, lower_percentile,
➥ axis=0) #3
upper_bounds = np.percentile(data, upper_percentile, axis=0)
pred_dates = pd.date_range(start=start_date, periods=horizon,
➥freq=freq) #4
formatted_dates = pred_dates.strftime('%m-%d-%Y').tolist()
df = pd.DataFrame({
'Date': formatted_dates,
'Store': id,
'Lag-Llama': medians,
f'Lag-Llama-lo-{int(confidence*100)}': lower_bounds,
f'Lag-Llama-hi-{int(confidence*100)}': upper_bounds
})
return df
Inspect the implementation that computes medians and percentile bounds from forecast samples, then formats dates and interval columns. section 4.2.2

