GithubHelp home page GithubHelp logo

tsa_exp6's Introduction

Ex.No: 6 HOLT WINTERS METHOD

Date: 30-03-2024

AIM:

To implement the Holt Winters Method Model using Python.

ALGORITHM:

  1. You import the necessary libraries
  2. You load a CSV file containing daily airpassengers data into a DataFrame, parse the 'date' column as datetime, and perform some initial data exploration
  3. You group the data by date and resample it to a monthly frequency (beginning of the month
  4. You plot the time series data
  5. You import the necessary 'statsmodels' libraries for time series analysis
  6. You decompose the time series data into its additive components and plot them:
  7. You calculate the root mean squared error (RMSE) to evaluate the model's performance
  8. You calculate the mean and standard deviation of the entire sales dataset, then fit a Holt- Winters model to the entire dataset and make future predictions
  9. You plot the original passengers data and the predictions

PROGRAM:

Import the libraries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.tsa.holtwinters import ExponentialSmoothing

Load the dataset

data=pd.read_csv("/content/AirPassengers.csv")
data

Convert the string format to Date format

data['Month'] = pd.to_datetime(data['Month'])
data.set_index('Month', inplace=True)

Perform Holt-Winters exponential smoothing

model = ExponentialSmoothing(data, trend="add", seasonal="add", seasonal_periods=12)
fit = model.fit()

Forecast for the next n steps

n_steps = 12  

forecast = fit.forecast(steps=n_steps)
forecast

Plot the original data and the forecast

plt.figure(figsize=(10, 6))
plt.plot(data.index, data, label='Original Data')
plt.plot(pd.date_range(start=data.index[-1], periods=n_steps+1, freq='M')[1:], forecast, label='Forecast')
plt.xlabel('Date')
plt.ylabel('Value')
plt.title('Holt-Winters Forecast')
plt.legend()
plt.show()

OUTPUT:

image

RESULT:

Thus the program run successfully based on the Holt Winters Method model.

tsa_exp6's People

Contributors

manojvenaram avatar varalakshmi1084 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.