Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

RintermediateaiAI generated

Forecasting Notebook

Build a forecasting analysis in R that predicts the next months of a time series, such as monthly sales, website visits or electricity use, and honestly measures how good those predictions are. You'll clean the data (missing months, duplicates and outliers), hold back the last part of the history as a test, fit several models with the fable package (a simple baseline, exponential smoothing and ARIMA), and compare their errors on the months they never saw. The best model makes the final forecast with uncertainty ranges, and a small Shiny app lets people explore it. You'll learn tidy time series with tsibble, forecasting models, proper evaluation with a holdout period, and presenting forecasts responsibly.

Estimate
~11.5h
Steps
7
Completed by
0
Proposed by
codeseed.app

tidyverse · Shiny

Project roadmap

  1. 01

    Choose the data and define the goal

    ~1h

    Pick a monthly or weekly series with at least 4 years of history (for example a public retail sales or tourism dataset). Write README.md: what is being forecast, how far ahead (for example 12 months), and how accuracy will be judged (the error on the last 12 months, held back). Install tidyverse, tsibble, fable, feasts and shiny. Done when: README.md states the goal and the evaluation method.

  2. 02

    Clean the series

    ~2h

    Load the data and turn it into a tsibble with the right time index (yearmonth). Check for and fix duplicate periods, fill missing periods explicitly (with fill_gaps) and decide how to handle the gaps, and look for outliers. Plot the series and its seasonal pattern with feasts (gg_season and STL decomposition), and describe the trend and seasonality you see. Done when: the clean series has no gaps or duplicates, and the charts are saved.

  3. 03

    Hold back a test period

    ~1h

    Split the series: everything except the last 12 periods for training, and the last 12 for testing. Never look at the test data while choosing models. Done when: the training and test sets are created, and a chart shows where the split is.

  4. 04

    Fit and compare models

    ~2.5h

    Fit several models on the training data with fable: a seasonal naive baseline (same as last year), ETS (exponential smoothing) and ARIMA, and optionally one with a transformation. Forecast the test period and compare them with accuracy() using RMSE and MAPE. Any model worse than the naive baseline isn't useful. Done when: a table ranks the models by their error on the test period.

  5. 05

    Check and make the final forecast

    ~1.5h

    Check the chosen model's residuals with gg_tsresiduals and a Ljung-Box test (they should look like random noise). Refit it on the full history and forecast the next 12 periods with 80% and 95% prediction intervals. Plot the history with the forecast and its intervals. Done when: the forecast chart and a table of the forecast values with intervals are saved.

  6. 06

    Build a small Shiny app

    ~2h

    Create a Shiny app that shows the series and the forecast, lets the user choose the model and the forecast horizon, and shows the test period comparison table. Explain in a sentence on the page what the intervals mean. Done when: changing the model or the horizon updates the chart and table.

  7. 07

    Write it up and test

    ~1.5h

    Put the analysis in a Quarto or R Markdown report: the data, the cleaning decisions, model comparison, the final forecast and its limits. Write testthat tests for the cleaning functions (duplicates, gaps). Done when: the report renders, and the tests pass.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~11.5h · 7 steps

Tech stack

tidyverseShiny