MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# Explain AR modelling of time series?

# Explain AR modelling of time series?

This recipe explains AR modelling of time series

Autoregression modeling is a modeling technique used for time series data that assumes linear continuation of the series so that previous values in the time series can be used to predict futures values. It includes the idea of 'lag variables'.

So this recipe is a short example on what is AR modelling of time series. Let's get started.

```
import numpy as np
import pandas as pd
from statsmodels.tsa.ar_model import AR
```

Let's pause and look at these imports. Numpy and pandas are general ones. Here statsmodels.tsa.ar_model is used to import autorregressive library for building of model.

```
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date'])
df['value'] = np.log(df['value'])
df['value'] = df['value'].diff()
df = df.drop(df.index[0])
df.head()
```

Here, we have used one time series data from github. Now, since this data is progressing and, we have normalized the set and taken difference so as to have a stationary series.

Now our dataset is ready.

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

Here we have simply split data into size of 12 and rest elements

```
model = AR(train_data.value)
model_fitted = model.fit()
```

We have simply build an AR model on our dataset and fit it.

```
print('coefficients',model_fitted.params)
predictions = model_fitted.predict(start=len(train_data), end=len(train_data) + len(test_data)-1)
print(predictions)
```

Here, we have printed the coeffiecient of model and the predicted values.

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

Scroll down the ipython file to visualize the output.

In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

In this project, we are going to work on Deep Learning using H2O to predict Census income.

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 data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.