Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sim plots] Analyze model prediction sanity, via ARIMA-style diagnostic plots of prediction residuals #1010

Open
3 tasks
trentmc opened this issue May 9, 2024 · 0 comments
Assignees
Labels
Type: Enhancement New feature or request

Comments

@trentmc
Copy link
Member

trentmc commented May 9, 2024

TODOs

  • Create a unit test for this. Analyze via unit tests on real crypto data.
  • Pre-requisite for next step: "Too many plots at once; fix via a tab on left for each group of plots" #1021
  • Put into sim_engine plotting

Background / motivation

Parent epic: #1006 "Explore SARIMAX modeling"

Once we've built a model, we analyze the distribution of its residuals = (test data predicted value - test data actual value). There are four complementary diagnostics: raw residuals, histogram, QQ, ACF (correlogram).

How: use one of:

Prototype

1010

Examples

Example 1: Sikligar thesis

Ref - py notebook

Screenshot 2024-05-09 at 11 21 13

Example 2: PSU

Ref - PSU course, lesson 03
graph_30

Example 3: plot at different autocorrelation lags

Eg at lags of 1m, 2m, ..., 5m, 10m, ...

Ref ethan rosenthal.com 3 plots above "Reversible Transformations" section

Screenshot 2024-05-09 at 11 23 10

Via this code

import statsmodels.tsa.api as smt

def plot_multi_acf(data, lags, titles, ylim=None, partial=False):
    num_plots = len(lags)
    fig, ax = plt.subplots(len(lags), 1, figsize=(10, 3 * num_plots));
    if num_plots == 1:
        ax = [ax]
    acf_func = smt.graphics.plot_pacf if partial else smt.graphics.plot_acf
    for idx, (lag, title) in enumerate(zip(lags, titles)):
        fig = acf_func(data, lags=lag, ax=ax[idx], title=title);
        if ylim is not None:
            ax[idx].set_ylim(ylim);

    fig.tight_layout();

period_minutes = 5
samples_per_hour = int(60 / period_minutes)
samples_per_day = int(24 * samples_per_hour)
samples_per_week = int(7 * samples_per_day)

lags = [3 * samples_per_hour, samples_per_day, samples_per_week]
titles= ['Autocorrelation: 3-Hour Lag',
         'Autocorrelation: 1-Day Lag',
         'Autocorrelation: 1-Week Lag']

plot_multi_acf(y, lags, titles)
@trentmc trentmc added the Type: Enhancement New feature or request label May 9, 2024
@trentmc trentmc changed the title [Component name] Benefit_yyy, via building_xxx [UX, sim] SARIMAX: 4 prediction residuals plots: raw time series, ACF, PACF, QQ May 9, 2024
@trentmc trentmc self-assigned this May 9, 2024
@trentmc trentmc changed the title [UX, sim] SARIMAX: 4 prediction residuals plots: raw time series, ACF, PACF, QQ [UX, sim] SARIMAX: Plot analytics of model prediction residuals: raw residuals, histogram, QQ, ACF (correlogram) May 9, 2024
@trentmc trentmc changed the title [UX, sim] SARIMAX: Plot analytics of model prediction residuals: raw residuals, histogram, QQ, ACF (correlogram) [UX, sim] SARIMAX: Plot diagnostics of model prediction residuals: raw residuals, histogram, QQ, ACF (correlogram) May 9, 2024
@trentmc trentmc changed the title [UX, sim] SARIMAX: Plot diagnostics of model prediction residuals: raw residuals, histogram, QQ, ACF (correlogram) [UX, sim] SARIMAX: Analyze model prediction sanity, via diagnostic plots of prediction residuals May 9, 2024
@trentmc trentmc changed the title [UX, sim] SARIMAX: Analyze model prediction sanity, via diagnostic plots of prediction residuals [Sim, Analytics] SARIMAX: Analyze model prediction sanity, via diagnostic plots of prediction residuals May 11, 2024
@trentmc trentmc changed the title [Sim, Analytics] SARIMAX: Analyze model prediction sanity, via diagnostic plots of prediction residuals [Sim plots] Analyze model prediction sanity, via diagnostic plots of prediction residuals May 11, 2024
@trentmc trentmc changed the title [Sim plots] Analyze model prediction sanity, via diagnostic plots of prediction residuals [Sim plots] Analyze model prediction sanity, via ARIMA-style diagnostic plots of prediction residuals May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant