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

Predict for future date without target value #597

Closed
ManikandanThangavelu opened this issue Feb 5, 2020 · 18 comments
Closed

Predict for future date without target value #597

ManikandanThangavelu opened this issue Feb 5, 2020 · 18 comments
Labels
question Further information is requested

Comments

@ManikandanThangavelu
Copy link

I need to predict for future dates with some dates missing in between the training date and the date I wan to predict. So I wont be having any target values.
When I use Nan for target series, My forecast is mostly on 0.

@ManikandanThangavelu ManikandanThangavelu added the question Further information is requested label Feb 5, 2020
@ManikandanThangavelu ManikandanThangavelu changed the title Predict for future data without target value Predict for future date without target value Feb 5, 2020
@mbohlkeschneider
Copy link
Contributor

Hi @ManikandanThangavelu,

thank you for using GluonTS.

Using NaNs would be our recommended way of handling this. Another option would be to manually impute the missing values yourself (using time series means, for example).

Please note that "cold-start' forecasts (not having any target values in the context before prediction), will be generally of lower quality than forecasts that have context data.

Hope that helps!

@ManikandanThangavelu
Copy link
Author

Hi @mbohlkeschneider

Thanks for your answer.

The predictions are not good when I use Nan and my question would be why should we provide target values if the model is already been trained in the historical data. Won't sending the dates should be enough for the model to predict. Like we do in other algorithms like Prophet.

@mbohlkeschneider
Copy link
Contributor

Hi @ManikandanThangavelu,

It depends on the algorithm, of course. DeepAR uses the context target values to update the hidden state and compute the distribution parameters with the learned weights (that are estimated during training). You can find more information in the DeepAR paper.

@ManikandanThangavelu
Copy link
Author

HI @mbohlkeschneider

That explains it. Can you please suggest an algorithm in GluonTs that won't need a target value while predicting and some examples if possible.

@mbohlkeschneider
Copy link
Contributor

Hi @ManikandanThangavelu,

all of our models use the target values, if I recall correctly.

@ManikandanThangavelu
Copy link
Author

Hi @mbohlkeschneider,

Any model that will perform well even if the target value is Nan?.

@mbohlkeschneider
Copy link
Contributor

That is hard to say in general terms. I would suggest to experiment if any of the models works for you.

Best,
Michael

@ManikandanThangavelu
Copy link
Author

Sure... Thank you.
Closing the issue

@pratikgehlott
Copy link

@ManikandanThangavelu it seems that the DeepAR estimator is not taking NaN values in the training set? what can you suggest?

@amarallr
Copy link

I have the same doubt.

How to forecast the target values with gluonts DeepAR?

I have a time series from 1995-01-01 to 2021-10-01. Frequency=monthly.

How to forecast values for the future (next 3 months): 2021-11-01 to 2022-01-01?

Note that I dont have the target values for 2021-11-01, 2021-12-01 and 2022-01-01.

Many thanks.

@dai-ichiro
Copy link

Are you touching on ”make_evaluation_predictions"?

You can use "predict".

@amarallr
Copy link

Actually, I would like to know the target values for "2021-11-01", "2021-12-01" and "2022-01-01". I have a time series from "1995-01-01" to "2021-10-01". Monthly frequency. How to forecast values for the next 3 months: "2021-11-01", "2021-12-01" and "2022-01-01"? Here is the code:

from gluonts.model.deepar import DeepAREstimator
from gluonts.mx import Trainer 
import numpy as np
import mxnet as mx

np.random.seed(7)
mx.random.seed(7)

estimator = DeepAREstimator(
    prediction_length=12
    , context_length=120
    , freq='M'
    , trainer=Trainer(        
        epochs=5
        , learning_rate=1e-03
        , num_batches_per_epoch=50))

predictor = estimator.train(training_data=df_train)

# Forecasting
predictions = predictor.predict(df_test)
predictions = list(predictions)[0]
predictions = predictions.quantile(0.5)

print(predictions)
[163842.34  152805.08  161326.3   176823.97  127003.79  126937.78
 139575.2   117121.67  115754.67  139211.28  122623.586 120102.65 ]

As I understood, the predictions values are not for "2021-11-01", "2021-12-01" and "2022-01-01". How do I know to wich months this values refer to? How to forecast values for the next 3 months: "2021-11-01", "2021-12-01" and "2022-01-01"?

Many thanks!

@dai-ichiro
Copy link

dai-ichiro commented Nov 11, 2021

You set prediction_length to 12 in DeepAREstimator, so you got 12 values.
First 3 values are those you want to get, I think.

Hope this helps.

@amarallr
Copy link

Take a look at this code. It comes from "Advanced Forecasting with Python".
https://github.com/Apress/advanced-forecasting-python/blob/main/Chapter%2020%20-%20Amazon's%20DeepAR.ipynb

It does not seem to forecast unknown future values, once it compares the last 28 values of test_ds (Listing 20-5. R2 score and prediction graph) with the predictions made over this same dataset test_ds (Listing 20-4. Prediction)

How do I forecast unknown future values?

Many thanks!

# Data source
# https://www.kaggle.com/c/recruit-restaurant-visitor-forecasting

# Listing 20-1. Importing the data
import pandas as pd
y = pd.read_csv('air_visit_data.csv.zip')
y = y.pivot(index='visit_date', columns='air_store_id')['visitors']
y = y.fillna(0)
y = pd.DataFrame(y.sum(axis=1))

y = y.reset_index(drop=False)
y.columns = ['date', 'y']


# Listing 20-2. Preparing the data format requered by the gluonts library
from gluonts.dataset.common import ListDataset
start = pd.Timestamp("01-01-2016", freq="H")
# train dataset: cut the last window of length "prediction_length", add "target" and "start" fields
train_ds = ListDataset([{'target': y.loc[:450,'y'], 'start': start}], freq='H')
# test dataset: use the whole dataset, add "target" and "start" fields
test_ds = ListDataset([{'target': y['y'], 'start': start}],freq='H')


# Listing 20-3. Fitting the default DeepAR model
from gluonts.model.deepar import DeepAREstimator
from gluonts.trainer import Trainer
import mxnet as mx
import numpy as np

np.random.seed(7)
mx.random.seed(7)

estimator = DeepAREstimator(
    prediction_length=28,
    context_length=100,
    freq=’H’,
    trainer=Trainer(ctx="gpu", # remove if running on windows
                    epochs=5,
                    learning_rate=1e-3,
                    num_batches_per_epoch=100
                   )
)

predictor = estimator.train(train_ds)



# Listing 20-4. Prediction
predictions = predictor.predict(test_ds)
predictions = list(predictions)[0]
predictions = predictions.quantile(0.5)



# Listing 20-5. R2 score and prediction graph
from sklearn.metrics import r2_score
print(r2_score( list(test_ds)[0]['target'][-28:], predictions))

import matplotlib.pyplot as plt
plt.plot(predictions)
plt.plot(list(test_ds)[0]['target'][-28:])
plt.legend(['predictions', 'actuals'])
plt.show()



@dai-ichiro
Copy link

Why don't you ask Apress?

I don't think this code is correct.

@junsyw
Copy link

junsyw commented Feb 8, 2022

Good afternoon all.
I have the same doubt, how to forecast future values ​​without having the targets?

@zhongxianmen2020
Copy link

ave the same doubt.

How to forecast the target values with gluonts DeepAR?

I have a time series from 1995-01-01 to 2021-10-01. Frequency=monthly.

How to forecast values for the future (next 3 months): 2021-11-01 to 2022-01-01?

Note that I dont have the target values for 2021-11-01, 2021-12-01 and 2022-01-01.

Many thanks.

I have to same issue to ask

@junsyw
Copy link

junsyw commented Apr 30, 2022

ave the same doubt.
How to forecast the target values with gluonts DeepAR?
I have a time series from 1995-01-01 to 2021-10-01. Frequency=monthly.
How to forecast values for the future (next 3 months): 2021-11-01 to 2022-01-01?
Note that I dont have the target values for 2021-11-01, 2021-12-01 and 2022-01-01.
Many thanks.

I have to same issue to ask

hello @zhongxianmen2020 , you must use the predcit function:

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

7 participants