question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Derive ForecastingHorizon from DatetimeIndex in predict method

See original GitHub issue

Is your feature request related to a problem? Please describe. Basically just a simplification request: converting from DatetimeIndex to ForecastingHorizon seems to me like a step that the BaseForecaster should be able to handle by itself. So instead of:

model = NaiveForecaster()
model.fit(train_data)
fh = ForecastingHorizon(test_data.index, is_relative=False)
forecast_data = model.predict(fh)

I would suggest users should be able to do:

model = NaiveForecaster()
model.fit(train_data)
forecast_data = model.predict(test_data.index)

which would be very elegant imo. It also removes the need to import ForecastingHorizon, which shortens user code and—and here’s my selfish reason—possibly avoids adding sktime as an explicit dependency in libraries that want to be sktime compatible but do not want to depend on it.

Describe the solution you’d like Perhaps the BaseForecaster.predict method can check whether its fh argument is a DatetimeIndex instance and run the necessary conversion itself?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
fkiralycommented, Jul 19, 2021

I quickly mocked sth up, @Flix6x, in #1169 - it appears the ForecastingHorizon constructor complains when getting a pd.DatetimeIndex instead of doing what I’d think is the obvious thing (from user perspective).

The tests still run for some time and I have to sign off now, but feel free to have a look (and help me debugging in case they break 😃 )

0reactions
fkiralycommented, Jul 20, 2021

Well, thanks for bringing it up, @Flix6x! This behaviour was not on my mental map.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ForecastingHorizon — sktime documentation
In-sample values of forecasting horizon. Return out-of-sample values of fh. Cutoff value is required to convert a relative forecasting horizon to an absolute ......
Read more >
sktime/_fh.py at main - GitHub
Index and delegate method calls to wrapped pandas.Index ... Forecasting horizon with steps ahead to predict. ... """Extract frequency string from cutoff.
Read more >
Source code for darts.models.forecasting.forecasting_model
The function `predict()` applies `f()` on one or several time series in order to obtain forecasts for a desired number of time stamps...
Read more >
Index and Date Problem on Plot Prediction - python
One thing you can do is to simply save the datetime index before model training/inference and then join it back on the RangeIndex....
Read more >
pandas.DatetimeIndex — pandas 1.5.2 documentation
Boolean indicator if the date belongs to a leap year. inferred_freq. Tries to return a string representing a frequency generated by infer_freq. Methods...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found