Comments (3)
Thanks for this excellent question! It is absolutely worth answering in the tutorial.
Because the TFT requires specifying covariates in the future, you need to construct a dataframe that has a time index for those values.
Taking the example from the demand forecasting tutorial. We assume that the variables known in the future stay the same in the next 6 months (particularly prices):
# select last 24 months from data (max_encoder_length is 24)
encoder_data = data[lambda x: x.time_idx > x.time_idx.max() - max_encoder_length]
# select last known data point and create decoder data from it by repeating it and incrementing the month
last_data = data[lambda x: x.time_idx == x.time_idx.max()]
decoder_data = pd.concat(
[last_data.assign(date=lambda x: x.date + pd.offsets.MonthBegin(i)) for i in range(1, max_prediction_length + 1)],
ignore_index=True,
)
# add time index consistent with "data"
decoder_data["time_idx"] = decoder_data["date"].dt.year * 12 + decoder_data["date"].dt.month
decoder_data["time_idx"] += encoder_data["time_idx"].max() + 1 - decoder_data["time_idx"].min()
# adjust additional time feature(s)
decoder_data["month"] = decoder_data.date.dt.month.astype(str).astype("category") # categories have be strings
# combine encoder and decoder data
new_prediction_data = pd.concat([encoder_data, decoder_data], ignore_index=True)
And now to predict and visualize some examples, simply run:
new_raw_predictions, new_x = best_tft.predict(new_prediction_data, mode="raw",return_x=True)
for idx in range(10): # plot 10 examples
best_tft.plot_prediction(new_x, new_raw_predictions, idx=idx, show_future_observed=False);
from pytorch-forecasting.
Wow, those updates you just pushed are amazing, @jdb78! Thank you so much! This is incredibly helpful!
I'll try to implement them on my own dataset tomorrow morning. Thanks so much for your quick and helpful reply! I really appreciate it!
from pytorch-forecasting.
Just tested the code you posted and so helpfully pushed in the v0.4.1 release on my own data! Worked great! Thanks so much, @jdb78!
Now if only I had more time series data for my TFT to train on! 🤣
from pytorch-forecasting.
Related Issues (20)
- Support for state of the art TSMixer model HOT 1
- Why does NHiTS need the target variable specified in the time_varying_unknown_reals attribute? HOT 1
- Odd values for VAL_MAE & VAL_RMSE for TFT
- RuntimeError on variable Validation Batch Sizes in TemporalFusionTransformer Tutorial HOT 6
- Symbol not found: __ZN3c106detail19maybe_wrap_dim_slowIxEET_S2_S2_b
- How to solve: OSError: [WinError 127] 找不到指定的程序。
- How to set up a training process that can take forecasts from other models
- Issue with TFT.forward() method
- Interpreting DeepAR.predict() HOT 1
- Data leakage problem HOT 2
- Bug of SMAPE when excuting tutorial
- RMSE defined as MSE HOT 1
- rubbish
- Val_loss Calculation with Multiple Validation Sets in Sliding Window Technique and Early Stopping
- How does one initialise a network without `from_dataset`?
- DeepAR with NormalDistributionLoss error on 0 values in target
- How to split the data into train, test, and validation HOT 1
- multi horizon timeseries time_idx
- Issue with installation HOT 1
- AssertionError: filters should not remove entries all entries - check encoder/decoder lengths and lags
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch-forecasting.