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

[ENH] Adapter for DARTS #1624

Open
ngupta23 opened this issue Nov 18, 2021 · 20 comments · May be fixed by #5043 or #6454
Open

[ENH] Adapter for DARTS #1624

ngupta23 opened this issue Nov 18, 2021 · 20 comments · May be fixed by #5043 or #6454
Assignees
Labels
interfacing algorithms Interfacing existing algorithms/estimators from third party packages module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting

Comments

@ngupta23
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Currently models from DARTS are not supported in sktime.

Describe the solution you'd like
Since the DARTS models use a unified fit, predict format, it may be beneficial to have a DARTS adapter built into sktime. The catch seems to be that DARTS works on a proprietary format of data (TimeSeries), so the adapter will need to handle the conversion from TimeSeries to pd.Series and vice versa.

from darts import TimeSeries

Describe alternatives you've considered
I tried creating the adapter outside of sktime. It trains OK, but the prediction does not work. Not sure what the issue is. Can someone help out please?

Notebook with DARTS adapter

@aiwalter
Copy link
Contributor

Which model do you want to use that are not in sktime?

@ngupta23
Copy link
Contributor Author

ngupta23 commented Nov 18, 2021

Hi @aiwalter There are many that are not there in sktime right now. Is there a technical challenge with adding an adapter for DARTS? I am ok doing it in pycaret if it can not be included in sktime, just need to understand why the predict does not work. Thanks!

https://github.com/unit8co/darts/tree/master/examples

image

@TonyBagnall TonyBagnall added the module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting label Nov 19, 2021
@ngupta23
Copy link
Contributor Author

Also, I will be happy to add this to sktime directly, if someone can guide me with the prediction problem in the code gist above. Thanks!

@fkiraly
Copy link
Collaborator

fkiraly commented Nov 20, 2021

@ngupta23, the main point is that you

  • need to set the line "y_inner_mtype": "pd.Series" to the type that you are using internally. It says pd.Series now, but you probably want pd.DataFrame or np.ndarray?
  • Whatever you pick, that's what will be given to the input of _fit, and that's what you need to return in _predict. You currently return a numpy array. It breaks since you are not returning a pd.Series.
  • as said, you probably want this to be compatible with multivariate input/output, so you probably want to move to pd.DataFrame input and output? Alternatively, if you set y_inner_mtype to np.ndarray, you can use 2D numpy arrays (but you need to make sure the return of _predict is also in this format).

There should probably be a more descriptive warning for implementers of methods here.
Would be keen to hear: did you use the extension template? Was it not clear enough? Where do you think more explanation would be useful?

@fkiraly
Copy link
Collaborator

fkiraly commented Nov 20, 2021

Perhaps more concretely, what I'd suggest:

  • set "y_inner_mtype": "pd.DataFrame"
  • in _fit, ensure you assume y is data frame, and convert it to the darts TimeSeries, using the class method from_dataframe (of TimeSeries)
  • in _predict, convert the return to a pd.DataFrame, using the pd_dataframe method of TimeSeries

@ngupta23
Copy link
Contributor Author

Hi @fkiraly , Thank you for the suggestions. It works after I make the changes per your suggestion. Working Gist here

One followup question. Deep learning models can take additional arguments in fit for example

# https://github.com/unit8co/darts/blob/master/examples/08-NBEATS-examples.ipynb
model_nbeats.fit(train, val_series=val, verbose=True)

# https://github.com/unit8co/darts/blob/master/examples/05-RNN-examples.ipynb
model_rnn.fit(
    train_transformed, 
    future_covariates=covariates, 
    val_series=val_transformed, 
    val_future_covariates=covariates, 
    verbose=True
)

Would it be possible for sktime fit to accept kwargs?

@fkiraly
Copy link
Collaborator

fkiraly commented Nov 23, 2021

Would it be possible for sktime fit to accept kwargs?

Unfortunately no, that would require a major API change and would "break" the unified interface pattern that half the world relies on... it's really a strong requirement that you can switch out different algorithms and the usage is absolutely identical as long as it is the same kind of algorithm (e.g., forecaster). Like a power plug.

Lack of a unified interface like this is one of the major design issues with DARTS currently, it's quite inhomogenous...

However, in interfacing from sktime there is a simple way to achieve interface homogeneity:

  • any hyper-parameters should move to the constructor
  • any change in data representation you move as logic into _fit
  • conversions to sktime supported data representations can also be dealt with by y_inner_mtype, X_inner_mtype instead

In the example of nbeats: I believe it expects you to split your series into train and val_series before you fit.
That should really happen as part of the algorithm, i.e., in _fit of sktime you would take y and split it into train and val. That might require some specification how you split, i.e., a train_val_cutoff (a relative time stamp or, better, percentage perhaps?), which you can introduce as a parameter in the constructor.
verbose also becomes a parameter in the constructor.

In the rnn model, you can do the same: y is split into train_transformed and val_series, and sktime's X is split into future_covariates and val_future_covariates (I think)? For control where you split, you may have to introduce a train_val_cutoff again. verbose becomes a constructor argument.

@fkiraly
Copy link
Collaborator

fkiraly commented Nov 23, 2021

additionally, since these are neural networks, you may think about extra methods or attributes that users can query for summaries, such as learning curves or validation losses.

@fkiraly
Copy link
Collaborator

fkiraly commented Nov 27, 2021

@ngupta23, how is it going? Let me know if the neural networks give you trouble, happy to have a look.

@ngupta23
Copy link
Contributor Author

Hi @fkiraly , Thanks for the feedback. I have not had a chance to evaluate this further. I think some collaborative effort here between sktime and pycaret would be good. Would you be open to adding this adapter in sktime directly? I am not sure how much work is going on with respect to sktime-dl (@mloning ?), but adding this adapter would be a good idea in the interim.

I would be happy to do the work on this and contribute this adapter to sktime (with guidance from you and others). Please let me know. Thanks!

@mloning
Copy link
Contributor

mloning commented Dec 3, 2021

Hey, yes, adding an adapter sounds like a good idea. One complication is to avoid adding a dependency on the deep-learning frameworks. But it seems like darts is separate out different sets of dependencies already.

@ilkersigirci
Copy link

ilkersigirci commented Mar 22, 2022

Any progress about this issue? It would be awesome to have some deep learning models of darts while waiting sktime-dl integration.

@ngupta23
Copy link
Contributor Author

@ilkersigirci I have not done any work on this beyond my initial investigation (notebook in #1624 (comment)). If anyone is available to pick this up, please feel free to do so. Thanks!

@ilkersigirci
Copy link

@ngupta23 Thanks, I might look into it since I am trying to use sktime with deep learning models

@fkiraly
Copy link
Collaborator

fkiraly commented Mar 24, 2022

Excellent, thanks, @ilkersigirci!

Here's the how-to of implementing new estimators.
(this should include that last section since you are adding directly to sktime)
https://www.sktime.org/en/latest/developer_guide/add_estimators.html

@fkiraly fkiraly added the interfacing algorithms Interfacing existing algorithms/estimators from third party packages label Mar 25, 2022
@MBristle
Copy link
Contributor

MBristle commented Jul 26, 2023

@ngupta23 I implemented a custom Adapter for Nbeats with Darts as I needed one for the replication of an experiment. It should be easy to change it to any other darts model, and it can also be generalized. I can have a look into contributing it properly to sktime after September if it has not been done until then.

@ngupta23
Copy link
Contributor Author

Sure, that would be great! Thanks

@fkiraly
Copy link
Collaborator

fkiraly commented Jul 26, 2023

NICE! We would much appreciate a PR, @MBristle!

@fkiraly
Copy link
Collaborator

fkiraly commented Jul 26, 2023

You could make a draft PR with your raw code, if someone else wants to pick up the "generalization" work? @yarnabrina in particular has written or refactored the adapters for statsmodels and statsforecast and might be interested to see this, FYI.
(the crediting to you would not be impacted)

@fnhirwa
Copy link
Contributor

fnhirwa commented May 15, 2024

I'll start to work on this issue as per the conversation we had here #6381 (comment)

@fnhirwa fnhirwa linked a pull request May 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interfacing algorithms Interfacing existing algorithms/estimators from third party packages module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

8 participants