MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to find optimal paramters for ARIMA model?

# How to find optimal paramters for ARIMA model?

This recipe helps you find optimal paramters for ARIMA model

The ARIMA model for time series analysis and forecasting can be tricky to configure. We can automate the process of evaluating a large number of hyperparameters for the ARIMA model by using a grid search procedure.

So this recipe is a short example on how to find optimal paramters for ARIMA model. Let's get started.

```
import warnings
import numpy as np
import pandas as pd
from statsmodels.tsa.arima_model import ARIMA
from sklearn.metrics import mean_squared_error
```

Let's pause and look at these imports. Numpy, pandas and warnings are general ones. Here, statsmodels.tsa.arima_model will help in building our model. mean_squared_error will be used for calculating MSE score.

```
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date']).set_index('date')
```

Here, we have used one time series data from github. Also, we have set our index to date.

Now our dataset is ready.

```
train_data = df[1:len(df)-12]
test_data = df[len(df)-12:]
```

Here, we have simply broken our dataset to two parts as test and train.

```
p_values = [0, 1]
d_values = range(0, 2)
q_values = range(0, 2)
```

Here, we have defined p,d and q for hyperparameter testing.

```
for p in p_values:
for d in d_values:
for q in q_values:
order = (p,d,q)
warnings.filterwarnings("ignore")
model = ARIMA(train_data.value, order=order).fit()
predictions = model.predict(start=len(train_data), end=len(train_data) + len(test_data)-1)
error = mean_squared_error(test_data, predictions)
print('ARIMA%s MSE=%.3f' % (order,error))
```

With each loop, we choose one parameter, fit the model and calculate the MSE over predictions. Later we choose the best model by looking at lowest MSE score.

Once we run the above code snippet, we will see:

Srcoll down the ipython file to visualize the results.

Best model to choose is (1,0,1).

In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset using Keras in Python.

In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.