SlideShare ist ein Scribd-Unternehmen logo
1 von 59
Downloaden Sie, um offline zu lesen
Learning Deep
Broadband Network@HOME
Hongjoo LEE
Who am I?
● Machine Learning Engineer
○ Fraud Detection System
○ Software Defect Prediction
● Software Engineer
○ Email Services (40+ mil. users)
○ High traffic server (IPC, network, concurrent programming)
● MPhil, HKUST
○ Major : Software Engineering based on ML tech
○ Research interests : ML, NLP, IR
Outline
Data Collection Time series Analysis Forecast Modeling Anomaly Detection
Naive approach
Logging SpeedTest
Data preparation
Handling time series
Seasonal Trend Decomposition Rolling Forecast Basic approaches
Stationarity
Autoregression, Moving Average
Autocorrelation
ARIMA Multivariate Gaussian
LSTM
Home Network
Home Network
Home Network
Anomaly Detection (Naive approach in 2015)
Problem definition
● Detect abnormal states of Home Network
● Anomaly detection for time series
○ Finding outlier data points relative to some usual signal
Types of anomalies in time series
● Additive outliers
Types of anomalies in time series
● Temporal changes
Types of anomalies in time series
● Level shift
Outline
Data Collection Time series Analysis Forecast Modeling Anomaly Detection
Naive approach
Logging SpeedTest
Data preparation
Handling time series
Seasonal Trend Decomposition Rolling Forecast Basic approaches
Stationarity
Autoregression, Moving Average
Autocorrelation
ARIMA Multivariate Gaussian
LSTM
Logging Data
● Speedtest-cli
● Every 5 minutes for 3 Month. ⇒ 20k observations.
$ speedtest-cli --simple
Ping: 35.811 ms
Download: 68.08 Mbit/s
Upload: 19.43 Mbit/s
$ crontab -l
*/5 * * * * echo ‘>>> ‘$(date) >> $LOGFILE; speedtest-cli --simple >> $LOGFILE
2>&1
Logging Data
● Log output
$ more $LOGFILE
>>> Thu Apr 13 10:35:01 KST 2017
Ping: 42.978 ms
Download: 47.61 Mbit/s
Upload: 18.97 Mbit/s
>>> Thu Apr 13 10:40:01 KST 2017
Ping: 103.57 ms
Download: 33.11 Mbit/s
Upload: 18.95 Mbit/s
>>> Thu Apr 13 10:45:01 KST 2017
Ping: 47.668 ms
Download: 54.14 Mbit/s
Upload: 4.01 Mbit/s
Data preparation
● Parse data
class SpeedTest(object):
def __init__(self, string):
self.__string = string
self.__pos = 0
self.datetime = None# for DatetimeIndex
self.ping = None # ping test in ms
self.download = None# down speed in Mbit/sec
self.upload = None # up speed in Mbit/sec
def __iter__(self):
return self
def next(self):
…
Data preparation
● Build panda DataFrame
speedtests = [st for st in SpeedTests(logstring)]
dt_index = pd.date_range(
speedtests[0].datetime.replace(second=0, microsecond=0),
periods=len(speedtests), freq='5min')
df = pd.DataFrame(index=dt_index,
data=([st.ping, st.download, st.upload] for st in speedtests),
columns=['ping','down','up'])
Data preparation
● Plot raw data
Data preparation
● Structural breaks
○ Accidental missings for a long period
Data preparation
● Handling missing data
○ Only a few occasional cases
Handling time series
● By DatetimeIndex
○ df[‘2017-04’:’2017-06’]
○ df[‘2017-04’:]
○ df[‘2017-04-01 00:00:00’:]
○ df[df.index.weekday_name == ‘Monday’]
○ df[df.index.minute == 0]
● By TimeGrouper
○ df.groupby(pd.TimeGrouper(‘D’))
○ df.groupby(pd.TimeGrouper(‘M’))
Patterns in time series
● Is there a pattern in 24 hours?
Patterns in time series
● Is there a daily pattern?
Components of Time series data
● Trend :The increasing or decreasing direction in the series.
● Seasonality : The repeating in a period in the series.
● Noise : The random variation in the series.
Components of Time series data
● A time series is a combination of these components.
○ yt
= Tt
+ St
+ Nt
(additive model)
○ yt
= Tt
× St
× Nt
(multiplicative model)
Seasonal Trend Decomposition
from statsmodels.tsa.seasonal import seasonal_decompose
decomposition = seasonal_decompose(week_dn_ts)
plt.plot(week_dn_ts) # Original
plt.plot(decomposition.seasonal)
plt.plot(decomposition.trend)
Rolling Forecast
A B C
Rolling Forecast
from statsmodels.tsa.arima_model import ARIMA
forecasts = list()
history = [x for x in train_X]
for t in range(len(test_X)): # for each new observation
model = ARIMA(history, order=order) # update the model
y_hat = model.fit().forecast() # forecast one step ahead
forecasts.append(y_hat) # store predictions
history.append(test_X[t]) # keep history updated
Residuals ~ N( , 2
)
residuals = [test[t] - forecasts[t] for t in range(len(test_X))]
residuals = pd.DataFrame(residuals)
residuals.plot(kind=’kde’)
Anomaly Detection (Basic approach)
● IQR (Inter Quartile Range)
● 2-5 Standard Deviation
● MAD (Median Absolute Deviation)
Anomaly Detection (Naive approach)
● Inter Quartile Range
Anomaly Detection (Naive approach)
● Inter Quartile Range
○ NumPy
○ Pandas
q1, q3 = np.percentile(col, [25, 75])
iqr = q3 - q1
np.where((col < q1 - 1.5*iqr) | (col > q3 + 1.5*iqr))
q1 = df[‘col’].quantile(.25)
q3 = df[‘col’].quantile(.75)
iqr = q3 - q1
df.loc[~df[‘col’].between(q1-1.5*iqr, q3+1.5*iqr),’col’]
Anomaly Detection (Naive approach)
● 2-5 Standard Deviation
Anomaly Detection (Naive approach)
● 2-5 Standard Deviation
○ NumPy
○ Pandas
std = pd[‘col’].std()
med = pd[‘col’].median()
df.loc[~df[‘col’].between(med - 3*std, med + 3*std), 0]
std = np.std(col)
med = np.median(col)
np.where((col < med - 3*std) | (col < med + 3*std))
Anomaly Detection (Naive approach)
● MAD (Median Absolute Deviation)
○ MAD = median(|Xi
- median(X)|)
○ “Detecting outliers: Do not use standard deviation around the mean, use absolute deviation
around the median” - Christopher Leys (2013)
Outline
Data Collection Time series Analysis Forecast Modeling Anomaly Detection
Naive approach
Logging SpeedTest
Data preparation
Handling time series
Seasonal Trend Decomposition Rolling Forecast Basic approaches
Stationarity
Autoregression, Moving Average
Autocorrelation
ARIMA Multivariate Gaussian
LSTM
Stationary Series Criterion
● The mean, variance and covariance of the series are time invariant.
stationary non-stationary
Stationary Series Criterion
● The mean, variance and covariance of the series are time invariant.
stationary non-stationary
Stationary Series Criterion
● The mean, variance and covariance of the series are time invariant.
stationary non-stationary
Test Stationarity
Differencing
● A non-stationary series can be made stationary after differencing.
● Instead of modelling the level, we model the change
● Instead of forecasting the level, we forecast the change
● I(d) = yt
- yt-d
● AR + I + MA
Autoregression (AR)
● Autoregression means developing a linear model that uses observations at
previous time steps to predict observations at future time step.
● Because the regression model uses data from the same input variable at
previous time steps, it is referred to as an autoregression
Moving Average (MA)
● MA models look similar to the AR component, but it's dealing with different
values.
● The model account for the possibility of a relationship between a variable
and the residuals from previous periods.
ARIMA(p, d, q)
● Autoregressive Integrated Moving Average
○ AR : A model that uses dependent relationship between an observation and some number of
lagged observations.
○ I : The use of differencing of raw observations in order to make the time series stationary.
○ MA : A model that uses the dependency between an observation and a residual error from a
MA model.
● parameters of ARIMA model
○ p : The number of lag observations included in the model
○ d : the degree of differencing, the number of times that raw observations are differenced
○ q : The size of moving average window.
Identification of ARIMA
● Autocorrelation function(ACF) : measured by a simple correlation between
current observation Yt
and the observation p lags from the current one Yt-p
.
● Partial Autocorrelation Function (PACF) : measured by the degree of
association between Yt
and Yt-p
when the effects at other intermediate time
lags between Yt
and Yt-p
are removed.
● Inference from ACF and PACF : theoretical ACFs and PACFs are available for
various values of the lags of AR and MA components. Therefore, plotting
ACFs and PACFs versus lags and comparing leads to the selection of the
appropriate parameter p and q for ARIMA model
Identification of ARIMA (easy case)
● General characteristics of theoretical ACFs and PACFs
● Reference :
○ http://people.duke.edu/~rnau/411arim3.htm
○ Prof. Robert Nau
model ACF PACF
AR(p) Tail off; Spikes decay towards zero Spikes cutoff to zero after lag p
MA(q) Spikes cutoff to zero after lag q Tails off; Spikes decay towards zero
ARMA(p,q) Tails off; Spikes decay towards zero Tails off; Spikes decay towards zero
Identification of ARIMA (easy case)
Identification of ARIMA (complicated)
Anomaly Detection (Parameter Estimation)
xdown
xup
xdown
xup
Anomaly Detection (Multivariate Gaussian Distribution)
Anomaly Detection (Multivariate Gaussian)
import numpy as np
from scipy.stats import multivariate_normal
def estimate_gaussian(dataset):
mu = np.mean(dataset, axis=0)
sigma = np.cov(dataset.T)
return mu, sigma
def multivariate_gaussian(dataset, mu, sigma):
p = multivariate_normal(mean=mu, cov=sigma)
return p.pdf(dataset)
mu, sigma = estimate_gaussian(train_X)
p = multivariate_gaussian(train_X, mu, sigma)
anomalies = np.where(p < ep) # ep : threshold
Anomaly Detection (Multivariate Gaussian)
import numpy as np
from scipy.stats import multivariate_normal
def estimate_gaussian(dataset):
mu = np.mean(dataset, axis=0)
sigma = np.cov(dataset.T)
return mu, sigma
def multivariate_gaussian(dataset, mu, sigma):
p = multivariate_normal(mean=mu, cov=sigma)
return p.pdf(dataset)
mu, sigma = estimate_gaussian(train_X)
p = multivariate_gaussian(train_X, mu, sigma)
anomalies = np.where(p < ep) # ep : threshold
Anomaly Detection (Multivariate Gaussian)
import numpy as np
from scipy.stats import multivariate_normal
def estimate_gaussian(dataset):
mu = np.mean(dataset, axis=0)
sigma = np.cov(dataset.T)
return mu, sigma
def multivariate_gaussian(dataset, mu, sigma):
p = multivariate_normal(mean=mu, cov=sigma)
return p.pdf(dataset)
mu, sigma = estimate_gaussian(train_X)
p = multivariate_gaussian(train_X, mu, sigma)
anomalies = np.where(p < ep) # ep : threshold
Outline
Data Collection Time series Analysis Forecast Modeling Anomaly Detection
Naive approach
Logging SpeedTest
Data preparation
Handling time series
Seasonal Trend Decomposition Rolling Forecast Basic approaches
Stationarity
Autoregression, Moving Average
Autocorrelation
ARIMA Multivariate Gaussian
LSTM
Long Short-Term Memory
h0
h1
h2
ht-2
ht-1
c0
c1
c2
ct-2
ct-1
x0
x1
x2
xt-2
xt-1
xt
LSTM layer
Long Short-Term Memory
x0
dn
x0
up
x0
pg
xt
dn
x1
up
x2
pg
xt-1
up
xt-1
dn
xt-1
pg
h0
h1
h2
ht-2
ht-1
c0
c1
c2
ct-2
ct-1
x0
x1
x2
xt-2
xt-1
xt
LSTM layer
Long Short-Term Memory
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from sklearn.metrics import mean_squared_error
model = Sequential()
model.add(LSTM(num_neurons, stateful=True, return_sequences=True,
batch_input_shape=(batch_size, timesteps, input_dimension))
model.add(LSTM(num_neurons, stateful=True,
batch_input_shape=(batch_size, timesteps, input_dimension))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
for i in range(num_epoch):
model.fit(train_X, y, epochs=1, batch_size=batch_size, shuffle=False)
model.reset_states()
Long Short-Term Memory
● Will allow to model sophisticated and seasonal dependencies in time series
● Very helpful with multiple time series
● On going research, requires a lot of work to build model for time series
Summary
● Be prepared before calling engineers for service failures
● Pythonista has all the powerful tools
○ pandas is great for handling time series
○ statsmodels for analyzing and modeling time series
○ sklearn is such a multi-tool in data science
○ keras is good to start deep learning
● Pythonista needs to understand a few concepts before using the tools
○ Stationarity in time series
○ Autoregressive and Moving Average
○ Means of forecasting, anomaly detection
● Deep Learning for forecasting time series
○ still on-going research
● Do try this at home
Contacts
lee.hongjoo@yandex.com
linkedin.com/in/hongjoo-lee

Weitere ähnliche Inhalte

Was ist angesagt?

STRIP: stream learning of influence probabilities.
STRIP: stream learning of influence probabilities.STRIP: stream learning of influence probabilities.
STRIP: stream learning of influence probabilities.
Albert Bifet
 
ICML2013読み会 Large-Scale Learning with Less RAM via Randomization
ICML2013読み会 Large-Scale Learning with Less RAM via RandomizationICML2013読み会 Large-Scale Learning with Less RAM via Randomization
ICML2013読み会 Large-Scale Learning with Less RAM via Randomization
Hidekazu Oiwa
 
Exploring Optimization in Vowpal Wabbit
Exploring Optimization in Vowpal WabbitExploring Optimization in Vowpal Wabbit
Exploring Optimization in Vowpal Wabbit
Shiladitya Sen
 

Was ist angesagt? (20)

Mining Frequent Closed Graphs on Evolving Data Streams
Mining Frequent Closed Graphs on Evolving Data StreamsMining Frequent Closed Graphs on Evolving Data Streams
Mining Frequent Closed Graphs on Evolving Data Streams
 
VAE-type Deep Generative Models
VAE-type Deep Generative ModelsVAE-type Deep Generative Models
VAE-type Deep Generative Models
 
Internet of Things Data Science
Internet of Things Data ScienceInternet of Things Data Science
Internet of Things Data Science
 
Gradient Estimation Using Stochastic Computation Graphs
Gradient Estimation Using Stochastic Computation GraphsGradient Estimation Using Stochastic Computation Graphs
Gradient Estimation Using Stochastic Computation Graphs
 
Deep learning for molecules, introduction to chainer chemistry
Deep learning for molecules, introduction to chainer chemistryDeep learning for molecules, introduction to chainer chemistry
Deep learning for molecules, introduction to chainer chemistry
 
Analysis
AnalysisAnalysis
Analysis
 
Mining Adaptively Frequent Closed Unlabeled Rooted Trees in Data Streams
Mining Adaptively Frequent Closed Unlabeled Rooted Trees in Data StreamsMining Adaptively Frequent Closed Unlabeled Rooted Trees in Data Streams
Mining Adaptively Frequent Closed Unlabeled Rooted Trees in Data Streams
 
Recursive algorithms
Recursive algorithmsRecursive algorithms
Recursive algorithms
 
Large scale logistic regression and linear support vector machines using spark
Large scale logistic regression and linear support vector machines using sparkLarge scale logistic regression and linear support vector machines using spark
Large scale logistic regression and linear support vector machines using spark
 
02 analysis
02 analysis02 analysis
02 analysis
 
Scalable Link Discovery for Modern Data-Driven Applications
Scalable Link Discovery for Modern Data-Driven ApplicationsScalable Link Discovery for Modern Data-Driven Applications
Scalable Link Discovery for Modern Data-Driven Applications
 
STRIP: stream learning of influence probabilities.
STRIP: stream learning of influence probabilities.STRIP: stream learning of influence probabilities.
STRIP: stream learning of influence probabilities.
 
Scaling out logistic regression with Spark
Scaling out logistic regression with SparkScaling out logistic regression with Spark
Scaling out logistic regression with Spark
 
Multinomial Logistic Regression with Apache Spark
Multinomial Logistic Regression with Apache SparkMultinomial Logistic Regression with Apache Spark
Multinomial Logistic Regression with Apache Spark
 
ICML2013読み会 Large-Scale Learning with Less RAM via Randomization
ICML2013読み会 Large-Scale Learning with Less RAM via RandomizationICML2013読み会 Large-Scale Learning with Less RAM via Randomization
ICML2013読み会 Large-Scale Learning with Less RAM via Randomization
 
Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)
 
Unsupervised Deep Learning (D2L1 Insight@DCU Machine Learning Workshop 2017)
Unsupervised Deep Learning (D2L1 Insight@DCU Machine Learning Workshop 2017)Unsupervised Deep Learning (D2L1 Insight@DCU Machine Learning Workshop 2017)
Unsupervised Deep Learning (D2L1 Insight@DCU Machine Learning Workshop 2017)
 
Exploring Optimization in Vowpal Wabbit
Exploring Optimization in Vowpal WabbitExploring Optimization in Vowpal Wabbit
Exploring Optimization in Vowpal Wabbit
 
2014-06-20 Multinomial Logistic Regression with Apache Spark
2014-06-20 Multinomial Logistic Regression with Apache Spark2014-06-20 Multinomial Logistic Regression with Apache Spark
2014-06-20 Multinomial Logistic Regression with Apache Spark
 
Optimizing Deep Networks (D1L6 Insight@DCU Machine Learning Workshop 2017)
Optimizing Deep Networks (D1L6 Insight@DCU Machine Learning Workshop 2017)Optimizing Deep Networks (D1L6 Insight@DCU Machine Learning Workshop 2017)
Optimizing Deep Networks (D1L6 Insight@DCU Machine Learning Workshop 2017)
 

Andere mochten auch

Andere mochten auch (20)

Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
Mock it right! A beginner’s guide to world of tests and mocks, Maciej PolańczykMock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
 
How to apply deep learning to 3 d objects
How to apply deep learning to 3 d objectsHow to apply deep learning to 3 d objects
How to apply deep learning to 3 d objects
 
Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!
 
EuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source projectEuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source project
 
OpenAPI development with Python
OpenAPI development with PythonOpenAPI development with Python
OpenAPI development with Python
 
Analytics Academy 2017 Presentation Slides
Analytics Academy 2017 Presentation SlidesAnalytics Academy 2017 Presentation Slides
Analytics Academy 2017 Presentation Slides
 
Fixing The Sales Forecast
Fixing The Sales ForecastFixing The Sales Forecast
Fixing The Sales Forecast
 
Systematically Improving Sales Forecast Accuracy
Systematically Improving Sales Forecast AccuracySystematically Improving Sales Forecast Accuracy
Systematically Improving Sales Forecast Accuracy
 
IDATE DigiWorld - FTTH global perspective 241017 - Roland Montagne
IDATE DigiWorld - FTTH global perspective 241017 - Roland MontagneIDATE DigiWorld - FTTH global perspective 241017 - Roland Montagne
IDATE DigiWorld - FTTH global perspective 241017 - Roland Montagne
 
The Future of Social Networks on the Internet: The Need for Semantics
The Future of Social Networks on the Internet: The Need for SemanticsThe Future of Social Networks on the Internet: The Need for Semantics
The Future of Social Networks on the Internet: The Need for Semantics
 
Sales forecast
Sales forecastSales forecast
Sales forecast
 
DigiWorld Future Paris-Bernard Ourghanlian-CTO & CS0- Microsoft
DigiWorld Future Paris-Bernard Ourghanlian-CTO & CS0- MicrosoftDigiWorld Future Paris-Bernard Ourghanlian-CTO & CS0- Microsoft
DigiWorld Future Paris-Bernard Ourghanlian-CTO & CS0- Microsoft
 
Predictive Analytics in Telecommunication
Predictive Analytics in TelecommunicationPredictive Analytics in Telecommunication
Predictive Analytics in Telecommunication
 
Improving Forecast Accuracy
Improving Forecast AccuracyImproving Forecast Accuracy
Improving Forecast Accuracy
 
IDATE DigiWorld - FTTH global perspective 241017 Gigabit VF - Roland Montagne
IDATE DigiWorld - FTTH global perspective 241017 Gigabit VF - Roland MontagneIDATE DigiWorld - FTTH global perspective 241017 Gigabit VF - Roland Montagne
IDATE DigiWorld - FTTH global perspective 241017 Gigabit VF - Roland Montagne
 
A Test of B2B Sales Forecasting Methods
A Test of B2B Sales Forecasting MethodsA Test of B2B Sales Forecasting Methods
A Test of B2B Sales Forecasting Methods
 
The State of Broadband: Broadband catalyzing sustainable development. Septemb...
The State of Broadband: Broadband catalyzing sustainable development. Septemb...The State of Broadband: Broadband catalyzing sustainable development. Septemb...
The State of Broadband: Broadband catalyzing sustainable development. Septemb...
 
Broadband 101 Feasibility Studies
Broadband 101 Feasibility StudiesBroadband 101 Feasibility Studies
Broadband 101 Feasibility Studies
 
IDATE DigiWorld -FTTx markets public - Roland MONTAGNE
IDATE DigiWorld -FTTx markets public - Roland MONTAGNEIDATE DigiWorld -FTTx markets public - Roland MONTAGNE
IDATE DigiWorld -FTTx markets public - Roland MONTAGNE
 
Understanding RF Fundamentals and the Radio Design of Wireless Networks
Understanding RF Fundamentals and the Radio Design of Wireless NetworksUnderstanding RF Fundamentals and the Radio Design of Wireless Networks
Understanding RF Fundamentals and the Radio Design of Wireless Networks
 

Ähnlich wie EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME

Svd filtered temporal usage clustering
Svd filtered temporal usage clusteringSvd filtered temporal usage clustering
Svd filtered temporal usage clustering
Liang Xie, PhD
 
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
 
MSc Thesis Defense Presentation
MSc Thesis Defense PresentationMSc Thesis Defense Presentation
MSc Thesis Defense Presentation
Mostafa Elhoushi
 
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and RPranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
PyData
 

Ähnlich wie EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME (20)

timeseries cheat sheet with example code for R
timeseries cheat sheet with example code for Rtimeseries cheat sheet with example code for R
timeseries cheat sheet with example code for R
 
Svd filtered temporal usage clustering
Svd filtered temporal usage clusteringSvd filtered temporal usage clustering
Svd filtered temporal usage clustering
 
Different Models Used In Time Series - InsideAIML
Different Models Used In Time Series - InsideAIMLDifferent Models Used In Time Series - InsideAIML
Different Models Used In Time Series - InsideAIML
 
GDG DevFest Xiamen 2017
GDG DevFest Xiamen 2017GDG DevFest Xiamen 2017
GDG DevFest Xiamen 2017
 
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 ...
 
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
#OSSPARIS19 : Detecter des anomalies de séries temporelles à la volée avec Wa...
 
Forecasting time series powerful and simple
Forecasting time series powerful and simpleForecasting time series powerful and simple
Forecasting time series powerful and simple
 
GDG DevFest Seoul 2017: Codelab - Time Series Analysis for Kaggle using Tenso...
GDG DevFest Seoul 2017: Codelab - Time Series Analysis for Kaggle using Tenso...GDG DevFest Seoul 2017: Codelab - Time Series Analysis for Kaggle using Tenso...
GDG DevFest Seoul 2017: Codelab - Time Series Analysis for Kaggle using Tenso...
 
TMPA-2017: Vellvm - Verifying the LLVM
TMPA-2017: Vellvm - Verifying the LLVMTMPA-2017: Vellvm - Verifying the LLVM
TMPA-2017: Vellvm - Verifying the LLVM
 
Time Series Analysis: Challenge Kaggle with TensorFlow
Time Series Analysis: Challenge Kaggle with TensorFlowTime Series Analysis: Challenge Kaggle with TensorFlow
Time Series Analysis: Challenge Kaggle with TensorFlow
 
ANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series PredictionANN ARIMA Hybrid Models for Time Series Prediction
ANN ARIMA Hybrid Models for Time Series Prediction
 
20191107 breizh data_day
20191107 breizh data_day20191107 breizh data_day
20191107 breizh data_day
 
Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.
 
MSc Thesis Defense Presentation
MSc Thesis Defense PresentationMSc Thesis Defense Presentation
MSc Thesis Defense Presentation
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdf
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
Deep Learning Introduction - WeCloudData
Deep Learning Introduction - WeCloudDataDeep Learning Introduction - WeCloudData
Deep Learning Introduction - WeCloudData
 
Tracking the tracker: Time Series Analysis in Python from First Principles
Tracking the tracker: Time Series Analysis in Python from First PrinciplesTracking the tracker: Time Series Analysis in Python from First Principles
Tracking the tracker: Time Series Analysis in Python from First Principles
 
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and RPranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
 
Unsupervised program synthesis
Unsupervised program synthesisUnsupervised program synthesis
Unsupervised program synthesis
 

Kürzlich hochgeladen

Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
HyderabadDolls
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
HyderabadDolls
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Klinik kandungan
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
nirzagarg
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
gajnagarg
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
HyderabadDolls
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 

Kürzlich hochgeladen (20)

Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbers
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
 

EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME

  • 2. Who am I? ● Machine Learning Engineer ○ Fraud Detection System ○ Software Defect Prediction ● Software Engineer ○ Email Services (40+ mil. users) ○ High traffic server (IPC, network, concurrent programming) ● MPhil, HKUST ○ Major : Software Engineering based on ML tech ○ Research interests : ML, NLP, IR
  • 3. Outline Data Collection Time series Analysis Forecast Modeling Anomaly Detection Naive approach Logging SpeedTest Data preparation Handling time series Seasonal Trend Decomposition Rolling Forecast Basic approaches Stationarity Autoregression, Moving Average Autocorrelation ARIMA Multivariate Gaussian LSTM
  • 7. Anomaly Detection (Naive approach in 2015)
  • 8. Problem definition ● Detect abnormal states of Home Network ● Anomaly detection for time series ○ Finding outlier data points relative to some usual signal
  • 9. Types of anomalies in time series ● Additive outliers
  • 10. Types of anomalies in time series ● Temporal changes
  • 11. Types of anomalies in time series ● Level shift
  • 12. Outline Data Collection Time series Analysis Forecast Modeling Anomaly Detection Naive approach Logging SpeedTest Data preparation Handling time series Seasonal Trend Decomposition Rolling Forecast Basic approaches Stationarity Autoregression, Moving Average Autocorrelation ARIMA Multivariate Gaussian LSTM
  • 13. Logging Data ● Speedtest-cli ● Every 5 minutes for 3 Month. ⇒ 20k observations. $ speedtest-cli --simple Ping: 35.811 ms Download: 68.08 Mbit/s Upload: 19.43 Mbit/s $ crontab -l */5 * * * * echo ‘>>> ‘$(date) >> $LOGFILE; speedtest-cli --simple >> $LOGFILE 2>&1
  • 14. Logging Data ● Log output $ more $LOGFILE >>> Thu Apr 13 10:35:01 KST 2017 Ping: 42.978 ms Download: 47.61 Mbit/s Upload: 18.97 Mbit/s >>> Thu Apr 13 10:40:01 KST 2017 Ping: 103.57 ms Download: 33.11 Mbit/s Upload: 18.95 Mbit/s >>> Thu Apr 13 10:45:01 KST 2017 Ping: 47.668 ms Download: 54.14 Mbit/s Upload: 4.01 Mbit/s
  • 15. Data preparation ● Parse data class SpeedTest(object): def __init__(self, string): self.__string = string self.__pos = 0 self.datetime = None# for DatetimeIndex self.ping = None # ping test in ms self.download = None# down speed in Mbit/sec self.upload = None # up speed in Mbit/sec def __iter__(self): return self def next(self): …
  • 16. Data preparation ● Build panda DataFrame speedtests = [st for st in SpeedTests(logstring)] dt_index = pd.date_range( speedtests[0].datetime.replace(second=0, microsecond=0), periods=len(speedtests), freq='5min') df = pd.DataFrame(index=dt_index, data=([st.ping, st.download, st.upload] for st in speedtests), columns=['ping','down','up'])
  • 18. Data preparation ● Structural breaks ○ Accidental missings for a long period
  • 19. Data preparation ● Handling missing data ○ Only a few occasional cases
  • 20. Handling time series ● By DatetimeIndex ○ df[‘2017-04’:’2017-06’] ○ df[‘2017-04’:] ○ df[‘2017-04-01 00:00:00’:] ○ df[df.index.weekday_name == ‘Monday’] ○ df[df.index.minute == 0] ● By TimeGrouper ○ df.groupby(pd.TimeGrouper(‘D’)) ○ df.groupby(pd.TimeGrouper(‘M’))
  • 21. Patterns in time series ● Is there a pattern in 24 hours?
  • 22. Patterns in time series ● Is there a daily pattern?
  • 23. Components of Time series data ● Trend :The increasing or decreasing direction in the series. ● Seasonality : The repeating in a period in the series. ● Noise : The random variation in the series.
  • 24. Components of Time series data ● A time series is a combination of these components. ○ yt = Tt + St + Nt (additive model) ○ yt = Tt × St × Nt (multiplicative model)
  • 25. Seasonal Trend Decomposition from statsmodels.tsa.seasonal import seasonal_decompose decomposition = seasonal_decompose(week_dn_ts) plt.plot(week_dn_ts) # Original plt.plot(decomposition.seasonal) plt.plot(decomposition.trend)
  • 27. Rolling Forecast from statsmodels.tsa.arima_model import ARIMA forecasts = list() history = [x for x in train_X] for t in range(len(test_X)): # for each new observation model = ARIMA(history, order=order) # update the model y_hat = model.fit().forecast() # forecast one step ahead forecasts.append(y_hat) # store predictions history.append(test_X[t]) # keep history updated
  • 28. Residuals ~ N( , 2 ) residuals = [test[t] - forecasts[t] for t in range(len(test_X))] residuals = pd.DataFrame(residuals) residuals.plot(kind=’kde’)
  • 29. Anomaly Detection (Basic approach) ● IQR (Inter Quartile Range) ● 2-5 Standard Deviation ● MAD (Median Absolute Deviation)
  • 30. Anomaly Detection (Naive approach) ● Inter Quartile Range
  • 31. Anomaly Detection (Naive approach) ● Inter Quartile Range ○ NumPy ○ Pandas q1, q3 = np.percentile(col, [25, 75]) iqr = q3 - q1 np.where((col < q1 - 1.5*iqr) | (col > q3 + 1.5*iqr)) q1 = df[‘col’].quantile(.25) q3 = df[‘col’].quantile(.75) iqr = q3 - q1 df.loc[~df[‘col’].between(q1-1.5*iqr, q3+1.5*iqr),’col’]
  • 32. Anomaly Detection (Naive approach) ● 2-5 Standard Deviation
  • 33. Anomaly Detection (Naive approach) ● 2-5 Standard Deviation ○ NumPy ○ Pandas std = pd[‘col’].std() med = pd[‘col’].median() df.loc[~df[‘col’].between(med - 3*std, med + 3*std), 0] std = np.std(col) med = np.median(col) np.where((col < med - 3*std) | (col < med + 3*std))
  • 34. Anomaly Detection (Naive approach) ● MAD (Median Absolute Deviation) ○ MAD = median(|Xi - median(X)|) ○ “Detecting outliers: Do not use standard deviation around the mean, use absolute deviation around the median” - Christopher Leys (2013)
  • 35. Outline Data Collection Time series Analysis Forecast Modeling Anomaly Detection Naive approach Logging SpeedTest Data preparation Handling time series Seasonal Trend Decomposition Rolling Forecast Basic approaches Stationarity Autoregression, Moving Average Autocorrelation ARIMA Multivariate Gaussian LSTM
  • 36. Stationary Series Criterion ● The mean, variance and covariance of the series are time invariant. stationary non-stationary
  • 37. Stationary Series Criterion ● The mean, variance and covariance of the series are time invariant. stationary non-stationary
  • 38. Stationary Series Criterion ● The mean, variance and covariance of the series are time invariant. stationary non-stationary
  • 40. Differencing ● A non-stationary series can be made stationary after differencing. ● Instead of modelling the level, we model the change ● Instead of forecasting the level, we forecast the change ● I(d) = yt - yt-d ● AR + I + MA
  • 41. Autoregression (AR) ● Autoregression means developing a linear model that uses observations at previous time steps to predict observations at future time step. ● Because the regression model uses data from the same input variable at previous time steps, it is referred to as an autoregression
  • 42. Moving Average (MA) ● MA models look similar to the AR component, but it's dealing with different values. ● The model account for the possibility of a relationship between a variable and the residuals from previous periods.
  • 43. ARIMA(p, d, q) ● Autoregressive Integrated Moving Average ○ AR : A model that uses dependent relationship between an observation and some number of lagged observations. ○ I : The use of differencing of raw observations in order to make the time series stationary. ○ MA : A model that uses the dependency between an observation and a residual error from a MA model. ● parameters of ARIMA model ○ p : The number of lag observations included in the model ○ d : the degree of differencing, the number of times that raw observations are differenced ○ q : The size of moving average window.
  • 44. Identification of ARIMA ● Autocorrelation function(ACF) : measured by a simple correlation between current observation Yt and the observation p lags from the current one Yt-p . ● Partial Autocorrelation Function (PACF) : measured by the degree of association between Yt and Yt-p when the effects at other intermediate time lags between Yt and Yt-p are removed. ● Inference from ACF and PACF : theoretical ACFs and PACFs are available for various values of the lags of AR and MA components. Therefore, plotting ACFs and PACFs versus lags and comparing leads to the selection of the appropriate parameter p and q for ARIMA model
  • 45. Identification of ARIMA (easy case) ● General characteristics of theoretical ACFs and PACFs ● Reference : ○ http://people.duke.edu/~rnau/411arim3.htm ○ Prof. Robert Nau model ACF PACF AR(p) Tail off; Spikes decay towards zero Spikes cutoff to zero after lag p MA(q) Spikes cutoff to zero after lag q Tails off; Spikes decay towards zero ARMA(p,q) Tails off; Spikes decay towards zero Tails off; Spikes decay towards zero
  • 46. Identification of ARIMA (easy case)
  • 47. Identification of ARIMA (complicated)
  • 48. Anomaly Detection (Parameter Estimation) xdown xup xdown xup
  • 49. Anomaly Detection (Multivariate Gaussian Distribution)
  • 50. Anomaly Detection (Multivariate Gaussian) import numpy as np from scipy.stats import multivariate_normal def estimate_gaussian(dataset): mu = np.mean(dataset, axis=0) sigma = np.cov(dataset.T) return mu, sigma def multivariate_gaussian(dataset, mu, sigma): p = multivariate_normal(mean=mu, cov=sigma) return p.pdf(dataset) mu, sigma = estimate_gaussian(train_X) p = multivariate_gaussian(train_X, mu, sigma) anomalies = np.where(p < ep) # ep : threshold
  • 51. Anomaly Detection (Multivariate Gaussian) import numpy as np from scipy.stats import multivariate_normal def estimate_gaussian(dataset): mu = np.mean(dataset, axis=0) sigma = np.cov(dataset.T) return mu, sigma def multivariate_gaussian(dataset, mu, sigma): p = multivariate_normal(mean=mu, cov=sigma) return p.pdf(dataset) mu, sigma = estimate_gaussian(train_X) p = multivariate_gaussian(train_X, mu, sigma) anomalies = np.where(p < ep) # ep : threshold
  • 52. Anomaly Detection (Multivariate Gaussian) import numpy as np from scipy.stats import multivariate_normal def estimate_gaussian(dataset): mu = np.mean(dataset, axis=0) sigma = np.cov(dataset.T) return mu, sigma def multivariate_gaussian(dataset, mu, sigma): p = multivariate_normal(mean=mu, cov=sigma) return p.pdf(dataset) mu, sigma = estimate_gaussian(train_X) p = multivariate_gaussian(train_X, mu, sigma) anomalies = np.where(p < ep) # ep : threshold
  • 53. Outline Data Collection Time series Analysis Forecast Modeling Anomaly Detection Naive approach Logging SpeedTest Data preparation Handling time series Seasonal Trend Decomposition Rolling Forecast Basic approaches Stationarity Autoregression, Moving Average Autocorrelation ARIMA Multivariate Gaussian LSTM
  • 56. Long Short-Term Memory from keras.models import Sequential from keras.layers import Dense from keras.layers import LSTM from sklearn.metrics import mean_squared_error model = Sequential() model.add(LSTM(num_neurons, stateful=True, return_sequences=True, batch_input_shape=(batch_size, timesteps, input_dimension)) model.add(LSTM(num_neurons, stateful=True, batch_input_shape=(batch_size, timesteps, input_dimension)) model.add(Dense(1)) model.compile(loss='mean_squared_error', optimizer='adam') for i in range(num_epoch): model.fit(train_X, y, epochs=1, batch_size=batch_size, shuffle=False) model.reset_states()
  • 57. Long Short-Term Memory ● Will allow to model sophisticated and seasonal dependencies in time series ● Very helpful with multiple time series ● On going research, requires a lot of work to build model for time series
  • 58. Summary ● Be prepared before calling engineers for service failures ● Pythonista has all the powerful tools ○ pandas is great for handling time series ○ statsmodels for analyzing and modeling time series ○ sklearn is such a multi-tool in data science ○ keras is good to start deep learning ● Pythonista needs to understand a few concepts before using the tools ○ Stationarity in time series ○ Autoregressive and Moving Average ○ Means of forecasting, anomaly detection ● Deep Learning for forecasting time series ○ still on-going research ● Do try this at home