A time series model is a forecasting technique that attempts to predict the future values of...

70.2K

Verified Solution

Question

Statistics

A time series model is a forecasting technique that attempts topredict the future values of a variable by using only historicaldata on that one variable. Here are some examples of variables youcan use to forecast. You may use a different source other than theones listed (be sure to reference the website). There are manyother variables you can use, as long as you have values that arerecorded at successive intervals of time.

Currency price

GNP

Average home sales

College tuition

Weather temperature or precipitation

Stock price

1.   State the variable you are forecasting.

2.   Collect data for any time horizon (daily,monthly, yearly). Select at least 8 data values.

3.   Use the Time Series Forecasting Templates toforecast using moving average, weighted moving average, andexponential smoothing

4.   Copy/paste the results of each method into yourpost. Be sure to state the number of periods used in the movingaverage method, the weights used in the weighted moving average,and the value of ? used in exponential smoothing.

5.   Clearly state the “next period” prediction foreach method.

Answer & Explanation Solved by verified expert
3.8 Ratings (504 Votes)
Understanding the Problem Statement andDatasetWe are provided with a Time Series problem involving predictionof number of commuters of JetRail a new high speed rail service byUnicorn Investors We are provided with 2 years of dataAug2012Sept 2014 and using this data we have to forecast the numberof commuters for next 7 monthsLets start working on the dataset downloaded from the abovelink In this article Im working with train dataset onlyimport pandas as pd import numpy as np import matplotlibpyplot as plt Importing datadf pdreadcsvtraincsvPrinting headdfheadPrinting taildftailAs seen from the print statements above we are given 2 years ofdata20122014 at hourly level with thenumber of commuters travelling and we need to estimate the numberof commuters for futureIn this article Im subsetting and aggregating dataset at dailybasis to explain the different methodsSubsetting the dataset from August 2012 Dec 2013Creating train and test file for modeling The first 14 monthsAugust 2012 October 2013 are used as training data and next 2months Nov 2013 Dec 2013 as testing dataAggregating the dataset at daily basisSubsetting the datasetIndex 11856 marks the end of year 2013df pdreadcsvtraincsv nrows 11856Creating train and test set Index 10392 marks the end of October 2013 traindf010392 testdf10392Aggregating the dataset at daily leveldfTimestamp pdtodatetimedfDatetimeformatdmY HM dfindex dfTimestamp df dfresampleDmeantrainTimestamp pdtodatetimetrainDatetimeformatdmY HM trainindex trainTimestamp train trainresampleDmean testTimestamp pdtodatetimetestDatetimeformatdmY HM testindex testTimestamp test testresampleDmeanLets visualize the data train and test together to know howit varies over a time periodPlotting datatrainCountplotfigsize158 title Daily Ridership fontsize14testCountplotfigsize158 title Daily Ridership fontsize14pltshowInstalling librarystatsmodelsThe library which I have used to perform Time series forecastingis statsmodels You need to install it before applying few of thegiven approaches statsmodels might already be installed in yourpython environment but it doesnt support forecasting methods Wewill clone it from their repository and install using the sourcecode Follow these steps Use pip freeze to check if its already installed in yourenvironmentIf already present remove it using conda removestatsmodelsClone the statsmodels repository using git clonegitgithubcomstatsmodelsstatsmodelsgit Initialise the Gitusing git init before cloningChange the directory to statsmodels using cd statsmodelsBuild the setup file using python setuppy buildInstall it using python setuppy installExit the bashterminalRestart the bashterminal in your environment open python andexecute from statsmodelstsaapi import ExponentialSmoothing toverifyMethod 1 Start with a Naive ApproachConsider the graph given below Lets assume that the yaxisdepicts the price of a coin and xaxis depicts the time daysWe can infer from the graph that the price of the coin is stablefrom the start Many a times we are provided with a dataset whichis stable throughout its time period If we want to forecast theprice for the next day we can simply take the last day value andestimate the same value for the next day Such forecastingtechnique which assumes that the next expected point is equal tothe last observed point is called NaiveMethodNow we will implement the Naive method to forecast the pricesfor test datadd npasarraytrainCountyhat testcopyyhatnaive ddlendd1pltfigurefigsize128pltplottrainindex trainCount labelTrainpltplottestindextestCount labelTestpltplotyhatindexyhatnaive labelNaive ForecastpltlegendlocbestplttitleNaive ForecastpltshowWe will now calculate RMSE to check to accuracy of our model ontest    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students