Skip to content

Commit

Permalink
Merge pull request #220 from ibm-granite/pipeline_exog
Browse files Browse the repository at this point in the history
Address some issues in forecasting pipeline
  • Loading branch information
wgifford authored Dec 4, 2024
2 parents ab5777d + 176e7d1 commit a1da2c5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tsfm_public/toolkit/time_series_forecasting_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def preprocess(self, time_series, **kwargs) -> Dict[str, Union[GenericTensor, Li
# future data needs some values for targets, but they are unused
future_time_series[target_columns] = 0
future_time_series = self.feature_extractor.preprocess(future_time_series)
future_time_series.drop(columns=target_columns)
future_time_series = future_time_series.drop(columns=target_columns)

time_series = pd.concat((time_series, future_time_series), axis=0)
else:
Expand Down Expand Up @@ -424,13 +424,16 @@ def postprocess(self, input, **kwargs):
# name the predictions of target columns
# outputs should only have size equal to target columns

# only allow adding ground truth when not exploding
add_known_ground_truth = kwargs["add_known_ground_truth"] if not kwargs["explode_forecasts"] else False

prediction_columns = []
for i, c in enumerate(kwargs["target_columns"]):
prediction_columns.append(f"{c}_prediction" if kwargs["add_known_ground_truth"] else c)
prediction_columns.append(f"{c}_prediction" if add_known_ground_truth else c)
out[prediction_columns[-1]] = input[model_output_key][:, :, i].numpy().tolist()
# provide the ground truth values for the targets
# when future is unknown, we will have augmented the provided dataframe with NaN values to cover the future
if kwargs["add_known_ground_truth"]:
if add_known_ground_truth:
for i, c in enumerate(kwargs["target_columns"]):
ground_truth = input["future_values"][:, :, i].numpy()
missing = ~input["future_observed_mask"][:, :, i].numpy()
Expand Down Expand Up @@ -478,7 +481,7 @@ def postprocess(self, input, **kwargs):
# inverse scale if we have a feature extractor
if self.feature_extractor is not None and kwargs["inverse_scale_outputs"]:
out = self.feature_extractor.inverse_scale_targets(out)
if kwargs["add_known_ground_truth"]:
if add_known_ground_truth:
out = self.feature_extractor.inverse_scale_targets(out, suffix="_prediction")

return out

0 comments on commit a1da2c5

Please sign in to comment.