unit8co / darts

A python library for user-friendly forecasting and anomaly detection on time series.
https://unit8co.github.io/darts/
Apache License 2.0
7.91k stars 858 forks source link

[BUG] Neural network models using only past covariates are predicting NaN values. #2100

Closed Erik-02 closed 9 months ago

Erik-02 commented 9 months ago

Describe the bug I have a dataset, created the target, past covariates and future covariate. However, when using neural network models that only use past covariates such as N-hits, N-beats, TCN... are only predicting Nan values when I specify past covariates during .fit()

To Reproduce Dataset has 15k rows, it has already been converted to timeseries using, TimeSeries.from_dataframe(), and has already been scaled. target = series['count'][:-168] past_cov = series['MA', 'EWMA'][:-168] future_cov = series['year', 'temperature']

-What doe not work: (this case is for all of the models using past covariates, nhits, nbeats, tcn...) nhits_model = NHiTSModel( model_name='NHiTS', input_chunk_length=168, output_chunk_length=168, n_epochs=1, dropout=0.2, random_state=123,) nhits_model.fit(target, past_covariates=past_cov) nhits_predictions = nhits_model.predict(168) OR nhits_predictions = nhits_model.predict(168, past_covariates=past_cov)

Even during the fit() process, the training loss says : training_loss=nan.0

This produces Nan values as the predictions, and no errors.

During this fit() process the loss is decreasing.

Expected behavior I expect the model to be able to predict actual values when using past_covariates=past_cov and not to just predict Nan.

System (please complete the following information):

Erik-02 commented 9 months ago

Ok, I found the problem. It seems that when the training loss states nan.0 , it actually means that there is nan values in the data that you are passing to it, whether it is the target or any covariates. I just overlooked the fact that my past covariates had nan values in them. After removing these nan values and trying again with the past covariates variable, it trained fine and did not produce nan values anymore.