Skip to content

Commit

Permalink
Merge pull request #82 from databricks-industry-solutions/fix-neuralf…
Browse files Browse the repository at this point in the history
…orecast-covariates

bug fixed for neuralforecast models
  • Loading branch information
ryuta-yoshimatsu authored Jan 20, 2025
2 parents dfdcee8 + 39eacb2 commit ae46562
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions mmf_sa/Forecaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ def backtest_global_model(
StructField("model_pickle", BinaryType()),
]
)
# Covert to Python-native types before converting to pyspark dataframe
res_pdf['forecast'] = res_pdf['forecast'].apply(lambda x: [float(i) for i in x])
res_pdf['actual'] = res_pdf['actual'].apply(lambda x: [float(i) for i in x])
res_sdf = self.spark.createDataFrame(res_pdf, schema)
# Write evaluation results to a delta table
if write:
Expand Down
4 changes: 2 additions & 2 deletions mmf_sa/models/neuralforecast/NeuralForecastPipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ def calculate_metrics(
else:
raise Exception(f"Metric {self.params['metric']} not supported!")
for key in keys:
actual = val_df[val_df[self.params["group_id"]] == key][self.params["target"]]
actual = val_df[val_df[self.params["group_id"]] == key][self.params["target"]].reset_index(drop=True)
forecast = pred_df[pred_df[self.params["group_id"]] == key][self.params["target"]].\
iloc[-self.params["prediction_length"]:]
iloc[-self.params["prediction_length"]:].reset_index(drop=True)
try:
if metric_name == "smape":
smape = MeanAbsolutePercentageError(symmetric=True)
Expand Down

0 comments on commit ae46562

Please sign in to comment.