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

Question: grid search for lags? #970

Closed
zora-no opened this issue May 23, 2022 · 4 comments
Closed

Question: grid search for lags? #970

zora-no opened this issue May 23, 2022 · 4 comments

Comments

@zora-no
Copy link

zora-no commented May 23, 2022

gridsearch() can be used to find the best model-specific hyperparameters. Regarding the lags, I only found the option to define a specific number of lags when initializing the model. Is there also a way to do a gridsearch of the best lags (of target series, past & future cov)?

@dennisbader
Copy link
Collaborator

Yes, you can use Darts' gridsearch to find the best lags.
For that you have a few options (as the lags arguments can either be int or list)

If you use int as lags:
model.gridsearch(paramaters={..., "lags": [-1,-2,-3, ...]})

If you use list as lags:
model.gridsearch(paramaters={..., "lags": [[-1,-2,], [-1, -2, -3], ...]})

@zora-no
Copy link
Author

zora-no commented May 24, 2022

Awesome, thank you!

I'm also trying to find a way to extract the feature importance, but haven't found a function to do that. Can you help?
I've tried doing it manually with the code below, but I feel like there probably exists a (better) function in darts that I just can't find?

X has the following structure:
lags_target | lags_past_covariates | lags_future_covariates
Where each lags_X has the following structure (lags_X=[-2,-1] and X has 2 components):
lag_-2_comp_1_X | lag_-2_comp_2_X | lag_-1_comp_1_X | lag_-1_comp_2_X

feature_names = [["target_lag_" + str(lag) for lag in model.lags["target"]]]
if "past" in model.lags.keys():
    feature_names.append(["past_" + str(var) + "_lag" + str(lag) for lag in model.lags["past"] for var in model.past_covariate_series.components.values])
if "future" in model.lags.keys():
    feature_names.append(["future_" + str(var) + "_lag" + str(lag) for lag in model.lags["future"] for var in model.future_covariate_series.components.values ])

feature_names = [val for sublist in feature_names for val in sublist]

feature_importances = model.model.feature_importances_
pd.DataFrame(data = {"importance": feature_importances}, index=feature_names)

And what would the structure be like if I had a multivariate forecast, i.e. multiple targets?

@hrzn
Copy link
Contributor

hrzn commented May 26, 2022

There's currently no feature in Darts to return features importance - we are however working on it here.

I'm closing this issue as the initial issue has been resolved.

1 similar comment
@hrzn
Copy link
Contributor

hrzn commented May 26, 2022

There's currently no feature in Darts to return features importance - we are however working on it here.

I'm closing this issue as the initial issue has been resolved.

@hrzn hrzn closed this as completed May 26, 2022
@hrzn hrzn closed this as completed May 26, 2022
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

No branches or pull requests

3 participants