<jupyter_start><jupyter_text>Backtest MiscExamples of backtesting for * multiple series * multiple models<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')

from orbit.lgt import LGT
from orbit.dlt import DLT
from orbit.backtest.backtest import TimeSeriesSplitter, Backtest
from orbit.utils.metrics import mape, smape, wmape
from orbit.backtest.functions import run_multi_series_backtest<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>data_path = "../examples/data/m4_weekly.csv"
data = pd.read_csv(data_path, parse_dates=['date'])
print("Total keys: {}".format(len(data['key'].unique())))
data.head(3)<jupyter_output><empty_output><jupyter_text>Settings<jupyter_code># data settings
date_col = "date"
response_col = "value"
key_col = "key"
seasonality = 52

# backtest settings
min_train_len = 120
forecast_len = 13
incremental_len = 5
n_splits = 1
window_type = "expanding"
seed = 2019
lgt_map = LGT(
    response_col=response_col,
    date_col=date_col,
    seasonality=seasonality,
    seed=seed,
    infer_method='map',
    predict_method='map',
    is_multiplicative=True
)

dlt_map = DLT(
    response_col=response_col,
    date_col=date_col,
    seasonality=seasonality,
    seed=seed,
    infer_method='map',
    predict_method='map',
)

bt_models = {
    'LGT-MAP': lgt_map,
    'DLT-MAP': dlt_map
}<jupyter_output><empty_output><jupyter_text>Backtest Multiple Series<jupyter_code>bt_result, bt_scores = run_multi_series_backtest(
    data=data, 
    response_col=response_col, 
    key_col=key_col, 
    date_col=date_col,
    model=lgt_map,
    min_train_len=min_train_len, 
    incremental_len=incremental_len, 
    forecast_len=forecast_len, 
    predicted_col='prediction', 
    n_splits=n_splits,
    window_type = window_type
)
bt_scores.head()<jupyter_output><empty_output><jupyter_text>Backtest Multiple Models (and Multiple Series)<jupyter_code>bt_result_list = []
bt_scores_list = []
for mod_name, mod in bt_models.items():
    bt_result, bt_scores = run_multi_series_backtest(
        data=data, 
        response_col=response_col, 
        key_col=key_col, 
        date_col=date_col,
        model=lgt_map,
        min_train_len=min_train_len, 
        incremental_len=incremental_len, 
        forecast_len=forecast_len, 
        predicted_col='prediction', 
        n_splits=n_splits,
        window_type = window_type
    )
    bt_result['model'] = mod_name
    bt_scores['model'] = mod_name
    bt_result_list.append(bt_result)
    bt_scores_list.append(bt_scores)
bt_result = pd.concat(bt_result_list, axis=0)
bt_scores = pd.concat(bt_scores_list, axis=0)
bt_scores.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10121012101210121, 'fraction_numerical': 0.0062339567290062336, 'mean_word_length': 4.969365426695842, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '108396', 'license': 'Apache-2.0', 'n_tokens_mistral': 1035, 'n_tokens_neox': 988, 'n_words': 158, 'path': 'examples/archive/Backtest_Misc.ipynb', 'repo_name': 'Okroshiashvili/orbit', 'size': '2727'}