SlideShare a Scribd company logo
TIME SERIES ANALYSIS:
THEORY AND PRACTICE
LMLP MEETUP
TIME SERIES ANALYSIS:THEORY AND PRACTICE
SOME HOUSEKEEPING
▸ Call for presenters over the summer period
▸ Please don’t use the CodeNode bar after the meetup since
it’s booked for a private event - go to the pub across the
road
2
TIME SERIES ANALYSIS:THEORY AND PRACTICE
DEFINITION OF TIME SERIES DATA
▸ Sequence of measurements (data points) -
▸ that follow non-random order (i.e. are successive) -
▸ taken over regular time intervals -
▸ usually with no more than one data point per interval (if
there’s more than one data point - we call it multiple time
series analysis and use slightly different approaches to
modelling).
3
TIME SERIES ANALYSIS:THEORY AND PRACTICE
HOW ARE TIME SERIES DIFFERENT FROM OTHER TYPES OF DATA?
▸ Panel data
▸ Cross-sectional data
▸ Time series is a type of cross-sectional data set where one
measurement is differentiated from another by time stamp only
4
TIME SERIES ANALYSIS:THEORY AND PRACTICE
APPLICATIONS
▸ Financial markets
▸ Weather forecasting
▸ Sales forecasting
▸ Signal processing
▸ Natural language processing
5
TIME SERIES ANALYSIS:THEORY AND PRACTICE
PROPERTIES OF TIME SERIES
▸ Seasonality
▸ Trending
▸ Cycles
6
TIME SERIES ANALYSIS:THEORY AND PRACTICE
TRENDING
▸ A trend exists when there is a long-term increase or decrease in the
data. It does not have to be linear. A trend can “change direction” and,
say, go from increasing to decreasing.
▸ Trends usually become visible when a linear function is fitted to the
data.
7
Source: http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
TIME SERIES ANALYSIS:THEORY AND PRACTICE
SEASONALITY AND CYCLES
▸ A seasonal pattern exists when a series is influenced by
seasonal factors (e.g. the month of the year or day of the
week). Seasonality is always of a fixed and of a known period.
▸ A cyclic pattern exists when data exhibit rises and falls that
are not of fixed period. The duration of these fluctuations is
usually of at least 2 years (e.g. economic cycles).
▸ What may seem to be a trend over a short period of time
may be due to seasonality/cycle over a longer period of time.
Always zoom in/zoom out when plotting your data!
8
TIME SERIES ANALYSIS:THEORY AND PRACTICE
WHAT DOES IT ALL LOOK LIKE ON A CHART?
9
Source: http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
TIME SERIES ANALYSIS:THEORY AND PRACTICE
WHAT DOES IT ALL LOOK LIKE ON A CHART?
10
Source: http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
TIME SERIES ANALYSIS:THEORY AND PRACTICE
WHAT DOES IT ALL LOOK LIKE ON A CHART?
11
Source: http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
TIME SERIES ANALYSIS:THEORY AND PRACTICE
WHAT DOES IT ALL LOOK LIKE ON A CHART?
12
TIME SERIES ANALYSIS:THEORY AND PRACTICE
TESTING FOR TRENDS AND SEASONALITY
▸ Checking for seasonality: autocorrelation.
▸ Checking for trends: fit a simple curve or a rolling average
and eyeball the chart. No proven automatic tests. Strong
autocorrelation with the time period immediately
preceding the measurement also suggests a trend
component.
13
TIME SERIES ANALYSIS:THEORY AND PRACTICE
ON THE IMPORTANCE OF ASKING THE RIGHT QUESTIONS
▸ What are you trying to predict?
▸ Do you know how the measurements were taken?
▸ Do you have any missing values in the dataset? If yes, what
do they represent?
▸ Do you need to adjust for seasonality or trend?
▸ What “shape” is your dataset?
▸ What are the assumptions being made?
14
TIME SERIES ANALYSIS:THEORY AND PRACTICE
ON THE IMPORTANCE OF ASKING THE RIGHT QUESTIONS
15
TIME SERIES ANALYSIS:THEORY AND PRACTICE
NOW TO THE PRACTICE BIT
▸ You can’t use the same procedures to analyse snapshot
and time series data.
▸ For example, you can’t randomly pick the data points that
will be withheld for cross-validation and testing purposes.
Why?
▸ Make sure to understand as much as possible about the
underlying factors that affect the measurements.
16
TIME SERIES ANALYSIS:THEORY AND PRACTICE
PLOT, PLOT, THEN PLOT AGAIN
▸ Plotting your data will allow you to uncover the structure
of the dataset, spot irregularities in the data and figure out
which adjustments need to be made before proceeding
with the modelling.
▸ Useful libraries: pandas, numpy, json, matplotlib.pyplot,
pathlib, seaborn, scipy stats, statsmodels.
17
TIME SERIES ANALYSIS:THEORY AND PRACTICE
TIPS AND TRICKS FOR PLOTTING
▸ Basic function: plot
18
TIME SERIES ANALYSIS:THEORY AND PRACTICE
TIPS AND TRICKS FOR PLOTTING
▸ Plotting multiple lines
19
TIME SERIES ANALYSIS:THEORY AND PRACTICE
TIPS AND TRICKS FOR PLOTTING
▸ Autocorrelation
▸ Use autocorrelation_plot from
pandas.tools.plotting
20
TIME SERIES ANALYSIS:THEORY AND PRACTICE
TIPS AND TRICKS FOR PLOTTING
▸ Autocorrelation
21
TIME SERIES ANALYSIS:THEORY AND PRACTICE
TIPS AND TRICKS FOR PLOTTING
▸ Smoothing - linear and exponential
▸ To see the “bigger picture” you may want to look at a moving average of the
input values.
▸ This is what they call “smoothing”.
▸ Linear smoothing gives equal weight to all the points it’s averaging over,
exponential smoothing gives more weight to more recent points.
▸ Points taken as inputs by moving average can be either centred around the
original value or directly behind it.
▸ Use [ColumnName].rolling.(window=[window size], center=True).mean().plot()
to plot rolling average. You can also replace mean by median.
22
TIME SERIES ANALYSIS:THEORY AND PRACTICE
TIPS AND TRICKS FOR PLOTTING
▸ For more plotting tools from pandas, visit
▸ http://pandas.pydata.org/pandas-docs/stable/
visualization.html#visualization-autocorrelation
▸ http://pandas.pydata.org/pandas-docs/stable/
computation.html#rolling-windows
23
TIME SERIES ANALYSIS:THEORY AND PRACTICE
DATA LOADING AND PREPROCESSING
▸ The data often comes in the form of multiple large csv files that
need to be concatenated together for further processing or slicing.
▸ Here is a useful discussion on Stack Overflow covering this issue:
http://stackoverflow.com/questions/25210819/speeding-up-data-
import-function-pandas-and-appending-to-dataframe/
25210900#25210900
▸ A useful aside: to speed up processing, specify columns to import
and their data type when you’re reading csv into a data frame - and
you can specify different data types for different columns by using
a dictionary: http://pandas.pydata.org/pandas-docs/stable/
generated/pandas.read_csv.html
24
TIME SERIES ANALYSIS:THEORY AND PRACTICE
MODELLING APPROACHES-ARMA
▸ ARMA: autoregressive moving average
▸ Example: http://statsmodels.sourceforge.net/devel/
examples/notebooks/generated/tsa_arma.html
▸ ARMA models combine t autoregressive and moving-
average terms to predict (t+1)-th term
25
TIME SERIES ANALYSIS:THEORY AND PRACTICE
MODELLING APPROACHES-ARMA
▸ Autoregressive model of order p:
▸ c is a constant, φ are parameters, ε is the error term (white
noise).
▸ Moving average model of order q:
▸ μ is expectation of Xt, ε is again the error term, θ are
parameters.
▸ Combined:
26
TIME SERIES ANALYSIS:THEORY AND PRACTICE
MODELLING APPROACHES - ARMA
▸ Why do we combine AR and MA models?
▸ AR model assumes steady change and is poor for
predicting sudden fluctuations.
▸ MA model takes error terms as an input which allows us to
take into account sudden changes in output faster than AR
model would have done on its own.
▸ Data doesn’t come with errors predefined - these are in fact
extrapolated by first fitting a model like AR. See any issues?
27
TIME SERIES ANALYSIS:THEORY AND PRACTICE
OTHER MODELLING APPROACHES
▸ Spectrum/Fourier analysis
▸ Attempts to decompose the function into a sum of sinusoidal
waves.
▸ Main aim is to determine the length and amplitude of
underlying cycles in cases where they are not immediately
obvious.
▸ More useful for things like sun spot activity than sales
forecasting (in the latter case seasonal component is easily
guessed by just eyeballing the data).
28
TIME SERIES ANALYSIS:THEORY AND PRACTICE
LIMITATIONS OF STANDARD APPROACHES
▸ Difficulty capturing high level dependencies - additional
rules typically have the be hardcoded.
▸ Can’t handle all of the possible data structures effectively.
29
TIME SERIES ANALYSIS:THEORY AND PRACTICE
PREDICTION HORIZON
▸ Why can’t we see far into the future?
▸ An interlude on chaos theory
30
TIME SERIES ANALYSIS:THEORY AND PRACTICE
NEURAL NETWORKS - A POSSIBLE ALTERNATIVE
▸ Neural network architectures can be modified to capture
global dependencies (e.g. LSTM).
▸ Capable of both regression and classification, depending
on the choice of activation function.
▸ Next time we will discuss
31
TIME SERIES ANALYSIS:THEORY AND PRACTICE
USEFUL LINKS
▸ https://documents.software.dell.com/statistics/textbook/time-series-analysis
▸ https://en.wikipedia.org/wiki/Time_series
▸ http://www.fil.ion.ucl.ac.uk/~wpenny/course/array.pdf
▸ https://en.wikipedia.org/wiki/Weather_forecasting
▸ https://www.otexts.org/fpp/6/1
▸ http://pandas.pydata.org/pandas-docs/stable/cookbook.html#cookbook-plotting
▸ http://pandas.pydata.org/pandas-docs/stable/visualization.html
▸ http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html
▸ http://en.wikipedia.org/wiki/Autoregressive–moving-average_model
▸ http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
32

More Related Content

What's hot

Arima model
Arima modelArima model
Arima model
Jassika
 
Time Series Analysis.pptx
Time Series Analysis.pptxTime Series Analysis.pptx
Time Series Analysis.pptx
Sunny429247
 
Machine learning & Time Series Analysis
Machine learning & Time Series AnalysisMachine learning & Time Series Analysis
Machine learning & Time Series Analysis
台灣量化交易協會
 
Exploratory data analysis
Exploratory data analysis Exploratory data analysis
Exploratory data analysis
Peter Reimann
 
Time series forecasting with machine learning
Time series forecasting with machine learningTime series forecasting with machine learning
Time series forecasting with machine learning
Dr Wei Liu
 
Exploratory data analysis with Python
Exploratory data analysis with PythonExploratory data analysis with Python
Exploratory data analysis with Python
Davis David
 
Time Series Analysis, Components and Application in Forecasting
Time Series Analysis, Components and Application in ForecastingTime Series Analysis, Components and Application in Forecasting
Time Series Analysis, Components and Application in Forecasting
Sundar B N
 
Exploratory data analysis
Exploratory data analysisExploratory data analysis
Exploratory data analysis
Gramener
 
Model Selection Techniques
Model Selection TechniquesModel Selection Techniques
Model Selection Techniques
Swati .
 
Principal Component Analysis
Principal Component AnalysisPrincipal Component Analysis
Principal Component Analysis
Ricardo Wendell Rodrigues da Silveira
 
Exploratory data analysis
Exploratory data analysisExploratory data analysis
Exploratory data analysis
Vishwas N
 
Lesson 2 stationary_time_series
Lesson 2 stationary_time_seriesLesson 2 stationary_time_series
Lesson 2 stationary_time_series
ankit_ppt
 
Arima model (time series)
Arima model (time series)Arima model (time series)
Arima model (time series)
Kumar P
 
Forecasting techniques, time series analysis
Forecasting techniques, time series analysisForecasting techniques, time series analysis
Forecasting techniques, time series analysis
SATISH KUMAR
 
Time series Analysis
Time series AnalysisTime series Analysis
Time series Analysis
Mahak Vijayvargiya
 
Mba 532 2011_part_3_time_series_analysis
Mba 532 2011_part_3_time_series_analysisMba 532 2011_part_3_time_series_analysis
Mba 532 2011_part_3_time_series_analysisChandra Kodituwakku
 
Statistics for data science
Statistics for data science Statistics for data science
Statistics for data science
zekeLabs Technologies
 
Time Series Analysis - 2 | Time Series in R | ARIMA Model Forecasting | Data ...
Time Series Analysis - 2 | Time Series in R | ARIMA Model Forecasting | Data ...Time Series Analysis - 2 | Time Series in R | ARIMA Model Forecasting | Data ...
Time Series Analysis - 2 | Time Series in R | ARIMA Model Forecasting | Data ...
Simplilearn
 
Time series analysis in Stata
Time series analysis in StataTime series analysis in Stata
Time series analysis in Stata
shahisec1
 

What's hot (20)

Arima model
Arima modelArima model
Arima model
 
Time Series Analysis.pptx
Time Series Analysis.pptxTime Series Analysis.pptx
Time Series Analysis.pptx
 
Machine learning & Time Series Analysis
Machine learning & Time Series AnalysisMachine learning & Time Series Analysis
Machine learning & Time Series Analysis
 
Exploratory data analysis
Exploratory data analysis Exploratory data analysis
Exploratory data analysis
 
Time series forecasting with machine learning
Time series forecasting with machine learningTime series forecasting with machine learning
Time series forecasting with machine learning
 
Exploratory data analysis with Python
Exploratory data analysis with PythonExploratory data analysis with Python
Exploratory data analysis with Python
 
Time Series Analysis, Components and Application in Forecasting
Time Series Analysis, Components and Application in ForecastingTime Series Analysis, Components and Application in Forecasting
Time Series Analysis, Components and Application in Forecasting
 
Exploratory data analysis
Exploratory data analysisExploratory data analysis
Exploratory data analysis
 
Model Selection Techniques
Model Selection TechniquesModel Selection Techniques
Model Selection Techniques
 
Principal Component Analysis
Principal Component AnalysisPrincipal Component Analysis
Principal Component Analysis
 
Exploratory data analysis
Exploratory data analysisExploratory data analysis
Exploratory data analysis
 
Lesson 2 stationary_time_series
Lesson 2 stationary_time_seriesLesson 2 stationary_time_series
Lesson 2 stationary_time_series
 
Arima model (time series)
Arima model (time series)Arima model (time series)
Arima model (time series)
 
Forecasting techniques, time series analysis
Forecasting techniques, time series analysisForecasting techniques, time series analysis
Forecasting techniques, time series analysis
 
Time series Analysis
Time series AnalysisTime series Analysis
Time series Analysis
 
Mba 532 2011_part_3_time_series_analysis
Mba 532 2011_part_3_time_series_analysisMba 532 2011_part_3_time_series_analysis
Mba 532 2011_part_3_time_series_analysis
 
Statistics for data science
Statistics for data science Statistics for data science
Statistics for data science
 
Time Series Analysis - 2 | Time Series in R | ARIMA Model Forecasting | Data ...
Time Series Analysis - 2 | Time Series in R | ARIMA Model Forecasting | Data ...Time Series Analysis - 2 | Time Series in R | ARIMA Model Forecasting | Data ...
Time Series Analysis - 2 | Time Series in R | ARIMA Model Forecasting | Data ...
 
Time series analysis in Stata
Time series analysis in StataTime series analysis in Stata
Time series analysis in Stata
 
PCA
PCAPCA
PCA
 

Viewers also liked

How to become a data scientist in 6 months
How to become a data scientist in 6 monthsHow to become a data scientist in 6 months
How to become a data scientist in 6 months
Tetiana Ivanova
 
Time Series
Time SeriesTime Series
Time Seriesyush313
 
Analysis of time series
Analysis of time seriesAnalysis of time series
Analysis of time seriesPablosperessos
 
Time Series Analysis
Time Series AnalysisTime Series Analysis
Time Series Analysis
QAware GmbH
 
STATA - Time Series Analysis
STATA - Time Series AnalysisSTATA - Time Series Analysis
STATA - Time Series Analysisstata_org_uk
 

Viewers also liked (9)

How to become a data scientist in 6 months
How to become a data scientist in 6 monthsHow to become a data scientist in 6 months
How to become a data scientist in 6 months
 
Time Series
Time SeriesTime Series
Time Series
 
Time series
Time seriesTime series
Time series
 
Analysis of time series
Analysis of time seriesAnalysis of time series
Analysis of time series
 
Time series Forecasting
Time series ForecastingTime series Forecasting
Time series Forecasting
 
Time Series Analysis Ravi
Time Series Analysis RaviTime Series Analysis Ravi
Time Series Analysis Ravi
 
Time series
Time seriesTime series
Time series
 
Time Series Analysis
Time Series AnalysisTime Series Analysis
Time Series Analysis
 
STATA - Time Series Analysis
STATA - Time Series AnalysisSTATA - Time Series Analysis
STATA - Time Series Analysis
 

Similar to Time Series Analysis: Theory and Practice

TIME SERIES ANALYSIS.docx
TIME SERIES ANALYSIS.docxTIME SERIES ANALYSIS.docx
TIME SERIES ANALYSIS.docx
MilhhanMohsin
 
TIME SERIES & CROSS ‎SECTIONAL ANALYSIS
TIME SERIES & CROSS ‎SECTIONAL ANALYSISTIME SERIES & CROSS ‎SECTIONAL ANALYSIS
TIME SERIES & CROSS ‎SECTIONAL ANALYSIS
Libcorpio
 
Time series analysis
Time series analysisTime series analysis
Time series analysis
Faltu Focat
 
Weather forecasting model.pptx
Weather forecasting model.pptxWeather forecasting model.pptx
Weather forecasting model.pptx
VisheshYadav12
 
Run Chart
Run ChartRun Chart
Run Chart
ahmad bassiouny
 
Mining Transactional and Time Series Data
Mining Transactional and Time Series DataMining Transactional and Time Series Data
Mining Transactional and Time Series DataBrenda Wolfe
 
Large Scale Automatic Forecasting for Millions of Forecasts
Large Scale Automatic Forecasting for Millions of ForecastsLarge Scale Automatic Forecasting for Millions of Forecasts
Large Scale Automatic Forecasting for Millions of ForecastsAjay Ohri
 
FIRE ADMIN UNIT 1 .orct121320#ffffff#fa951a#FFFFFF#e7b3513VERSON.docx
FIRE ADMIN UNIT 1 .orct121320#ffffff#fa951a#FFFFFF#e7b3513VERSON.docxFIRE ADMIN UNIT 1 .orct121320#ffffff#fa951a#FFFFFF#e7b3513VERSON.docx
FIRE ADMIN UNIT 1 .orct121320#ffffff#fa951a#FFFFFF#e7b3513VERSON.docx
AKHIL969626
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
Aneel Raza
 
Quality Journey -Introduction to 7QC Tools2.0.pdf
Quality Journey -Introduction to 7QC Tools2.0.pdfQuality Journey -Introduction to 7QC Tools2.0.pdf
Quality Journey -Introduction to 7QC Tools2.0.pdf
NileshJajoo2
 
Quality management methodology
Quality management methodologyQuality management methodology
Quality management methodologyselinasimpson2201
 
Lesson 1 introduction_to_time_series
Lesson 1 introduction_to_time_seriesLesson 1 introduction_to_time_series
Lesson 1 introduction_to_time_series
ankit_ppt
 
Quality management methodologies
Quality management methodologiesQuality management methodologies
Quality management methodologiesselinasimpson331
 
Inter Time Series Sales Forecasting
Inter Time Series Sales ForecastingInter Time Series Sales Forecasting
Inter Time Series Sales Forecasting
IJASCSE
 
Quality management system procedures
Quality management system proceduresQuality management system procedures
Quality management system proceduresselinasimpson2101
 
Demand Forecasting
Demand ForecastingDemand Forecasting
Demand Forecastingyashpal01
 
OLD SEVEN TOOLS OF QUALTIY MANAGEMENT
OLD SEVEN TOOLS OF QUALTIY MANAGEMENTOLD SEVEN TOOLS OF QUALTIY MANAGEMENT
OLD SEVEN TOOLS OF QUALTIY MANAGEMENT
ANNA UNIVERSITY
 
Tqm old tools
Tqm old toolsTqm old tools
Tqm old tools
ANNA UNIVERSITY
 

Similar to Time Series Analysis: Theory and Practice (20)

TIME SERIES ANALYSIS.docx
TIME SERIES ANALYSIS.docxTIME SERIES ANALYSIS.docx
TIME SERIES ANALYSIS.docx
 
TIME SERIES & CROSS ‎SECTIONAL ANALYSIS
TIME SERIES & CROSS ‎SECTIONAL ANALYSISTIME SERIES & CROSS ‎SECTIONAL ANALYSIS
TIME SERIES & CROSS ‎SECTIONAL ANALYSIS
 
Time series analysis
Time series analysisTime series analysis
Time series analysis
 
Weather forecasting model.pptx
Weather forecasting model.pptxWeather forecasting model.pptx
Weather forecasting model.pptx
 
Run Chart
Run ChartRun Chart
Run Chart
 
Mining Transactional and Time Series Data
Mining Transactional and Time Series DataMining Transactional and Time Series Data
Mining Transactional and Time Series Data
 
Large Scale Automatic Forecasting for Millions of Forecasts
Large Scale Automatic Forecasting for Millions of ForecastsLarge Scale Automatic Forecasting for Millions of Forecasts
Large Scale Automatic Forecasting for Millions of Forecasts
 
Demand forecasting
Demand forecastingDemand forecasting
Demand forecasting
 
FIRE ADMIN UNIT 1 .orct121320#ffffff#fa951a#FFFFFF#e7b3513VERSON.docx
FIRE ADMIN UNIT 1 .orct121320#ffffff#fa951a#FFFFFF#e7b3513VERSON.docxFIRE ADMIN UNIT 1 .orct121320#ffffff#fa951a#FFFFFF#e7b3513VERSON.docx
FIRE ADMIN UNIT 1 .orct121320#ffffff#fa951a#FFFFFF#e7b3513VERSON.docx
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Ac26185187
Ac26185187Ac26185187
Ac26185187
 
Quality Journey -Introduction to 7QC Tools2.0.pdf
Quality Journey -Introduction to 7QC Tools2.0.pdfQuality Journey -Introduction to 7QC Tools2.0.pdf
Quality Journey -Introduction to 7QC Tools2.0.pdf
 
Quality management methodology
Quality management methodologyQuality management methodology
Quality management methodology
 
Lesson 1 introduction_to_time_series
Lesson 1 introduction_to_time_seriesLesson 1 introduction_to_time_series
Lesson 1 introduction_to_time_series
 
Quality management methodologies
Quality management methodologiesQuality management methodologies
Quality management methodologies
 
Inter Time Series Sales Forecasting
Inter Time Series Sales ForecastingInter Time Series Sales Forecasting
Inter Time Series Sales Forecasting
 
Quality management system procedures
Quality management system proceduresQuality management system procedures
Quality management system procedures
 
Demand Forecasting
Demand ForecastingDemand Forecasting
Demand Forecasting
 
OLD SEVEN TOOLS OF QUALTIY MANAGEMENT
OLD SEVEN TOOLS OF QUALTIY MANAGEMENTOLD SEVEN TOOLS OF QUALTIY MANAGEMENT
OLD SEVEN TOOLS OF QUALTIY MANAGEMENT
 
Tqm old tools
Tqm old toolsTqm old tools
Tqm old tools
 

Recently uploaded

Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
GetInData
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Enterprise Wired
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
u86oixdj
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
slg6lamcq
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptxData_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
AnirbanRoy608946
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 

Recently uploaded (20)

Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptxData_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 

Time Series Analysis: Theory and Practice

  • 1. TIME SERIES ANALYSIS: THEORY AND PRACTICE LMLP MEETUP
  • 2. TIME SERIES ANALYSIS:THEORY AND PRACTICE SOME HOUSEKEEPING ▸ Call for presenters over the summer period ▸ Please don’t use the CodeNode bar after the meetup since it’s booked for a private event - go to the pub across the road 2
  • 3. TIME SERIES ANALYSIS:THEORY AND PRACTICE DEFINITION OF TIME SERIES DATA ▸ Sequence of measurements (data points) - ▸ that follow non-random order (i.e. are successive) - ▸ taken over regular time intervals - ▸ usually with no more than one data point per interval (if there’s more than one data point - we call it multiple time series analysis and use slightly different approaches to modelling). 3
  • 4. TIME SERIES ANALYSIS:THEORY AND PRACTICE HOW ARE TIME SERIES DIFFERENT FROM OTHER TYPES OF DATA? ▸ Panel data ▸ Cross-sectional data ▸ Time series is a type of cross-sectional data set where one measurement is differentiated from another by time stamp only 4
  • 5. TIME SERIES ANALYSIS:THEORY AND PRACTICE APPLICATIONS ▸ Financial markets ▸ Weather forecasting ▸ Sales forecasting ▸ Signal processing ▸ Natural language processing 5
  • 6. TIME SERIES ANALYSIS:THEORY AND PRACTICE PROPERTIES OF TIME SERIES ▸ Seasonality ▸ Trending ▸ Cycles 6
  • 7. TIME SERIES ANALYSIS:THEORY AND PRACTICE TRENDING ▸ A trend exists when there is a long-term increase or decrease in the data. It does not have to be linear. A trend can “change direction” and, say, go from increasing to decreasing. ▸ Trends usually become visible when a linear function is fitted to the data. 7 Source: http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
  • 8. TIME SERIES ANALYSIS:THEORY AND PRACTICE SEASONALITY AND CYCLES ▸ A seasonal pattern exists when a series is influenced by seasonal factors (e.g. the month of the year or day of the week). Seasonality is always of a fixed and of a known period. ▸ A cyclic pattern exists when data exhibit rises and falls that are not of fixed period. The duration of these fluctuations is usually of at least 2 years (e.g. economic cycles). ▸ What may seem to be a trend over a short period of time may be due to seasonality/cycle over a longer period of time. Always zoom in/zoom out when plotting your data! 8
  • 9. TIME SERIES ANALYSIS:THEORY AND PRACTICE WHAT DOES IT ALL LOOK LIKE ON A CHART? 9 Source: http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
  • 10. TIME SERIES ANALYSIS:THEORY AND PRACTICE WHAT DOES IT ALL LOOK LIKE ON A CHART? 10 Source: http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
  • 11. TIME SERIES ANALYSIS:THEORY AND PRACTICE WHAT DOES IT ALL LOOK LIKE ON A CHART? 11 Source: http://jcflowers1.iweb.bsu.edu/rlo/trends.htm
  • 12. TIME SERIES ANALYSIS:THEORY AND PRACTICE WHAT DOES IT ALL LOOK LIKE ON A CHART? 12
  • 13. TIME SERIES ANALYSIS:THEORY AND PRACTICE TESTING FOR TRENDS AND SEASONALITY ▸ Checking for seasonality: autocorrelation. ▸ Checking for trends: fit a simple curve or a rolling average and eyeball the chart. No proven automatic tests. Strong autocorrelation with the time period immediately preceding the measurement also suggests a trend component. 13
  • 14. TIME SERIES ANALYSIS:THEORY AND PRACTICE ON THE IMPORTANCE OF ASKING THE RIGHT QUESTIONS ▸ What are you trying to predict? ▸ Do you know how the measurements were taken? ▸ Do you have any missing values in the dataset? If yes, what do they represent? ▸ Do you need to adjust for seasonality or trend? ▸ What “shape” is your dataset? ▸ What are the assumptions being made? 14
  • 15. TIME SERIES ANALYSIS:THEORY AND PRACTICE ON THE IMPORTANCE OF ASKING THE RIGHT QUESTIONS 15
  • 16. TIME SERIES ANALYSIS:THEORY AND PRACTICE NOW TO THE PRACTICE BIT ▸ You can’t use the same procedures to analyse snapshot and time series data. ▸ For example, you can’t randomly pick the data points that will be withheld for cross-validation and testing purposes. Why? ▸ Make sure to understand as much as possible about the underlying factors that affect the measurements. 16
  • 17. TIME SERIES ANALYSIS:THEORY AND PRACTICE PLOT, PLOT, THEN PLOT AGAIN ▸ Plotting your data will allow you to uncover the structure of the dataset, spot irregularities in the data and figure out which adjustments need to be made before proceeding with the modelling. ▸ Useful libraries: pandas, numpy, json, matplotlib.pyplot, pathlib, seaborn, scipy stats, statsmodels. 17
  • 18. TIME SERIES ANALYSIS:THEORY AND PRACTICE TIPS AND TRICKS FOR PLOTTING ▸ Basic function: plot 18
  • 19. TIME SERIES ANALYSIS:THEORY AND PRACTICE TIPS AND TRICKS FOR PLOTTING ▸ Plotting multiple lines 19
  • 20. TIME SERIES ANALYSIS:THEORY AND PRACTICE TIPS AND TRICKS FOR PLOTTING ▸ Autocorrelation ▸ Use autocorrelation_plot from pandas.tools.plotting 20
  • 21. TIME SERIES ANALYSIS:THEORY AND PRACTICE TIPS AND TRICKS FOR PLOTTING ▸ Autocorrelation 21
  • 22. TIME SERIES ANALYSIS:THEORY AND PRACTICE TIPS AND TRICKS FOR PLOTTING ▸ Smoothing - linear and exponential ▸ To see the “bigger picture” you may want to look at a moving average of the input values. ▸ This is what they call “smoothing”. ▸ Linear smoothing gives equal weight to all the points it’s averaging over, exponential smoothing gives more weight to more recent points. ▸ Points taken as inputs by moving average can be either centred around the original value or directly behind it. ▸ Use [ColumnName].rolling.(window=[window size], center=True).mean().plot() to plot rolling average. You can also replace mean by median. 22
  • 23. TIME SERIES ANALYSIS:THEORY AND PRACTICE TIPS AND TRICKS FOR PLOTTING ▸ For more plotting tools from pandas, visit ▸ http://pandas.pydata.org/pandas-docs/stable/ visualization.html#visualization-autocorrelation ▸ http://pandas.pydata.org/pandas-docs/stable/ computation.html#rolling-windows 23
  • 24. TIME SERIES ANALYSIS:THEORY AND PRACTICE DATA LOADING AND PREPROCESSING ▸ The data often comes in the form of multiple large csv files that need to be concatenated together for further processing or slicing. ▸ Here is a useful discussion on Stack Overflow covering this issue: http://stackoverflow.com/questions/25210819/speeding-up-data- import-function-pandas-and-appending-to-dataframe/ 25210900#25210900 ▸ A useful aside: to speed up processing, specify columns to import and their data type when you’re reading csv into a data frame - and you can specify different data types for different columns by using a dictionary: http://pandas.pydata.org/pandas-docs/stable/ generated/pandas.read_csv.html 24
  • 25. TIME SERIES ANALYSIS:THEORY AND PRACTICE MODELLING APPROACHES-ARMA ▸ ARMA: autoregressive moving average ▸ Example: http://statsmodels.sourceforge.net/devel/ examples/notebooks/generated/tsa_arma.html ▸ ARMA models combine t autoregressive and moving- average terms to predict (t+1)-th term 25
  • 26. TIME SERIES ANALYSIS:THEORY AND PRACTICE MODELLING APPROACHES-ARMA ▸ Autoregressive model of order p: ▸ c is a constant, φ are parameters, ε is the error term (white noise). ▸ Moving average model of order q: ▸ μ is expectation of Xt, ε is again the error term, θ are parameters. ▸ Combined: 26
  • 27. TIME SERIES ANALYSIS:THEORY AND PRACTICE MODELLING APPROACHES - ARMA ▸ Why do we combine AR and MA models? ▸ AR model assumes steady change and is poor for predicting sudden fluctuations. ▸ MA model takes error terms as an input which allows us to take into account sudden changes in output faster than AR model would have done on its own. ▸ Data doesn’t come with errors predefined - these are in fact extrapolated by first fitting a model like AR. See any issues? 27
  • 28. TIME SERIES ANALYSIS:THEORY AND PRACTICE OTHER MODELLING APPROACHES ▸ Spectrum/Fourier analysis ▸ Attempts to decompose the function into a sum of sinusoidal waves. ▸ Main aim is to determine the length and amplitude of underlying cycles in cases where they are not immediately obvious. ▸ More useful for things like sun spot activity than sales forecasting (in the latter case seasonal component is easily guessed by just eyeballing the data). 28
  • 29. TIME SERIES ANALYSIS:THEORY AND PRACTICE LIMITATIONS OF STANDARD APPROACHES ▸ Difficulty capturing high level dependencies - additional rules typically have the be hardcoded. ▸ Can’t handle all of the possible data structures effectively. 29
  • 30. TIME SERIES ANALYSIS:THEORY AND PRACTICE PREDICTION HORIZON ▸ Why can’t we see far into the future? ▸ An interlude on chaos theory 30
  • 31. TIME SERIES ANALYSIS:THEORY AND PRACTICE NEURAL NETWORKS - A POSSIBLE ALTERNATIVE ▸ Neural network architectures can be modified to capture global dependencies (e.g. LSTM). ▸ Capable of both regression and classification, depending on the choice of activation function. ▸ Next time we will discuss 31
  • 32. TIME SERIES ANALYSIS:THEORY AND PRACTICE USEFUL LINKS ▸ https://documents.software.dell.com/statistics/textbook/time-series-analysis ▸ https://en.wikipedia.org/wiki/Time_series ▸ http://www.fil.ion.ucl.ac.uk/~wpenny/course/array.pdf ▸ https://en.wikipedia.org/wiki/Weather_forecasting ▸ https://www.otexts.org/fpp/6/1 ▸ http://pandas.pydata.org/pandas-docs/stable/cookbook.html#cookbook-plotting ▸ http://pandas.pydata.org/pandas-docs/stable/visualization.html ▸ http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html ▸ http://en.wikipedia.org/wiki/Autoregressive–moving-average_model ▸ http://jcflowers1.iweb.bsu.edu/rlo/trends.htm 32