Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time series forecasting support #611

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

Lopa10ko
Copy link

@Lopa10ko Lopa10ko commented Mar 6, 2024

Summary

Add support for time series forecasting functionality from FEDOT framework.

Context

closes #610

@shchur shchur self-assigned this Mar 13, 2024
training_params.update({k: v for k, v in config.framework_params.items() if not k.startswith('_')})
n_jobs = training_params["n_jobs"]

log.info('Running FEDOT with a maximum time of %ss on %s cores, optimizing %s.',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: f-strings are a bit more readable and are compatible with all Python versions used by AMLB

f"Running FEDOT with a maximum time of {config.max_runtime_seconds}s on {n_jobs} cores, optimizing {scoring_metric}"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

predictions = []

for label in train_df[id_column].unique():
train_sub_df = train_df[train_df[id_column] == label].drop(columns=[id_column], axis=1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be very inefficient for large dataframes with many time series (scales as O(N^2)). A better option would be to use groupby, e.g.

for label, ts in train_df.groupby(id_column, sort=False):
    train_series = ts[dataset.target].to_numpy()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, tried that: imo using zip may be inappropriate here, so I would stick with a janky bad-asymptotic solution to ensure that the labels are matching
e6f19e7

train_sub_df = train_df[train_df[id_column] == label].drop(columns=[id_column], axis=1)
train_series = np.array(train_sub_df[dataset.target])
train_input = InputData(
idx=train_sub_df.index.to_numpy(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code uses the range index [0, 1, 2, ..., n-1] instead of the timestamps of the time series. Should this be train_sub_df[timestamp_column] instead, or does FEDOT ignore the timestamps?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FEDOT ignores timestamps, so that idx should be fine

)

test_sub_df = test_df[test_df[id_column] == label].drop(columns=[id_column], axis=1)
test_series = np.array(test_sub_df[dataset.target])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contains the future values of the time series, I doubt that these values need to be fed to the model at predictions time.

For example, if training data contains time steps [1, 2, 3, ..., T] and the goal is to predict [T+1, ..., T+H], then based on your current code

  • train_series contains timesteps [1, 2, 3, ..., T]
  • test_series contains timesteps [T+1, ..., T+H]

My guess is that we need to pass train_series as input to both fit() and predict()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in essence predict and forecast are the same thing, but we could pass test_input with features from train_series and target from test_series to get the prediction horizon in a predict

changed to a clear forecast method
a357726

timeout=runtime_min,
metric=scoring_metric,
seed=config.seed,
max_pipeline_fit_time=runtime_min / 10,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is / 10 necessary here?

Copy link
Author

@Lopa10ko Lopa10ko Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally speaking, this is a small safety measure to ensure that the training time of one pipeline is exactly within the total timeout. the classification and regression #563 uses the same empirical approach. it should be patched in the future

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to split the time limit evenly across the series? Right now it seems that 10% of the total time limit is given to each series, which may lead to overruns if >10 series are available.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 97 to 98
training_duration=training_duration,
predict_duration=predict_duration)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it would be cleaner to remove the line training_duration, predict_duration = 0, 0 above and just return training_duration=training.duration, predict_duration=predict.duration here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we train the FEDOT model for each series (for each label), training.duration value isn't cumulative and will only reflect the time spent on the last iteration

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I didn't realize this was happening inside the loop over individual series

models_count += fedot.current_pipeline.length

save_artifacts(fedot, config)
return result(output_file=config.output_predictions_file,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's necessary to return dataset.repeated_item_id and dataset.repeated_abs_seasonal_error as optional_columns in the result for MASE computation to work correctly (see https://github.com/openml/automlbenchmark/blob/master/frameworks/AutoGluon/exec_ts.py#L63C1-L67C1).
This is a rather ugly hack that is necessary to make history-dependent metrics like MASE compatible with the AMLB results API.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lopa10ko
Copy link
Author

@shchu, thanks for the initial review :)
I intend to continue exploring the benchmarks and testing some things locally in order to ensure that all FEDOT-related functionality is working correctly. This may take some time, so when I'm finished, I will undraft this pull request.

@Lopa10ko Lopa10ko marked this pull request as ready for review May 16, 2024 13:26
@Lopa10ko
Copy link
Author

@shchur sorry it took ages to finally return to this PR.
would be great to have a further review

@Lopa10ko Lopa10ko requested a review from shchur July 11, 2024 13:37
@PGijsbers
Copy link
Collaborator

@shchur would you be available for another look?:)

@shchur
Copy link
Collaborator

shchur commented Sep 20, 2024

Hi @Lopa10ko @PGijsbers, I will try to have a look at the PR today

Copy link
Collaborator

@shchur shchur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small comments that probably need to be addressed, but otherwise looks good to me.

timeout=runtime_min,
metric=scoring_metric,
seed=config.seed,
max_pipeline_fit_time=runtime_min / 10,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to split the time limit evenly across the series? Right now it seems that 10% of the total time limit is given to each series, which may lead to overruns if >10 series are available.


fedot = Fedot(
problem=TaskTypesEnum.ts_forecasting.value,
task_params=task.task_params,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, Fedot currently only supports point forecasting but AMLB may also include probabilistic forecasting tasks (see https://github.com/openml/automlbenchmark/blob/master/amlb/results.py#L767-L792). Probably it would make sense to raise an exception if someone tries to evaluate FEDOT on such a probabilistic forecasting task.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to distinguish a probabilistic forecasting task based on the benchmark run config?

the get_fedot_metrics function already emits logs in case of unsupported metrics (like mql, wql, and sql)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that filtering by the mql, wql, sql metrics is the simplest way to accomplish this.

Another option is to repeat the point forecast for each of the quantile levels and raise a warning.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lopa10ko
Copy link
Author

@shchur thanks for a review,
@PGijsbers if you have any suggestions for improvements, I would be happy to incorporate them

@PGijsbers
Copy link
Collaborator

In principle it looks fine. Does FEDOT support provided memory constraints? If so, I would appreciate it if you add that to the integration script (config.max_mem_size_mb).

@Lopa10ko
Copy link
Author

Lopa10ko commented Oct 5, 2024

In principle it looks fine. Does FEDOT support provided memory constraints? If so, I would appreciate it if you add that to the integration script (config.max_mem_size_mb).

@PGijsbers sorry, FEDOT does't have the capability to handle memory limitations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time series forecasting support for FEDOT
3 participants