
Time Series Analysis and Modeling Overview
Explore time series analysis in machine learning with practical examples like forecasting sales trends and detecting anomalies. Understand the importance of stationarity in time series data for accurate modeling.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Machine Learning for Beginners: Class 9 By Kelsey Emnett
Links Files located here Files located here: bit.ly/machine-learning-introduction Class videos Class videos will be posted by the Sunday after class on my website www.kelseyemnett.com and my YouTube channel https://www.youtube.com/channel/UCR7ejcDyKykQ3wE- KS08Smg.
Class Machine Learning Example Trying to Measure: Trying to Measure: Data: Data: Goal: Goal: Missouri drug overdose counts Rossmann store sales Trends, patterns, and seasonality over time Understand past and current trends and forecast the future Drug Overdose Data Rossmann Store Sales 3
Overview of Time Series Analysis
Time Series Modeling Missouri Drug Overdoses According to Practical Time Series Analysis, time series analysis analysis is the endeavor of extracting meaningful summary and statistical information from points arrange in chronological order . Why not use regression? Regression assumes independence of observations Previous data points will be similar to future data points time series Rossmann Store Sales
Time Series Use Cases Forecasting future sales and transactions Understanding historical credit card application trends, seasonality, and events such as holidays Detect anomalies to: Predict machinery malfunctions Detect misuse in rewards and recognition usage
Stationarity Stationarity: Stationarity: Assumption of some time series methods that statistical properties of a system stay static over time Exhibits no trends or seasonality Shows a constant mean and variance Not Stationary Stationary
Stationarity Requirement The presence or absence of these patterns in your data determine which modeling method is best To use most traditional statistical time series data, the data needs to be stationary Need stationary data to run autoregressive (AR), moving average (MA), ARMA, and ARIMA models If your data is not stationary, can use differencing to make it stationary 1st Differencing: Taking the current time period minus the previous time period 2nd Differencing: Differencing using the results of 1st differencing procedure
Testing for Stationarity To test for stationarity mathematically can use a Dickey-Fuller test Uses an auto-regressive model and tests for stationarity across multiple lag values Null hypothesis is that a data set is not stationary If the p p- -value is significant value is significant, we can reject the null hypothesis and assume that the data is stationary data is stationary
Autocorrelation Autocorrelation: Autocorrelation: Correlation between two data points at different positions in a time series Autocorrelation is measured in lags or the number of intervals between two points in a time series For example, the lag between the current point and two points prior is 2 Examining autocorrelation plots can help uncover stationarity, seasonality, and trends
Autocorrelation (ACF) Plots: Stationary Bars outside the red lines have autocorrelation that is significant If there is a significant autocorrelation, indicates you need a model with lags Stationary time series have autocorrelation that declines to zero quickly
Autocorrelation (ACF) Plots: Not Stationary Random Random Trend Trend Seasonality Seasonality Correlation gradually decreases with each additional lag Bars oscillate with a consistent a pattern Points are not correlated with previous points Demonstrates seasonality and the data is not stationary Use regression not time series Demonstrates a trend and the data is not stationary
Partial Autocorrelation Plots Similar to an autocorrelation plot in that it shows the correlation between each point and its prior points Differs because it shows only the correlation that is not explained by the shorter lags For example, the partial correlation for lag 3 will be the correlation not explained by lags 1 and 2
Autoregressive (AR) Model An autoregressive model autoregressive model is a linear regression model that uses its own lagged values as predictors In an AR(1) each point is regressed on its prior value, whereas in an AR(2) model each point is regressed on the two previous values
AR Models: Identifying AR Order Value Choose the AR order value (p) with a partial autocorrelation plot (PACF) Count the number of lags that are significant before dropping towards zero In this case, the AR order value should be 2
Moving Average (MA) Models Similar to AR models except that the predictors in the linear regression model are past forecast errors Returns a weighted moving average of the specified number of past forecast errors
MA Models: Choosing MA Window Use the autocorrelation plot to determine the moving average (MA) window (q) The first 2 lags are significant meaning a moving average window of 2 is appropriate
Choosing a Model Model Type Model Type AR Only MA Only ARMA ACF ACF Gradual q significant lags Gradual Gradual PACF PACF p significant lags Gradual AR Only MA Only ARMA
ARMA and ARIMA Models Can combine AR and MA models when both autocorrelation and partial autocorrelation plots show gradual decreases If differencing is used, use an ARIMA model If differencing is not used, use an ARMA model (p, d, q) p: AR parameters d: differencing q: MA parameters
Seasonality and Trends What if you cannot achieve stationarity? Usually occurs when a trend or seasonality exists Need to use a model that accounts for seasonality and/or trends If is no trend but seasonality exists: Can use SARIMA models Uses an ARIMA model that accounts for seasonal trends If there is a trend and seasonality need to use a model that accounts for both In a future class we will cover Meta/Facebook Prophet models an option for this type of analysis
Time Series Resources General Time Series Resources https://otexts.com/fpp2/index.html https://towardsdatascience.com/time-series-from-scratch-decomposing-time-series- data-7b7ad0c30fe7 MA, AR, ARMA, and ARIMA Models https://predictivehacks.com/arima-model-in-python/ https://machinelearningmastery.com/make-sample-forecasts-arima-python/ https://towardsdatascience.com/time-series-forecasting-arima-models- 7f221e9eee06#:~:text=Stationary%20time%20series%20is%20when,when%20the%2 0series%20is%20stationary.&text=Autocorrelation%20refers%20to%20how%20corre lated,and%20including%20the%20lag%20unit. https://towardsdatascience.com/defining-the-moving-average-model-for-time- series-forecasting-in-python-626781db2502 https://www.geeksforgeeks.org/python-arima-model-for-time-series-forecasting/ Data Visualization https://machinelearningmastery.com/time-series-data-visualization-with-python/
Time Series Resources Time Series Assumptions https://analyzingalpha.com/stationarity https://statisticsbyjim.com/time-series/autocorrelation-partial- autocorrelation/#:~:text=Autocorrelation%20is%20the%20correlation%20between,va lues%20influence%20the%20current%20value. https://analyticsindiamag.com/an-overview-of-autocorrelation-seasonality-and- stationarity-in-time-series-data/ https://www.influxdata.com/blog/autocorrelation-in-time-series-data/ https://towardsdatascience.com/identifying-ar-and-ma-terms-using-acf-and-pacf- plots-in-time-series-forecasting-ccb9fd073db8 https://analyticsindiamag.com/complete-guide-to-dickey-fuller-test-in-time-series- analysis/