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

Plot the curve for learning of an lgbm forecaster #224

Closed
DariusMargineanNicolae opened this issue Aug 24, 2022 · 4 comments
Closed

Plot the curve for learning of an lgbm forecaster #224

DariusMargineanNicolae opened this issue Aug 24, 2022 · 4 comments
Labels
question Further information is requested

Comments

@DariusMargineanNicolae
Copy link

DariusMargineanNicolae commented Aug 24, 2022

Hello! I am new to sk.forecast.ForecasterAutoReg. I tried to implement an LGBM model, and make the predictions on 4 steps ahead. I did manage to visualize the predictions, but I struggle how to plot the curve for the learning part to see how the model performs on the learning dataframe. Below is the code I have used.

`forecaster = ForecasterAutoreg(
regressor=LGBMRegressor(**lgbm_trial_params), lags=[1,2,3,4]
)

cols = [col for col in df.columns if col not in ['date', "Qty"]]
exog = df[cols]

forecaster.fit(y=df["Qty"][:-4], exog=exog[:-4])
predictions = forecaster.predict(steps = 4,exog = exog[:-4])`

Qty represents the target variable I want to predict and my dataframe is structured on weekly data with month, week_num and last_month_average as features.

Here is a printscreen of the structure of my dataframe:

image

I did not manage to find something useful searching the internet so any help will be much apreciatted. Thanks!

@JoaquinAmatRodrigo
Copy link
Owner

Hi @DariusMargineanNicolae
I am not sure if I undertood the issue. Do you mean you would like calculate predictions on the training data set?

@DariusMargineanNicolae
Copy link
Author

Hi @DariusMargineanNicolae

I am not sure if I undertood the issue. Do you mean you would like calculate predictions on the training data set?

Hello @JoaquinAmatRodrigo . Thanks for your reply. Basically yes, I want to view the predictions on the training data set also and then plot them along with the actual data to see how the model behave during training.

@JoaquinAmatRodrigo
Copy link
Owner

The following steps should work:

  1. Train the forecaster as you are doing.
  2. Set arguments initial_train_size=None and refit=False to perform backtesting using the already trained forecaster.

Two observations:

  • It is important that, during the backtesting you use the same steps as in the training, other your backtesting would be too optimistc.
  • The first 4 observations are not predicted since they are needed to create the lags used as predictors.

You can find an example here: https://joaquinamatrodrigo.github.io/skforecast/0.4.3/notebooks/backtesting.html#predict-using-backtesting_forecaster

@JoaquinAmatRodrigo JoaquinAmatRodrigo added the question Further information is requested label Aug 25, 2022
@DariusMargineanNicolae
Copy link
Author

DariusMargineanNicolae commented Aug 25, 2022

It worked. Thanks a lot for your time! I will close the issue now.

The following steps should work:

  1. Train the forecaster as you are doing.
  2. Set arguments initial_train_size=None and refit=False to perform backtesting using the already trained forecaster.

Two observations:

  • It is important that, during the backtesting you use the same steps as in the training, other your backtesting would be too optimistc.
  • The first 4 observations are not predicted since they are needed to create the lags used as predictors.

You can find an example here: https://joaquinamatrodrigo.github.io/skforecast/0.4.3/notebooks/backtesting.html#predict-using-backtesting_forecaster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants