def plot_test_prediction(target, predictions, model_name, data_desc, error_func): save_plot = options.save_plot if save_plot: pp_path = get_path(options, "prediction_%s" % data_desc, "pdf") pp = PdfPages(pp_path) error = concat_and_calc_error(predictions, target, error_func) if np.any(target == 0): mapestr = "no MAPE due to 0's in observations" else: mapestr = 'MAPE: %3.2f' % concat_and_calc_error( predictions, target, sg.utils.mape) title = 'Test data prediction, %s, %s, %i days, model error: ' \ '%3.2f, RMSE: %3.2f, %s' % \ (model_name, data_desc, len(predictions), error, concat_and_calc_error(predictions, target, Oger.utils.rmse), mapestr) print "%s." % title plt.figure() plt.title(title) plot_target_predictions(target, predictions) if save_plot: pp.savefig() pp.close() if not options.no_show_plot: plt.ioff() # In case --live-plot is chosen, since that sets ion(). plt.show()
def test_plot_full_ar(self): for std in [0.1]: #[0.01, 0.1, 0.5]: (predictions, target, rmse) = self._test_ar_fake( [self.param_lags, []], std) plot_target_predictions(target, predictions) plt.title('Fake data prediction, sin input only, std=%f. RMSE %f' % (std, rmse)) (predictions, target, rmse) = self._test_ar_fake( [[], self.param_lags], std) plot_target_predictions(target, predictions) plt.title('Fake data prediction, cos input only, std=%f. RMSE %f' % (std, rmse)) (predictions, target, rmse) = self._test_ar_fake( [self.param_lags, self.param_lags], std) plot_target_predictions(target, predictions) plt.title('Fake data prediction, sin+cos inputs, std=%f. RMSE %f' % (std, rmse)) self.cos = np.sin (predictions, target, rmse) = self._test_ar_fake( [self.param_lags, self.param_lags], std) plot_target_predictions(target, predictions) plt.title('Fake data prediction, sin+sin inputs, std=%f. RMSE %f' % (std, rmse)) self.cos = np.cos self.hindsight = self.hindsight * 2 (predictions, target, rmse) = self._test_ar_fake( [self.param_lags, []], std) plot_target_predictions(target, predictions) plt.title('Fake data prediction, double length sin, std=%f. RMSE %f' % (std, rmse)) self.hindsight = self.hindsight / 2
def plot_test_prediction(target, predictions, model_name, data_desc, error_func): save_plot = options.save_plot if save_plot: pp_path = get_path(options, "prediction_%s" % data_desc, "pdf") pp = PdfPages(pp_path) error = concat_and_calc_error(predictions, target, error_func) if np.any(target == 0): mapestr = "no MAPE due to 0's in observations" else: mapestr = 'MAPE: %3.2f' % concat_and_calc_error(predictions, target, sg.utils.mape) title = 'Test data prediction, %s, %s, %i days, model error: ' \ '%3.2f, RMSE: %3.2f, %s' % \ (model_name, data_desc, len(predictions), error, concat_and_calc_error(predictions, target, Oger.utils.rmse), mapestr) print "%s." % title plt.figure() plt.title(title) plot_target_predictions(target, predictions) if save_plot: pp.savefig() pp.close() if not options.no_show_plot: plt.ioff() # In case --live-plot is chosen, since that sets ion(). plt.show()
def test_plot_ar_ga_with_predefined_lags(self): data = pd.DataFrame({'Load': self.data, 'Temperature': 0}) plt.figure() plt.title("Prediction with varying number of AR indices") for order, fmt in zip([1, 2, 3], ['r-', 'g-', 'c-']): (predictions, target, rmse) = \ self._test_ar_ga_with_predefined_lags(data, [self.hindsight, order]) plot_target_predictions(target, predictions, fmt)