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
Hi - I'm an R user experimenting with running gluonts in a Python code chunk sandwiched between R code to prepare the input and ggplot() the output. The following, using the toy example, seems to work. I'm wondering though if gluonts provides, or could provide, an extractor function in Python to put the actuals and forecast into a pandas dataframe(s)? It could replace my attempted extraction (using R) from the gluons objects.
PS - I'm aware of issue 3020 causing the plotting problem on Apple silicon. The example below was run on an M2 machine.
```{python}
import pandas as pd
import matplotlib.pyplot as plt
from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.split import split
from gluonts.torch import DeepAREstimator
# Load data from a CSV file into a PandasDataset
df = pd.read_csv(
"https://raw.githubusercontent.com/AileenNielsen/"
"TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv",
index_col=0,
parse_dates=True
)
# Use the data read from R instead
df2 = r.df2
df2['Month'] = pd.to_datetime(df2['Month'])
df2 = df2.set_index("Month")
dataset = PandasDataset(df2, target="#Passengers")
# Split the data for training and testing
training_data, test_gen = split(dataset, offset=-36)
test_data = test_gen.generate_instances(prediction_length=12, windows=3)
# Train the model and make predictions
model = DeepAREstimator(
prediction_length=12, freq="M", trainer_kwargs={"max_epochs": 5}
).train(training_data)
forecasts = list(model.predict(test_data.input))
# Plot predictions
plt.plot(df2["1954":], color="black")
for forecast in forecasts:
forecast.plot()
plt.legend(["True values"], loc="upper left", fontsize="xx-large")
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'm an R user experimenting with running gluonts in a Python code chunk sandwiched between R code to prepare the input and
ggplot()
the output. The following, using the toy example, seems to work. I'm wondering though if gluonts provides, or could provide, an extractor function in Python to put the actuals and forecast into a pandas dataframe(s)? It could replace my attempted extraction (using R) from the gluons objects.PS - I'm aware of issue 3020 causing the plotting problem on Apple silicon. The example below was run on an M2 machine.
Beta Was this translation helpful? Give feedback.
All reactions