Git Product home page Git Product logo

-exp---5-auto-regression-model's Introduction

EXP - 5 AUTO-REGRESSION-MODEL

AIM:

Implementation of Auto Regression Model using Python

ALGORITHM:

  1. Import necessary libraries
  2. Read the CSV file into a DataFrame
  3. Perform Augmented Dickey-Fuller test
  4. Split the data into training and testing sets.Fit an AutoRegressive (AR) model with 13 lags
  5. Plot Partial Autocorrelation Function (PACF) and Autocorrelation Function (ACF)
  6. Make predictions using the AR model.Compare the predictions with the test data
  7. Calculate Mean Squared Error (MSE).Plot the test data and predictions.

PROGRAM:

PYTHON import pandas as pd import numpy as np from matplotlib import pyplot from statsmodels.tsa.ar_model import AutoReg df=pd.read_csv("rainfall.csv") df X=df['temp'] X X.plot() from statsmodels.tsa.stattools import adfuller dtest=adfuller(X,autolag='AIC') print("ADF:",dtest[0]) print("P value:",dtest[1]) print("No. of lags:",dtest[2]) print("No. of observations used for ADF regression:",dtest[3]) X_train=X[:len(X)-15] X_test=X[len(X)-15:] AR_model=AutoReg(X_train,lags=13).fit() print(AR_model.summary()) from statsmodels.graphics.tsaplots import plot_pacf,plot_acf pacf=plot_pacf(X,lags=25) acf=plot_acf(X,lags=25) pred=AR_model.predict(start=len(X_train),end=len(X_train)+len(X_test)-1,dynamic=False) pred.plot() X_test pred import sklearn.metrics mse=sklearn.metrics.mean_squared_error(X_test,pred) mse**0.5 X_test.plot() pred.plot()

OUTPUT:

GIVEN DATA

image

PACF - ACF

image

PREDICTION

image

FINIAL PREDICTION

image

RESULT:

Thus we have successfully implemented the auto regression function using above mentioned program.

-exp---5-auto-regression-model's People

Contributors

swethamohanraj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.