Giter VIP home page Giter VIP logo

Comments (3)

jdb78 avatar jdb78 commented on May 19, 2024 1

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.

AlexMRuch avatar AlexMRuch commented on May 19, 2024

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.

AlexMRuch avatar AlexMRuch commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.