Get startedGet started for free

Don't Throw Out That Winter Coat Yet

Finally, you will forecast the temperature over the next 30 years using an ARMA(1,1) model, including confidence bands around that estimate. Keep in mind that the estimate of the drift will have a much bigger impact on long range forecasts than the ARMA parameters.

Earlier, you determined that the temperature data follows a random walk and you looked at first differencing the data. In this exercise, you will use the ARIMA module on the temperature data (before differencing), which is identical to using the ARMA module on changes in temperature, followed by taking cumulative sums of these changes to get the temperature forecast.

Because temperatures are trending up over time, you will also need to add a trend component when you define the ARIMA model. In the exercise, you'll use a linear trend with time by setting the argument trend='t'. You can also try other trend models to see how the forecasts change. For example, for a quadratic trend \(\small a+ bt + ct^2\), set trend=[0,1,1], to include both a linear term, \(\small bt\), and quadratic term, \(\small ct^2\), in the model.

The data is preloaded in a DataFrame called temp_NY.

This exercise is part of the course

Time Series Analysis in Python

View Course

Exercise instructions

  • Create an instance of the ARIMA class called mod for an integrated ARMA(1,1) model, or ARIMA(1,1,1) model
    • The d in order(p,d,q) is one, since we first differenced once
    • Fit mod using the .fit() method and call the results res
  • Forecast the series using the plot_predict() method on res
    • Choose the start date as 1872 and the end date as 2046

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import the ARIMA module from statsmodels
from statsmodels.tsa.arima.model import ARIMA
from statsmodels.graphics.tsaplots import plot_predict

# Forecast temperatures using an ARIMA(1,1,1) model
mod = ARIMA(temp_NY, trend='t', order=(1,1,1))
___ = ___.fit()

# Plot the original series and the forecasted series
fig, ax = plt.subplots()
temp_NY.plot(ax=ax)
plot_predict(___, start='1872', end='2046', ax=ax)
plt.show()
Edit and Run Code