NeuralProphet 中的多元预测

问题描述 投票:0回答:1

我正在尝试建立一个全局模型来同时预测两个时间序列。下面的代码运行没有错误。但预测数据帧的所有 NaN 都对应于两个 ID 之一(即有两个时间序列)。 yhat 值也全部为 NaN。我是不是做错了什么或者遗漏了什么?

m = NeuralProphet(
    yearly_seasonality=True,
    weekly_seasonality=True,
    daily_seasonality=False,  
    quantiles=quantiles,
    n_lags=60,
    epochs=100,
    n_forecasts=30,
    loss_func='Huber',
)
m.set_plotting_backend('plotly')
m.highlight_nth_step_ahead_of_each_forecast(step_number=10)

metrics = m.fit(train_df[['ds', 'y', 'ID']])

df_future = m.make_future_dataframe(
    train_df, 
    n_historic_predictions=True,   
)

forecast = m.predict(df_future)
python machine-learning time-series facebook-prophet
1个回答
0
投票

您的代码缺少一些处理多个时间序列的基本配置。

NeuralProphet
确实支持多变量预测,但您需要明确指定每个系列的目标列。

尝试下面的代码来正确处理 NeuralProphet 的多元预测

import NeuralProphet
import pandas as pd

# Assuming train_df contains ds (datetime), y (target variable), and ID columns for each time series

m = NeuralProphet(
    yearly_seasonality=True,
    weekly_seasonality=True,
    daily_seasonality=False,  
    quantiles=quantiles,
    n_lags=60,
    epochs=100,
    n_forecasts=30,
    loss_func='Huber',
    num_hidden_layers=3,  # Add this line to specify the number of hidden layers (optional)
)

# You need to specify the target_columns for multivariate forecasting
target_columns = ['y1', 'y2']  # Assuming 'y1' and 'y2' are the target columns for your two time series

metrics = m.fit(train_df, 
                freq='D',  # Assuming daily frequency
                target_columns=target_columns)

# Create a future dataframe
df_future = m.make_future_dataframe(train_df, 
                                    periods=n_forecasts, 
                                    n_historic_predictions=True,   
                                    target_columns=target_columns)

# Make predictions
forecast = m.predict(df_future)

y1
y2
替换为
target_columns
列表中每个时间序列的目标变量的实际列名称

© www.soinside.com 2019 - 2024. All rights reserved.