- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- AI
Time Series Modeling with ARIMA
Welcome to the Time Series Modeling with ARIMA Lab! You've joined an airline's data science team, and your manager needs a forecast of passenger demand for the next two years. Forecast too low, and the airline could struggle to accommodate demand. Forecast too high, and it could allocate resources unnecessarily. Your mission is to turn historical passenger data into forecasts using ARIMA, a classical statistical approach to time series forecasting. You'll work with an Air Passengers dataset, similar to the one available on Kaggle, which contains monthly international airline passenger totals from January 1949 through December 1960. The series exhibits a clear upward trend and recurring seasonal peaks, making it a great opportunity to explore both the potential and the limitations of time series forecasting. You'll inspect and clean the data, investigate stationarity, compare ARIMA configurations, generate forecasts, and evaluate their accuracy on unseen observations. Along the way, you'll complete practical coding tasks with automated tests to validate your work. No crystal ball required. Just Python, historical data, and a forecasting challenge!
Lab Info
Table of Contents
-
Challenge
Introduction
Welcome to the Time Series Modeling with ARIMA Lab.
You have joined an airline data science team. Your manager needs a forecast of passenger demand for the next two years.
Forecast too low, and the airline may not seat every passenger. Forecast too high, and the airline may staff flights that do not fill.
Your mission is to turn historical passenger totals into a forecast with ARIMA, a classical statistical model for time series.
You work with
data/AirPassengers.csv, which holds monthly international airline passenger totals from January 1949 through December 1960, plus two planted data-quality problems. The series shows an upward trend and recurring seasonal peaks.You inspect and clean the data, investigate stationarity, compare ARIMA configurations, generate forecasts, and evaluate accuracy on unseen months. Automated checks validate each task. Estimated time: about 30 minutes.
Learning objectives
By completing this lab, you will be able to:
- Prepare and validate a chronologically indexed time series
- Visualize temporal patterns and investigate stationarity
- Fit and compare ARIMA models using AIC
- Generate forecasts for unseen observations
- Evaluate forecast accuracy using MAE and RMSE
- Analyze forecast misses and recognize the limitations of standard ARIMA on seasonal data
Before you start
- Open
src/step1_know_your_passengers.py - Run:
python3 src/step1_know_your_passengers.pyThe BEFORE block shows 146 rows, one missing passenger value, and one duplicate month. That broken file is your starting point.
How you work
- Complete the TODO functions in
src/ - Select Validate after each task
- Move to the next step file when the step is complete
If you get stuck, open the matching file in
solution/. Tests import fromsrc/, so you must complete the TODOs there to pass Validate. -
Challenge
Step 1: Get to Know Your Passengers
Before you forecast, you need a clean monthly series. The raw file in
data/AirPassengers.csvis not ready yet: it is out of order, one passenger value is missing, and one March 1952 row was planted with#Passengers999.In this step, you will load that file, remove the two bad rows, and create a chronological train/test split. A plot of the cleaned series is already provided for you.
Work in
src/step1_know_your_passengers.py. Look for the# TODOcomments under each task.Run the starter script
- Open
src/step1_know_your_passengers.py - Run:
python3 src/step1_know_your_passengers.py - Read the BEFORE block and confirm the two rows that must be removed later
Outcome
Rerun the
src/step1_know_your_passengers.pyfile to observe the outcome.When Step 1 is complete, you have:
- A cleaned series of 144 months with frequency
MS - A chronological 120 / 24 train-test split
Move to
src/step2_train_arima.py. - Open
-
Challenge
Step 2: Train Your ARIMA Model
Your cleaned series is ready. In this step, you will check stationarity, compare three ARIMA models with AIC, and forecast the 24 held-out months.
Important rule: Fit and choose the model on the training series only. The test months are for later scoring, not for model selection.
Work in
src/step2_train_arima.py. A forecast-versus-actual plot is already provided for you after the forecast runs.Run the Step 2 starter
-
Open
src/step2_train_arima.py -
Run:
python3 src/step2_train_arima.py -
Read the BEFORE block that states the train and test windows
Outcome
Rerun the
src/step2_train_arima.pyfile to observe the outcome.When Step 2 is complete, you have:
- ADF results before and after differencing
- One ARIMA model chosen by training AIC
- A 24-month forecast aligned to the test dates
Move to
src/step3_evaluate_forecast.py. -
-
Challenge
Step 3: Evaluate the Forecast
Your model has predicted the next 24 months. Now measure how close those forecasts are to reality, then analyze where a standard ARIMA model struggles with recurring seasonal peaks.
Work in
src/step3_evaluate_forecast.py. Use the held-out actual values and your existing predictions. Do not refit or tune a model on the test set.Run the Step 3 starter
-
Open
src/step3_evaluate_forecast.py -
Run:
python3 src/step3_evaluate_forecast.py -
Read the BEFORE block that describes the scoring and analysis workflow
Outcome
Rerun the
src/step3_evaluate_forecast.pyfile to observe the outcome.When Step 3 is complete, you have:
- MAE and RMSE on the 24 held-out months
- A forecast-versus-actual plot
- The largest miss, the substantial-error months, and a clear seasonal-limitation write-up
The required lab ends here.
Optional stretch challenge
If you want to go further, implement
forecast_seasonal(train, test_index).To-do:
- Fit
SARIMAXwithorder=(1, 1, 1)andseasonal_order=(1, 1, 1, 12)on the training series - Forecast the same 24 test months
- Compare seasonal RMSE with the non-seasonal ARIMA RMSE
Hint
UseSARIMAX(...).fit(disp=False), then.forecast(steps=len(test_index)), and return a Series indexed bytest_index. This stretch is optional. -
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.