You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am doing a multivariate(metereological timeseries)--->univariate(solar radaition target timeseries) prediction using DeepVAREstimator. My data sset spans over 3 year period(2021-2023). Now what I want is to get a forecast of solarariadtion for whole year of 2023 as a function of input metereological parameters. But even after setting the test dataset to be of 2023 year period, what the model does after training is predict the 24 hr forecast as a function of (8760-24)hr of test data as input. What I want is to a forecast for whole year? How can I achive that? I will attach the code snippet:
import pandas as pd
from gluonts.model.deepar import DeepAREstimator
from gluonts.trainer import Trainer
from gluonts.dataset.common import ListDataset
from gluonts.evaluation import make_evaluation_predictions
from gluonts.evaluation import Evaluator
import numpy as np
import matplotlib.pyplot as plt
# Load the dataset
data_path = "C:/Users/user/Weather_2021_2024v1.csv"
df = pd.read_csv(data_path)
df['Hour'] = pd.to_datetime(df['Hour']) # Convert 'Hour' column to datetime
# Define train and test sets
train_df = df[df['Hour'] < '2023']
test_df = df[df['Hour'] >= '2023']
# Define feature columns and target column
feature_cols = ['T(C)', 'Pr(mm)', 'WS(m/s)', 'WD', 'RH(%)', 'SS(hr)', 'SN(cm)', 'TC']
target_col = 'SR(kW/m2)'
# Convert dataframes to ListDataset
training_data = ListDataset(
[{"start": train_df['Hour'].min(), "target": train_df[target_col].values, "feat_dynamic_real": [train_df[feature_cols].values]}],
freq="1H"
)
test_data = ListDataset(
[{"start": test_df['Hour'].min(), "target": test_df[target_col].values, "feat_dynamic_real": [test_df[feature_cols].values]}],
freq="1H"
)
# Define the DeepAR estimator
estimator = DeepAREstimator(
freq="1H", # Assuming hourly frequency
prediction_length=8760, # Forecast horizon for the entire year of 2023
trainer=Trainer(epochs=10)
)
# Train the DeepAR model
predictor = estimator.train(training_data=training_data)
# Make forecasts for the entire year of 2023
forecast_it, ts_it = make_evaluation_predictions(
dataset=test_data, # Test dataset
predictor=predictor, # Trained predictor
num_samples=100, # Number of sample paths to draw while making predictions
)
# Extract forecasts and actual values
forecasts = list(forecast_it)
targets = list(ts_it)
# Initialize an evaluator
evaluator = Evaluator(quantiles=[0.5]) # Median quantile for point forecasts
# Compute metrics
agg_metrics, item_metrics = evaluator(targets, forecasts)
# Extract MAE from aggregated metrics
mae = agg_metrics["MAE"]
print("Mean Absolute Error (MAE):", abs_error)
# Plot forecast with prediction intervals
fig, ax = plt.subplots(1, 1, figsize=(10, 7))
for forecast_entry in forecasts:
forecast_entry.plot(color='g', prediction_intervals=(50.0, 90.0))
plt.grid(which="both")
plt.legend(["observations", "median prediction", "50% prediction interval", "90% prediction interval"], loc="upper left")
plt.show()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I am doing a multivariate(metereological timeseries)--->univariate(solar radaition target timeseries) prediction using DeepVAREstimator. My data sset spans over 3 year period(2021-2023). Now what I want is to get a forecast of solarariadtion for whole year of 2023 as a function of input metereological parameters. But even after setting the test dataset to be of 2023 year period, what the model does after training is predict the 24 hr forecast as a function of (8760-24)hr of test data as input. What I want is to a forecast for whole year? How can I achive that? I will attach the code snippet:
Thank you for your time.
Beta Was this translation helpful? Give feedback.
All reactions