Forecasting Experiment¶
The main goal here is to show the simple interface for running a wide range of experiments in forecasting consumer energy utilization.
We aim to show modularity with respect to:
Dataset: the underlying data being forecasted
Models: take sensor measurements (mostly time series data) and output forecast of these results
Tasks: here we define some of the basic configurations of time series experiments such as horizon and history.
Here we use synthetic data from Smart-DS and downloaded from BetterGrids.org
[2]:
import sys
from gridds.experimenter import Experimenter
from gridds.data import SmartDS
from gridds.tools.viz import visualize_output
import os
import matplotlib.pyplot as plt
from gridds.models import ARIMA, VRAE, LSTM, VanillaRNN
# from gridds.tools.utils import *
import gridds.tools.tasks as tasks
import shutil
Run all experiments from root directory
[3]:
# run experiments from root dir ( one up)
os.chdir('../')
Instantiate Dataset¶
The first thing we do is build the dataset class.
We choose a train/test percentage and the the “size” or number of total points we want to use.
Since this is an example we use a fairly small number of data points.
We provide the dataset reader class instructions about what part of this dataset we would like to fetch and how we would like it ordered. This is applicable across many types of data. Ie;
sourcesmight be “transformers”,modalitieswould be “[phase angle, voltage]” andreplicatesmight be “sites’.Each of these entries needs to be a folder.
Prepare data converts these into X and y for machine learning.
[4]:
dataset = SmartDS('univariate_nrel', sites=1, test_pct=.5, normalize=False, size=300)
reader_instructions = {
'sources': ['P1U'],
'modalities': ['load_data'],
'target': '', # NREL synthetic data doesn't have faults
'replicates': ['customers']
}
dataset.prepare_data(reader_instructions)
Instantiate Methods¶
Here the modularity and instantiation procedure for methods is very clear since they are all just getting stored in a list.
We can set some parameters for each method.
[8]:
methods = []
methods += [ARIMA('ARIMA')]
methods += [ VanillaRNN('RNN', train_iters=20, learning_rate=.001, batch_size=5, hidden_size=16)]
methods += [VRAE('VRAE',train_iters=20, batch_size=5)]
methods += [LSTM('LSTM', train_iters=20, batch_size=5, learning_rate=.003, layer_dim=1, hidden_size=32, dropout=0)]
Instantiate Task and Run Experiment¶
Experimenterhandles the bulk of running these experiments.we choose a task when we run
experimenter.run_experiment. Here we chosetasks.default_autoregression
[10]:
tasks.default_autoregression
[10]:
{'name': 'autoregression',
'procedure': ['fit', 'predict'],
'metrics': [<function gridds.tools.metrics.mae(y_pred, y)>,
<function gridds.tools.metrics.rmse(y_pred, y)>,
<function gridds.tools.metrics.rse(y_pred, y)>,
<function gridds.tools.metrics.bias(y_pred, y)>],
'delay': 5,
'horizon': 1,
'univariate': True}
[12]:
exp = Experimenter('autoregression_basic_tst', runs=1)
exp.run_experiment(dataset,methods,task=tasks.default_autoregression, clean=False)
[ ]:
[ ]:
visualize_output(os.path.join('outputs', exp.name))
[ ]:
# copy this file into output folder for archive
curr_filepath = os.path.join(os.getcwd(), 'experiments', __file__)
shutil.copy(curr_filepath, os.path.join('outputs', exp.name))