[Python] Missing Covariates in Darts TimeSeries

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    I'm putting together a TFT model in the darts library in python and I keep getting the same error. Here's roughly what I have:

    import numpy as np
    import pandas as pd
    from datetime import timedelta
    from tqdm import tqdm_notebook as tqdm

    import matplotlib.pyplot as plt

    from darts import TimeSeries, concatenate
    from darts.dataprocessing.transformers import Scaler
    from darts.models import TFTModel
    from darts.metrics import mape
    from darts.utils.statistics import check_seasonality, plot_acf
    from darts.utils.timeseries_generation import datetime_attribute_timeseries
    from darts.utils.likelihood_models import QuantileRegression

    f_columns = ['Year', 'Month', 'Week', 'DayOfMonth', 'DayOfWeek', 'WeekOfMonth', 'Season', 'Holidays', 'Weekend']
    QUANTILES = [0.01, 0.05, 0.1, 0.2, 0.25, 0.5, 0.75, 0.8, 0.9, 0.95, 0.99]
    ICL = 60
    OCL = 15

    time_series = TimeSeries.from_dataframe(data, time_col='CreateDate', value_cols=f_columns + ['Count'], freq = 'D')
    train, test = time_series.split_after(SPLIT)

    scaler = Scaler()
    train_data_scaled = scaler.fit_transform(train)
    test_data_scaled = scaler.transform(test)

    model = TFTModel(
    input_chunk_length=ICL,
    output_chunk_length=OCL,
    hidden_size=16,
    lstm_layers=2,
    num_attention_heads=1,
    dropout=0.1,
    batch_size=16,
    n_epochs=2,
    likelihood = QuantileRegression(quantiles=QUANTILES),
    )

    model.fit(series = train_data_scaled['Count'],
    past_covariates = train_data_scaled[f_columns],
    future_covariates = test_data_scaled[f_columns],
    verbose=True
    )

    preds = model.predict(test_data_scaled)
    preds = scaler.inverse_transform(preds)


    When I run this I consistently get the error

    Missing covariates; could not find past covariates in index value range: 2020-08-22 00:00:00 - 2020-10-20 00:00:00


    However any time I change the input or output chunk lengths these dates change accordingly. Whenever I look at the data though, there is valid data in whatever time window it claims there are no past covariates. I'm really unsure what the problem is here. Let me know how I can amend this issue and get my model working.

    This was also a problem someone posted on Github but they didn't post a definitive answer and the OP's explanation of how they resolved the issue wasn't detailed enough.

    Continue reading...

Compartilhe esta Página