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

Feature: Add support for logistic growth to Prophet #1419

Merged

Conversation

DavidKleindienst
Copy link
Contributor

@DavidKleindienst DavidKleindienst commented Dec 9, 2022

Fixes #628 and #178

Summary

Adds support for logistic growth to Prophet and a corresponding unit-test.

This PR adds the function Prophet.set_capacity to allow setting cap and floor parameters needed.
Prophet.set_capacity takes two arguments (cap and floor), which may be either numbers or Callables.
floor defaults to 0, to replicate FBProphet's default behaviour.
Numbers should be used as arguments when modeling a constant carrying capacity, Callables can be supplied when variable carrying capacities are needed.
A Callable supplied as argument to Prophet.set_capacity must accept a DatetimeIndex or RangeIndex as input, and return a Sequence of numbers with the same length. Each number in this Sequence indicates the carrying capacity at the corresponding index.

During Prophet.fit and Prophet.predict cap and floor columns with the appropriate values are added to fit_df and predict_df, respectively.
If Prophet was instantiated with growth = 'logistic, Prophet.fit now raises a ValueError if carrying capacities have not been set.
If Prophet.set_capacity is called when growth is not logistic, a warning is logged and the cap and floor values set are ignored.

@DavidKleindienst DavidKleindienst changed the title Feat/prophet logistic growth (#628) Feature: Add support for logistic growth to Prophet Dec 9, 2022
@codecov-commenter
Copy link

codecov-commenter commented Dec 16, 2022

Codecov Report

Base: 94.09% // Head: 94.02% // Decreases project coverage by -0.07% ⚠️

Coverage data is based on head (a6fc312) compared to base (e1c8d34).
Patch coverage: 82.60% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1419      +/-   ##
==========================================
- Coverage   94.09%   94.02%   -0.07%     
==========================================
  Files         125      125              
  Lines       11071    11079       +8     
==========================================
  Hits        10417    10417              
- Misses        654      662       +8     
Impacted Files Coverage Δ
darts/models/forecasting/prophet_model.py 92.59% <82.60%> (-1.70%) ⬇️
darts/utils/data/tabularization.py 99.27% <0.00%> (-0.73%) ⬇️
darts/timeseries.py 92.14% <0.00%> (-0.23%) ⬇️
darts/ad/anomaly_model/filtering_am.py 91.93% <0.00%> (-0.13%) ⬇️
...arts/models/forecasting/torch_forecasting_model.py 89.52% <0.00%> (-0.05%) ⬇️
darts/models/forecasting/block_rnn_model.py 98.24% <0.00%> (-0.04%) ⬇️
darts/models/forecasting/nhits.py 99.27% <0.00%> (-0.01%) ⬇️
darts/datasets/__init__.py 100.00% <0.00%> (ø)

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

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@hrzn hrzn added this to In review in darts via automation Jan 5, 2023
Copy link
Contributor

@hrzn hrzn left a comment

Choose a reason for hiding this comment

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

Many thanks @DavidKleindienst and I'm really sorry it took us so long to review!

I think it looks really good. I would just prefer if we could specify cap and floor in the constructor instead of relying on an extra set_capacity() method. Let me know your thoughts.

darts/models/forecasting/prophet_model.py Outdated Show resolved Hide resolved
darts/models/forecasting/prophet_model.py Outdated Show resolved Hide resolved
See <https://facebook.github.io/prophet/docs/saturating_forecasts.html> for more information
on logistic forecasts.

The `cap` and `floor` parameters may be:
Copy link
Contributor

Choose a reason for hiding this comment

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

You should add a blank line for the bullet-point list to render correctly in HTML (you can try building & rendering the doc with ./gradlew buildDocs to check the HTML files directly).

@hrzn
Copy link
Contributor

hrzn commented Jan 31, 2023

LGTM, thanks @DavidKleindienst !
There's only a linting issue remaining

@DavidKleindienst
Copy link
Contributor Author

Fixed the linting problem and removed a the previous docstring that accidentally remained there.
The remaining failing tests seem to be unrelated.
Thanks @hrzn for reviewing!

@hrzn hrzn merged commit 84e8313 into unit8co:master Feb 16, 2023
darts automation moved this from In review to Done Feb 16, 2023
@DavidKleindienst DavidKleindienst deleted the Feat/Prophet_logistic_growth_(#628) branch February 20, 2023 12:13
@dennisbader dennisbader moved this from Done to Released in darts May 23, 2023
alexcolpitts96 pushed a commit to alexcolpitts96/darts that referenced this pull request May 31, 2023
* Add logistic growth to prophet

* Add RangeIndex to typehint and docstring

* Fix import order

* Move cap & floor to __init__

* Update darts/models/forecasting/prophet_model.py

* Fix linting & remove duplicat docstring

---------

Co-authored-by: David Kleindienst <kleindienst@ximes.com>
Co-authored-by: Julien Herzen <julien@unit8.co>
Co-authored-by: Julien Herzen <j.herzen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
darts
Released
Development

Successfully merging this pull request may close these issues.

Logistic growth with Prophet
3 participants