# Forecasting with MA Model

As you did with AR models, you will use MA models to forecast in-sample and out-of-sample data using the `plot_predict()`

function in statsmodels.

For the simulated series `simulated_data_1`

with \(\small \theta=-0.9\), you will plot in-sample and out-of-sample forecasts. One big difference you will see between out-of-sample forecasts with an MA(1) model and an AR(1) model is that the MA(1) forecasts more than one period in the future are simply the mean of the sample.

This is a part of the course

## “Time Series Analysis in Python”

### Exercise instructions

- Import the class
`ARIMA`

and also import the function`plot_predict`

- Create an instance of the
`ARIMA`

class called`mod`

using the simulated data`simulated_data_1`

and the (p,d,q) order of the model (in this case, for an MA(1)),`order=(0,0,1)`

- Fit the model
`mod`

using the method`.fit()`

and save it in a results object called`res`

- Plot the in-sample data starting with data point 950
- Plot out-of-sample forecasts of the data and confidence intervals using the
`plot_predict()`

function, starting with data point 950 and ending the forecast at point 1010

### Hands-on interactive exercise

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

```
# Import the ARIMA and plot_predict from statsmodels
from statsmodels.tsa.arima.model import ARIMA
from statsmodels.graphics.tsaplots import plot_predict
# Forecast the first MA(1) model
mod = ARIMA(___, order=___)
res = mod.fit()
# Plot the data and the forecast
fig, ax = plt.subplots()
simulated_data_1.loc[950:].plot(ax=ax)
plot_predict(res, start=___, end=___, ax=ax)
plt.show()
```

This exercise is part of the course

## Time Series Analysis in Python

In this four-hour course, you’ll learn the basics of analyzing time series data in Python.

In this chapter you'll learn about another kind of model, the moving average, or MA, model. You will also see how to combine AR and MA models into a powerful ARMA model.

Exercise 1: Describe ModelExercise 2: Simulate MA(1) Time SeriesExercise 3: Compute the ACF for Several MA Time SeriesExercise 4: Match ACF with MA ModelExercise 5: Estimation and Forecasting an MA ModelExercise 6: Estimating an MA ModelExercise 7: Forecasting with MA ModelExercise 8: ARMA modelsExercise 9: High Frequency Stock PricesExercise 10: More Data Cleaning: Missing DataExercise 11: Applying an MA ModelExercise 12: Equivalence of AR(1) and MA(infinity)### What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.