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 19 commits into
base: master
Choose a base branch
from

Conversation

Lopa10ko
Copy link

@Lopa10ko Lopa10ko commented Mar 6, 2024

WIP

  • refactor code after initial review
  • add pip install fedot[extra] to a setup file
  • manually test fedot ts forecasting scenario

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

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
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
2 participants