<jupyter_start><jupyter_text>Experiments on electricity data  1. Experiment description:** Models: ** Naive, Mean, AutoRegression and TRMF models;** Lags: ** {1, 24};** Forecast horizon: ** 1, 5, 10, 20;** Metrics: ** Normalized deviation (ND), Normalized Root Mean Squared Error (NRMSE).  2. Load data.<jupyter_code>electricity = pd.read_table('../data/LD2011_2014.txt', sep=';', decimal=',')
electricity.head()
# transpose and sum by hours
data = electricity.values[:,1:].T.reshape((35064*370,4)).sum(axis=1).reshape((370,35064))[:,10064:].astype(float)[:, -750:]
data.shape
plt.figure(figsize=(15,8))
plt.plot(data[100], color='blue')

plt.xlabel('timepoint')
plt.ylabel('value')

plt.show()
N = 370
T = 750
K = 8
lags = [1, 24]
L = len(lags)<jupyter_output><empty_output><jupyter_text>3. Apply models<jupyter_code># Naive model
for h in [1, 5, 10, 20]:
    model = NaiveModel()
    scores_nd = RollingCV(model, data, T-9-h, h, T_step=1, metric='MAE')
    scores_nrmse = RollingCV(model, data, T-9-h, h, T_step=1, metric='NRMSE')
    print('Naive model performance ND/NRMSE (h = {}): {}/{}'.format(h, round(np.array(scores_nd).mean(),3),\
                                                                    round(np.array(scores_nrmse).mean(),3)))
# Mean model
for h in [1, 5, 10, 20]:
    model = MeanModel()
    scores_nd = RollingCV(model, data, T-9-h, h, T_step=1, metric='ND')
    scores_nrmse = RollingCV(model, data, T-9-h, h, T_step=1, metric='NRMSE')
    print('Mean model performance ND/NRMSE (h = {}): {}/{}'.format(h, round(np.array(scores_nd).mean(),3),\
                                                          round(np.array(scores_nrmse).mean(),3)))
# AR model
for h in [1, 5, 10, 20]:
    model = AutoRegressionModel(lags)
    scores_nd = RollingCV(model, data, T-9-h, h, T_step=1, metric='ND')
    scores_nrmse = RollingCV(model, data, T-9-h, h, T_step=1, metric='NRMSE')
    print('AR performance ND/NRMSE (h = {}): {}/{}'.format(h, round(np.array(scores_nd).mean(),3),\
                                                           round(np.array(scores_nrmse).mean(),3)))
# TRMF model
lambda_f = 1.
lambda_x = 1.
lambda_w = 1.
eta = 1.
alpha = 1000.
max_iter = 1000

for h in [1, 5, 10, 20]:
    model = trmf(lags, K, lambda_f, lambda_x, lambda_w, alpha, eta, max_iter)
    scores_nd = RollingCV(model, data, T-9-h, h, T_step=1, metric='ND')
    scores_nrmse = RollingCV(model, data, T-9-h, h, T_step=1, metric='NRMSE')
    print('TRMF performance ND/NRMSE (h = {}): {}/{}'.format(h, round(np.array(scores_nd).mean(),3),\
                                                    round(np.array(scores_nrmse).mean(),3)))<jupyter_output>TRMF performance ND/NRMSE (h = 1): 0.637/0.809
TRMF performance ND/NRMSE (h = 5): 0.74/0.962
TRMF performance ND/NRMSE (h = 10): 0.675/0.925
TRMF performance ND/NRMSE (h = 20): 0.585/0.807
{'fraction_non_alphanumeric': 0.18450704225352113, 'fraction_numerical': 0.056338028169014086, 'mean_word_length': 3.1474452554744525, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '649864', 'license': 'Apache-2.0', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1056, 'n_words': 240, 'path': 'TRFM/experiments_electricity.ipynb', 'repo_name': 'dmohorcic/SU_project', 'size': '2840'}