This script evaluates a trained neural network on its salient features regarding the time and feature dimension and creates a saliency heatmap. The neural network should be trained beforehand.
The output consists of the most salient features visualized in the form of saliency maps split up into multiple .png images together with a csv file on the metrics and the model’s output tensors. Basic saliency map with 7 days long recent history horizon input (predictor variable load, and hour of the day) in the encoder and one day prediction. Decoder inputs are sinus and cosinus encoding of the hour of the day.
Saliency map showing the importance of features per timestep tp maintain the trained loss.
Select and download the data on which you want to train a neural network on and put it in the data folder.
Make a new folder in the targets folder and put a config.json
and tuning.json file within.
There you can set all the relevant paths and parameters.
Now train the neural network on the data by using the fc_train function.
The resulting net will be saved in the oracles folder
Now in __main__
function of the interpreter.py
the following setting need to be made:
MAX_BATCH_SIZE
to the number of references to use for each feature (recommended: At least 10)MAX_EPOCHS
to the number of epochs of the saliency map optimization process (recommended: At least a few thousand)N_TRIALS
to the number of hyperparameter search trials to run (recommended: at least 30)MODEL_NAME
to the name of the folder in the targets folder created beforeSEP
to the column seperation sign used in the data file (eg. “;” or “,")timesteps
to any number of timesteps to interpret (e.g [1,2,3])beware that the timestep indicates the beginning of the history horizon, not the forecast horizon. Also the timestep should be identical to the one of the internal dataloader not the datasheet file in the data folder
Now run the interpreter.py
script.
The function will now read in all the parameters it needs from the config.json
file.
The trained net will be loaded and the saliency map is calculated for each timestep.
During the hyperparameter search some tensor will be saved to the oracles/interpretation/Tensors folder
and the Tensors of the best performing saliency map are loaded again automatically after the process for plotting purposes.
After the interpreter.py
script has finished several plots can be found in the oracles/interpretation/plots/<model name> folder:
The numbers in the plot names refer to the timestep of the plot