def get_predictions(context,model,X,y,train_scaler,batch_size,look_ahead,look_back,epochs,experiment_id): predictions = model.predict(X, batch_size=batch_size) # rescale predictions = train_scaler.inverse_transform(predictions) y = train_scaler.inverse_transform(y) # extract first timestep for true values y_true = y[:, 0].flatten() # diagonals contains a reading's values calculated at different points in time diagonals = util.get_diagonals(predictions) # the top left and bottom right predictions do not contain predictions for all timesteps # fill the missing prediction values in diagonals. curenttly using the first predicted value for all missing timesteps for idx, diagonal in enumerate(diagonals): diagonal = diagonal.flatten() # missing value filled with the first value diagonals[idx] = np.hstack((diagonal, np.full(look_ahead - len(diagonal), diagonal[0]))) predictions_timesteps = np.asarray(diagonals) shifted_1 = util.shift_time_series(y_true, 1) title = "Prediction on %s data. %d epochs, look back %d, look_ahead %d & batch_size %d." % ( context, epochs, look_back, look_ahead, batch_size) path = "%s/%s/"%("imgs",experiment_id) make_plots(context,predictions_timesteps,y_true,look_ahead,title,path,cfg.run_config['save_figure']) return predictions_timesteps, y_true
def get_predictions(context, model, X, y, train_scaler, batch_size, look_ahead, look_back, epochs, experiment_id): predictions = model.predict(X, batch_size=batch_size) # print predictions.shape # rescale predictions = train_scaler.inverse_transform(predictions) y = train_scaler.inverse_transform(y) print('predictions:', predictions.shape) print('y:', y.shape) # extract first timestep for true values y_true = y[:, 0].flatten() print('y_true:', y_true.shape) # diagonals contains a reading's values calculated at different points in time diagonals = util.get_diagonals(predictions) print('diagonals:', len(diagonals)) # the top left and bottom right predictions do not contain predictions for all timesteps # fill the missing prediction values in diagonals. curenttly using the first predicted value for all missing timesteps for idx, diagonal in enumerate(diagonals): diagonal = diagonal.flatten() # missing value filled with the first value diagonals[idx] = np.hstack( (diagonal, np.full(look_ahead - len(diagonal), diagonal[0]))) predictions_timesteps = np.asarray(diagonals) print('y_true: ', y_true.shape) print('predictions_timesteps:', predictions_timesteps.shape) for i in range(look_ahead): logging.info( "%s RMSE on %d timestep prediction %f" % (context, (i + 1), mean_squared_error(y_true, predictions_timesteps[:, i])**0.5)) shifted_1 = util.shift_time_series(y_true, 1) logging.info(" %s RMSE Naive One Timestep Shift %f", context, mean_squared_error(y_true[1:], shifted_1[1:])**0.5) title = "Prediction on %s data. %d epochs, look back %d, look_ahead %d & batch_size %d." % ( context, epochs, look_back, look_ahead, batch_size) path = "%s/%s/" % ("imgs", experiment_id) make_plots(context, predictions_timesteps, y_true, look_ahead, title, path, cfg.run_config['save_figure'], cfg.run_config['Xserver']) return predictions_timesteps, y_true
def get_predictions(context,model,X,y,train_scaler,batch_size,look_ahead,look_back,epochs,experiment_id): predictions = model.predict(X, batch_size=batch_size) print predictions.shape # rescale predictions = train_scaler.inverse_transform(predictions) y = train_scaler.inverse_transform(y) # extract first timestep for true values y_true = y[:, 0].flatten() # diagonals contains a reading's values calculated at different points in time diagonals = util.get_diagonals(predictions) # the top left and bottom right predictions do not contain predictions for all timesteps # fill the missing prediction values in diagonals. curenttly using the first predicted value for all missing timesteps for idx, diagonal in enumerate(diagonals): diagonal = diagonal.flatten() # missing value filled with the first value diagonals[idx] = np.hstack((diagonal, np.full(look_ahead - len(diagonal), diagonal[0]))) predictions_timesteps = np.asarray(diagonals) for i in range(look_ahead): logging.info("%s RMSE on %d timestep prediction %f" % ( context, (i + 1), mean_squared_error(y_true, predictions_timesteps[:, i]) ** 0.5)) shifted_1 = util.shift_time_series(y_true, 1) logging.info(" %s RMSE Naive One Timestep Shift %f",context, mean_squared_error(y_true[1:], shifted_1[1:]) ** 0.5) title = "Prediction on %s data. %d epochs, look back %d, look_ahead %d & batch_size %d." % ( context, epochs, look_back, look_ahead, batch_size) path = "%s/%s/"%("imgs",experiment_id) make_plots(context,predictions_timesteps,y_true,look_ahead,title,path,cfg.run_config['save_figure'], cfg.run_config['Xserver']) return predictions_timesteps, y_true