Learning Library

← Back to Library

Lag-Llama Forecast for Plant Survival

Key Points

  • The author bought an orange mum plant and needs to forecast freezing temperatures in New York to know when to bring it indoors.
  • They use the open‑source Lag‑Llama foundation model, accessed via a GitHub repo and Hugging Face checkpoint, run in an IBM watsonx.ai Studio notebook (or any compatible environment).
  • After loading hourly temperature data for October‑November, they clean missing values by interpolation and observe a clear cooling trend.
  • Unlike traditional ARIMA models that require training on the specific series, Lag‑Llama can perform zero‑shot forecasting by leveraging its transformer architecture trained on large‑scale time‑series data and lag features.
  • The forecasting setup specifies an 8‑hour prediction horizon (overnight lows) and a one‑week context window to capture lagged correlations before generating the temperature forecasts.

Full Transcript

# Lag-Llama Forecast for Plant Survival **Source:** [https://www.youtube.com/watch?v=MOOPuizuf6o](https://www.youtube.com/watch?v=MOOPuizuf6o) **Duration:** 00:06:37 ## Summary - The author bought an orange mum plant and needs to forecast freezing temperatures in New York to know when to bring it indoors. - They use the open‑source Lag‑Llama foundation model, accessed via a GitHub repo and Hugging Face checkpoint, run in an IBM watsonx.ai Studio notebook (or any compatible environment). - After loading hourly temperature data for October‑November, they clean missing values by interpolation and observe a clear cooling trend. - Unlike traditional ARIMA models that require training on the specific series, Lag‑Llama can perform zero‑shot forecasting by leveraging its transformer architecture trained on large‑scale time‑series data and lag features. - The forecasting setup specifies an 8‑hour prediction horizon (overnight lows) and a one‑week context window to capture lagged correlations before generating the temperature forecasts. ## Sections - [00:00:00](https://www.youtube.com/watch?v=MOOPuizuf6o&t=0s) **Forecasting NYC Night Temps for Plant Care** - The speaker outlines using the open‑source Lag‑Llama model in a watsonx.ai notebook to predict hourly low temperatures in New York, helping decide when to bring an orange mum plant indoors before freezing. - [00:03:06](https://www.youtube.com/watch?v=MOOPuizuf6o&t=186s) **Building and Evaluating Lag‑Llama Forecasts** - The speaker explains how to construct a Lag‑Llama forecaster with a lag estimator and predictor, generate November frost forecasts using GluonTS, assess accuracy via MAPE, and visualize the forecasts with 50% and 90% prediction intervals. - [00:06:18](https://www.youtube.com/watch?v=MOOPuizuf6o&t=378s) **Foundation Models Boost Time‑Series Forecasting** - The speaker highlights recent results with a new outdoor plant that illustrate the promising potential of foundation models for time‑series forecasting, an emerging application beyond their usual generative AI and LLM uses. ## Full Transcript
0:00This fall, I bought a new plant. 0:02It's an orange mum, and it  looks great outside my house. 0:06But the weather is already  getting colder in New York. 0:08And if the temperature goes below  freezing, my new plant will die. 0:12I gather data on hourly temperatures in  New York over the past several weeks. 0:17Using this time series data. 0:19I'm going to use the Lag-Llama model  an Open Source Foundation model, 0:24to predict the overnight low temperature and 0:26help me decide when I need to bring  the plant indoors to keep it alive. 0:31First, we'll clone the open source GitHub repo. 0:34I'm using a notebook with an IBM  watsonx.ai studio for this project, 0:39but you can use any environment to run this model. 0:44Next we'll install the Pre-trained model weights  from the hugging face repo where they're stored. 0:50We use the hugging basically to download  the trained Lag-Llama checkpoint. 0:57Now we have to wait for a pre-trained model  that we can use in our zero shot forecasting. 1:05We need to import libraries  to work with Lag-Llama. 1:08For this project, we'll use GleonTS,  an open source PyTorch Base library 1:13for working with time series  data and forecasting models. 1:18Next, we need to load the  data set for our tutorial. 1:21You can find this dataset in the  repo along with the notebook. 1:25This time series data contains hourly temperatures  in New York for the month of October and November. 1:31The data was gathered from ACS Web services. 1:35I'm loading data from within my project  in watsonx.ai Studio, but this will differ 1:41depending on what environment you're using  and where you are storing the data file. 1:46The data has some missing readings. 1:48We'll fill them in by  interpolating between values. 1:51So there's no missing values in the time series. 1:55Here's what the data looks like. 1:56We can see the trend of colder  weather throughout the fall. 2:00Now we're ready to make predictions in traditional  time series forecasting with a model like ARIMA. 2:06We'd have to first train  the model on this data set. 2:09Lag-Llama works differently as a foundation model. 2:13It can create a forecast without pre training, 2:15the same way that an LLM can output text  without being pre trained on a task. 2:21This works because Lag-Llama is trained  on large scale time series data sets, 2:26like how LLMs are trained on  a massive corpus of text data. 2:31The Lag-Llama model uses a transformer 2:33architecture based on the  Llama model architecture. 2:37The model makes use of lag features or  previous readings from the time series, 2:42like traditional forecasting models such as ARIMA. 2:46We need to specify some  configuration settings for our model. 2:50The prediction length is how many time  steps each prediction should contain. 2:55We'll predict the overnight  temperatures, so eight hours out. 2:59The context length sets the number  of time points looking back into 3:02the past that the model should  look for lagged correlations. 3:06We'll look back one week when  making these overnight predictions. 3:12Now we'll create the forecaster. 3:14This step consists of two parts. 3:16First, we create a lag estimator which uses 3:20all the parameters copied from  the downloaded Lag-Llama model. 3:24The second step is to create  a Lag-Llama predictor using 3:27that create predictor method of the estimator. 3:31This allows us to pass a context lead sized window  of data to get the forecasts from the predictor. 3:38Now we're ready to create our forecast. 3:41We'll focus on days in late November because 3:43I know that's typically when the  first frost of the season happens. 3:47We'll use the make evaluation predictions 3:50method from the GluonTS evaluation  library to generate our forecasts. 3:55Now that we've generated our forecasts, we'll  evaluate them against the ground truth data. 4:01We'll use an evaluator object also  from the GluonTS evaluation library 4:06will generate several metrics that we can use  to evaluate the accuracy of our forecasts. 4:11But we'll focus on mean absolute  percentage error or MAPE. 4:19Once we have the evaluations for each  prediction, we can graph each prediction. 4:26Our chart shows each of  our six zero shot forecasts 4:29shown in green and the actual time series data, 4:33the blue Line. 4:35For each forecast, we can see the  mean forecast as the green line. 4:40The boundaries of the 50% prediction interval in 4:43dark green and the boundaries of the 90%  prediction interval in lighter green. 4:49These prediction intervals show us how certain  our model is about the forecast at each step. 4:54This is an advantage of a probabilistic model. 4:57It will show us how certain it  is at each step in the forecast. 5:02So what does this mean for my new plan? 5:05To be cautious? 5:06I think any time the 50% prediction interval  indicates a frost, I'll take the plant inside. 5:12By this measure, the Lag-Llama model performs  pretty well at predicting an overnight forecast. 5:18For example, in this first chart for  November 24th, the model predicts 5:24within the 50% prediction interval that the  overnight temperature will go below freezing. 5:30And it does. 5:31We can see that the blue line tracks  fairly closely to the green predicted line. 5:37This is also reflected in our low  MAPE for this day's predictions. 5:43For the date of November 28th. 5:46We see a less accurate forecast  from the model on this day. 5:50The overnight temperature drops  to the coldest yet this season. 5:54For this prediction, we see  the actual temperature ends 5:57up within the 90% prediction interval, but  mostly misses the 50% prediction interval. 6:04But following my guideline to  take the plant inside any time 6:08the 50% prediction interval goes below freezing, 6:12I would have saved my plant on this day, so  it's not bad performance overall from the model. 6:18Based on the results with my new outdoor plant. 6:21We can see that foundation models hold  promise for time series forecasting. 6:26While we've seen a lot of applications  for the use of generative AI 6:29and foundation models for LLMs, 6:32applying these approaches to time series  forecasting is still a developing field.