def evaluate(self, data, metrics=['mse'], multioutput="uniform_average", batch_size=32): ''' Evaluate the time series pipeline. :param data: data can be a TSDataset or data creator(will be supported). The TSDataset should follow the same operations as the training TSDataset used in AutoTSEstimator.fit. :param metrics: list. The evaluation metric name to optimize. e.g. ["mse"] :param multioutput: Defines aggregating of multiple output values. String in ['raw_values', 'uniform_average']. The value defaults to 'uniform_average'. :param batch_size: predict batch_size, the process will cost more time if batch_size is small while cost less memory. The param is only effective when data is a TSDataset. The values defaults to 32. ''' _, y = self._tsdataset_to_numpy(data, is_predict=False) yhat = self.predict(data, batch_size=batch_size) if self._scaler: from zoo.chronos.data.utils.scale import unscale_timeseries_numpy y = unscale_timeseries_numpy(y, self._scaler, self._scaler_index) eval_result = [ Evaluator.evaluate(m, y_true=y, y_pred=yhat[:y.shape[0]], multioutput=multioutput) for m in metrics ] return eval_result
def unscale_numpy(self, data): ''' Unscale the time series forecaster's numpy prediction result/ground truth. :param data: a numpy ndarray with 3 dim whose shape should be exactly the same with self.numpy_y. :return: the unscaled numpy ndarray. ''' return unscale_timeseries_numpy(data, self.scaler, self.scaler_index)
def _unscale_numpy(self, data): ''' unscale the time series forecastor's numpy prediction result/ground truth. :param data: a numpy ndarray with 3 dim whose shape should be exactly the same with self.numpy_y. :return: the unscaled numpy ndarray ''' num_roll_target = len(self.roll_target) repeat_factor = len(self._id_list) if self.id_sensitive else 1 scaler_index = [self.target_col.index(self.roll_target[i]) for i in range(num_roll_target)] * repeat_factor return unscale_timeseries_numpy(data, self.scaler, scaler_index)
def predict(self, data, batch_size=32): ''' Rolling predict with time series pipeline. :param data: data can be a TSDataset or data creator(will be supported). The TSDataset should follow the same operations as the training TSDataset used in AutoTSTrainer.fit. :param batch_size: predict batch_size, the process will cost more time if batch_size is small while cost less memory. The param is only effective when data is a TSDataset. The values defaults to 32. ''' x, _ = self._tsdataset_to_numpy(data, is_predict=True) yhat = self._best_model.predict(x, batch_size=batch_size) if self._scaler: from zoo.chronos.data.utils.scale import unscale_timeseries_numpy yhat = unscale_timeseries_numpy(yhat, self._scaler, self._scaler_index) return yhat
def _tsdataset_unscale(self, y): if self._scaler: from zoo.chronos.data.utils.scale import unscale_timeseries_numpy y = unscale_timeseries_numpy(y, self._scaler, self._scaler_index) return y