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

[enhancement] Add conditional seasonality as a new feature #1067

Merged
merged 9 commits into from
Jan 13, 2023

Conversation

judussoari
Copy link
Collaborator

@judussoari judussoari commented Dec 14, 2022

🔬 Background

NeuralProphet forces a weekly, daily, and yearly seasonality to the data (if activated). Apart from that, we were able to add custom seasonalities to the model. However, both custom and default seasonalities are applied to the entire dataset, without the possibility to specify a condition for a custom seasonality.

🔮 Key changes

condition_name is a new input parameter for m.add_seasonality(). Using this, the NP model fits and predicts seasonalities according to the condition specified by the user.
The condition is specified through a new column that is added to the input df. The new column should exclusively contain boolean values. True, if the condition applies to the row timestamp, and False otherwise. The same column(s) must be added to the future dataframe, if we want to predict into the unknown future.

The user workflow follows the example of Facebook Prophet

See test_custom_seasons() for an exmaple: on-season and off-season weekly seasonalities for Football. on-season we see a high during the weekends, while during the week there is no game going on. off-season does not show an increase during the weekend.

Bildschirmfoto 2022-12-13 um 17 04 15

📋 Review Checklist

  • I have performed a self-review of my own code.
  • I have commented my code, added docstrings and data types to function definitions.
  • I have added pytests to check whether my feature / fix works.

*Indicates whether conditional seasonality is applied or not - Type: boolean
*Mask out all the seasonality features that do not belong to the conditioned seasonality

*Ensured conditional seasonality is part of the model's data_params

*Integrated check in check_dataframe to rule out false column names for conditional seasonality
@judussoari judussoari added enhancement status: needs review PR needs to be reviewed by Reviewer(s) labels Dec 14, 2022
@judussoari judussoari added this to the Release 0.5.1 milestone Dec 14, 2022
@judussoari judussoari self-assigned this Dec 14, 2022
@github-actions
Copy link

github-actions bot commented Dec 14, 2022

64469dd

Model Benchmark

Benchmark Metric main current diff
AirPassengers MAE_val 15.2698 15.2698 0.0%
AirPassengers RMSE_val 19.4209 19.4209 0.0%
AirPassengers Loss_val 0.00195 0.00195 0.0%
AirPassengers MAE 9.82902 9.82902 0.0%
AirPassengers RMSE 11.7005 11.7005 0.0%
AirPassengers Loss 0.00056 0.00056 0.0%
AirPassengers time 5.20638 4.34 -16.64% 🎉
YosemiteTemps MAE_val 1.72948 1.72949 0.0%
YosemiteTemps RMSE_val 2.27386 2.27386 0.0%
YosemiteTemps Loss_val 0.00096 0.00096 0.0%
YosemiteTemps MAE 1.45189 1.45189 0.0%
YosemiteTemps RMSE 2.16631 2.16631 0.0%
YosemiteTemps Loss 0.00066 0.00066 0.0%
YosemiteTemps time 119.133 97.64 -18.04% 🎉
PeytonManning MAE_val 0.64636 0.64636 0.0%
PeytonManning RMSE_val 0.79276 0.79276 0.0%
PeytonManning Loss_val 0.01494 0.01494 0.0%
PeytonManning MAE 0.42701 0.42701 0.0%
PeytonManning RMSE 0.57032 0.57032 0.0%
PeytonManning Loss 0.00635 0.00635 0.0%
PeytonManning time 14.2091 11.99 -15.62% 🎉
Model training plots

Model Training

PeytonManning

YosemiteTemps

AirPassengers

@codecov-commenter
Copy link

codecov-commenter commented Dec 14, 2022

Codecov Report

Merging #1067 (6192355) into main (2f2907f) will increase coverage by 0.02%.
The diff coverage is 90.32%.

@@            Coverage Diff             @@
##             main    #1067      +/-   ##
==========================================
+ Coverage   89.98%   90.01%   +0.02%     
==========================================
  Files          21       21              
  Lines        4784     4805      +21     
==========================================
+ Hits         4305     4325      +20     
- Misses        479      480       +1     
Impacted Files Coverage Δ
neuralprophet/df_utils.py 94.68% <83.33%> (-0.05%) ⬇️
neuralprophet/configure.py 90.15% <100.00%> (+0.07%) ⬆️
neuralprophet/forecaster.py 87.90% <100.00%> (+0.02%) ⬆️
neuralprophet/time_dataset.py 94.68% <100.00%> (+0.05%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@judussoari judussoari requested review from ourownstory and Kevin-Chen0 and removed request for ourownstory and Kevin-Chen0 December 14, 2022 02:12
Copy link
Owner

@ourownstory ourownstory left a comment

Choose a reason for hiding this comment

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

Could you please also add a quick example to the seasonal tutorial (or a new tutorial notebook if that one feels too long already)?

If condition_name is provided, the dataframe passed to `fit` and
`predict` should have a column with the specified condition_name
containing only zeros and ones, deciding when to apply seasonality.
Floats between 0 and 1 can be used to apply seasonality partially.
Copy link
Owner

Choose a reason for hiding this comment

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

Can you please add a (code) example - using quarterly changing weekly seasonality - to the docstring?

Copy link
Owner

@ourownstory ourownstory left a comment

Choose a reason for hiding this comment

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

Good work!
I think we can merge this now.

Please add in a subsequent PR

  • docstring example
  • tutorial inclusion
  • some validation of the values in the condition column (range 0-1)

@ourownstory ourownstory merged commit 1b44634 into main Jan 13, 2023
@ourownstory ourownstory deleted the conditional_seasonality branch January 13, 2023 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs review PR needs to be reviewed by Reviewer(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants