Full text
i Time Series Classification for Device Fingerprinting Ana Sofia Tavares Jordão Alves Internship project at a telecommunications and technology company Internship report presented as partial requirement for obtaining the master’s degree in Data Science and Advanced Analytics
ii NOVA Information Management School Instituto Superior de Estatística e Gestão de Informação Universidade Nova de Lisboa TIME SERIES CLASSIFICATION FOR DEVICE FINGERPRINTING by Ana Sofia Tavares Jordão Alves Internship report presented as partial requirement for obtaining the master’s degree in Data Science and Advanced Analytics Advisor: Prof. Doutor Flávio Luis Portas Pinheiro Co Advisor: Hock Ng, Ph.D. September 2020
iii ACKNOWLEDGEMENTS This report reflects the synergy among myself and different players I crossed paths within this journey. In this way, I could not leave this page blank without acknowledging each of them. I would like to start by thanking my supervisor, Professor Flávio Pinheiro, for providing useful inputs and the required guidance to build this document. I should also extend my gratitude to all the professors I encountered in my educational path whose shared expertise somehow contributed to the conclusion of this cycle. To my supervisor at the company, Hock Ng, who accepted this challenge and introduced me to the project and to the telecommunications field and was always available for any question I had despite the geographical distance. I appreciate the data science knowledge and supervision given to me throughout this period. I would also like to thank my manager, Sumathi Mohanselvan, as well as all the members of the team that welcomed me at the company, for the learning experience and the opportunity given to me. In particular, to my colleagues, Tatiane Espindola and Hamid Khosravani, for all the wise words, ideas and interest in this project. Finally, to my parents, Ana and Mário, and my brother Luis, for the endless caring, continuous encouragement and support. To each and every one of you – Thank you!
iv ABSTRACT The telecommunication service providers seek an accurate insight into the devices that are connected within a home network, in order to provide a better in-home experience. In this way, the goal of the internship was to develop a machine learning model for fingerprinting of Amazon devices. This can be translated to a timeseries binary classification problem and assumes an exploration background of understanding the employment of bytes received by the router over time as an indicator of the internet usage to detect the Amazon devices. A feature-based analysis was conducted to make it possible to apply the most common and simple classifiers, which is relevant within a company context. The available data presented some challenges, namely a high imbalance and number of missing values. For this, it was studied several combinations of different techniques to increase the importance of the minority class and to impute the unknown values. In addition, multiple models were trained, whose results were evaluated and compared. The achieved performance of the best model was not considered satisfactory to correctly identify the Amazon devices, which lead to the conclusion that other approaches, algorithms and/or variable(s) need to be considered in a future iteration. The project contributed to a better understanding of the path to take on the identification of the devices and introduced new approaches and reasoning when dealing with similar data as the timeseries in analysis. KEYWORDS Machine Learning; Telecommunications; Time Series; Binary Classification; Supervised Learning; Feature-Based Analysis; Imbalanced Data; Decision Trees; Ensemble Methods; Random Forest; AdaBoost; XGBoost; Logistic Regression; SVMs
v INDEX 1. Introduction .................................................................................................................. 1 1.1. Company Overview ............................................................................................... 2 1.2. The Team and Activities ........................................................................................ 2 1.3. Internship Goals..................................................................................................... 3 2. Theoretical Framework ................................................................................................ 5 2.1. Machine Learning .................................................................................................. 5 2.1.1. Categories of Machine Learning Problems .................................................... 5 2.1.2. Overview of the Machine Learning Process ................................................... 6 2.1.3. Data Preparation ............................................................................................ 6 2.1.4. Feature Engineering ....................................................................................... 7 2.1.5. Imbalanced Dataset ........................................................................................ 7 2.1.6. K-fold Cross Validation ................................................................................... 9 2.1.7. Machine Learning Algorithms ........................................................................ 9 2.1.8. Evaluation Measures .................................................................................... 18 2.2. Time Series .......................................................................................................... 19 2.2.1. Feature-Based Analysis ................................................................................ 20 3. Tools and Technology ................................................................................................. 24 3.1. Tsfresh ................................................................................................................. 24 3.2. Xgboost ................................................................................................................ 25 4. The Project .................................................................................................................. 26 4.1. Timeline ............................................................................................................... 26 4.2. Device Fingerprinting Project .............................................................................. 26 4.2.1. Motivation .................................................................................................... 28 4.2.2. Data Description ........................................................................................... 28 4.2.3. Model and Analysis ...................................................................................... 30 4.2.4. Results and Discussion ................................................................................. 33 4.2.5. Conclusions ................................................................................................... 37 5. Conclusions ................................................................................................................. 38 5.1. Connection to the Master Program .................................................................... 38 5.2. Internship Evaluation .......................................................................................... 38 5.3. Limitations ........................................................................................................... 39 5.4. Lessons Learned .................................................................................................. 39 5.5. Future Work......................................................................................................... 39
vi 6. Bibliography ................................................................................................................ 41 7. Annexes ...................................................................................................................... 44
vii LIST OF FIGURES Figure 1: SMOTE. The axes represent the values of features 𝑥1 and 𝑥2. A) is a point from the minority class where the lines correspond to the distance to the nearest neighbors. B) is a chosen neighbor from the 3 nearest neighbors. C) is the new generated data point.... 8 Figure 2: 3-Fold Cross Validation. In each iteration, the original train data is divided into 3 folds: one is held as the unseen data and the remaining as the train data. After training a model on the train data, the chosen evaluation measure is calculated based on the results of the model on the unseen data. The final performance is given by the average of the values of the chosen evaluation measure along the different iterations. ......................... 9 Figure 3: Decision Tree architecture. From the root node, the observations are divided accordingly with the decision taken on the decision node. The observations on a leaf node will not be further divided................................................................................................ 12 Figure 4: SVM for a 2-class problem. The axes represent the values of the features 𝑥1and 𝑥2. A) and B) are support vectors and the dashed lines correspond to the boundary of the respective class. C) is the decision boundary that maximizes D) the margin. ................. 17 Figure 5: Confusion Matrix for a 2-class problem. The lines of the matrix correspond to the number of observations within the actual class value while the columns represent the number of observations within the respective predicted class value. The values for TN, TP, FN and FP allow to evaluate the correctness of the predictions made by the classifier. . 18 Figure 6: Fourier Transform. The time series function (in black) is decomposed into simpler functions (in blue and grey) with a given frequency and amplitude. .............................. 21 Figure 7: Wavelet transform properties. A) Scaling the wavelet to detect different frequency resolutions. B) Translation of the wavelet over time ...................................................... 22 Figure 8: Tsfresh. The original dataset with the time series of each device is transformed into a dataset with the respective extracted features of each time series. ........................... 25 Figure 9: Example of the time series with a clear pattern of bytes received by the router over time for an Amazon device .............................................................................................. 27 Figure 10: Example of the time series of bytes received by the router over time for a non- Amazon device ................................................................................................................. 27 Figure 11: Number of missing values on the train set. A high number of devices have at least one missing value. ............................................................................................................ 29 Figure 12: Train set data imbalance. Only 5% of devices are Amazon devices. ...................... 30 Figure 13: Example of the overfitting of the decision tree models in the scenarios where SMOTE and ADASYN were followed to balance the data and for different balancing rates.
viii The models have a good performance on the train set and behave poorly on the test set. .......................................................................................................................................... 34 Figure 14: Performance on the test set of each model following a cost-sensitive analysis. The Random Forest model from scenario C is the only model with f1-score above 50%. ..... 35 Figure 15: Precision-Recall curve on test set of the models in scenario C. The tree-based models show better performance than logistic regression and SVM.............................. 35 Figure 16: Evaluation measures on train set and on test set along 5 different seeds. The performance of the best model on the test set does not differs significantly from the performance on the train set. .......................................................................................... 36
ix LIST OF TABLES Table 1: Differences between the scenarios regarding the followed techniques to impute the missing values and to balance the data. .......................................................................... 30 Table 2: Grid search tuned hyperparameters per algorithm. .................................................. 32 Table 3: Number of selected features accordingly with the missing values imputation method. .......................................................................................................................................... 33 Table 4: Confusion matrix of the best model. The number of FN remains high. .................... 36 Table 5: Tuned hyperparameters of the best model. .............................................................. 37
6 The regression problems are also included on the supervised learning category and are related to problems where the target variable is continuous. 2.1.2. Overview of the Machine Learning Process The machine learning process should start by partitioning the original dataset in, at least, two subsets that should be as independent as possible: the training and the test sets. The exploration of the data begins in the training subset where the necessary actions are taken accordingly to the findings (for instance, how to deal with the missing values or inconsistencies in the data). This includes a range of techniques for data preparation and feature engineering, which are done in order to improve the performance of the algorithms. These actions will be reproduced on the test set accordingly with the conclusions taken on the training data. Afterwards, the models are trained observing only the preprocessed data from the train set while the test set data is used later on to evaluate the performance of the trained models in an unseen set of data. The evaluation of the performance of a model relies in a range of evaluation measures, that will be further detailed in this chapter. The chosen model should be the one with the best and stable behavior on the unseen data. 2.1.3. Data Preparation In order to ensure the independence between both the train and test sets, any duplicated observation should be initially removed before the splitting to avoid any data leakage to the test set. Additionally, feature scaling is also important, especially when dealing with distance-based algorithms. When having features with different scales and ranges, the models will attribute a higher importance to the ones with higher values. Feature scaling will change the range of the numerical features, giving an equal weight to each of them. Normalization and standardization are two common methods to perform feature scaling. The first one scales the variables to have values between 0 and 1 (by applying, for instance, Equation 1), while the second one transforms the variables to have mean 0 and standard deviation 1 (by using the Equation 2, for example). 𝑥′= 𝑥−min (𝑥) max(𝑥)−min (𝑥) ( 1 ) 𝑥′= 𝑥−𝜇 𝜎 ( 2 ) Furthermore, one should take into consideration that most of the methods in the machine learning pipeline and algorithms do not deal with the existence of unknown values in the data. Therefore, there are several techniques to perform missing values imputation, such as considering the attribute’s mean value of the respective observation or a global constant (like an impossible value given the context) [3]. To note that when dealing with time series data, is also possible to consider the previous (LOCF) and next values (NOCB) of the series to fulfill the missing ones [4].
7 2.1.4. Feature Engineering Another issue that requires attention is the so-called curse of dimensionality. This happens when the data has too many features, which can bring unnecessary information and can lead the model to overfit. In fact, each added feature will make the model to learn the particularities and the appearance of the training data and consequently, the algorithm learns too well the training data but has a poor performance on unseen data. Thus, when in the presence of a higher dimensionality space, it is more complicated for the algorithm to achieve an optimal solution [5]. The curse of dimensionality has a bigger impact on the algorithms that partition the vector space and rely on computing distances between data points. In order to avoid the curse of dimensionality, one can select the features that are more relevant for the classification problem. There are several methods for feature selection, such as the correlation matrix and the RFE [6]. The correlation matrix allows to visualize the features that are highly correlated with each other and thus not bringing new information to the model. By keeping only one of the features that are correlated, one is performing feature selection. In what concerns to the RFE, it trains an estimator in recursively smaller sets of features [7]. In other words, the estimator is fit on the data and the features are ranked based on their coefficients. Then, the less important feature, i.e. the one with smaller discrimination ability, is discarded, and the model is fit on the remaining features. The process is repeated until a predefined number of features is achieved. In parallel with feature selection, it may also be relevant to perform feature extraction. This consists in creating new useful variables, based on the existing ones and/or on the field knowledge, bringing additional and more relevant information [6]. In this way, the feature extraction can also contribute to feature selection as the new variables can provide a summary of the information contained on the original set of features (which can be later discarded). 2.1.5. Imbalanced Dataset When using real-world data and, in the context of a classification problem, it is common to happen to have more observations of a certain class (usually the negative class), making the dataset imbalanced. In the presence of an imbalanced dataset, one can conduct a cost sensitive analysis, where is possible to assign different weights on the classification errors of each class, instead of the proportional weights assumed by default [8][9]. In this way, the goal is to give a higher penalization (or cost) in the loss function of the classifier when observations from the minority group are misclassified as the model seeks the minimization of the cost. In alternative, under-sampling and oversampling are both techniques that should be taken into consideration to help balancing the data [10]. The under-sampling means to reduce the number of observations of the majority class, by randomly dropping a percentage of them, for example. The oversampling consists of increasing the class with less observations by means of, for instance, repetition of the available observations of this class, SMOTE or ADASYN.
8 2.1.5.1. SMOTE The SMOTE method consists of the creation of ‘artificial’ observations similar to the ones of the class we want to increase the presence. In each iteration, it randomly chooses a data point, 𝑥, belonging to the minority class and one of the k nearest minority class neighbors, 𝑥𝑘. Then, it generates a synthetic data point, 𝑥′, on the line defined between the two instances (see Figure 1). This is done by taking the difference between the two points, multiplying the difference by a random number between 0 and 1 and add it to the selected sample (see Equation 3)[11]. 𝑥′= 𝑥 +𝑟𝑎𝑛𝑑(0,1) × |𝑥 − 𝑥𝑘| ( 3 ) 2.1.5.2. ADASYN The ADASYN approach, follows a similar reasoning to that of SMOTE, but in addition it generates more data for the harder to learn observations [12]. In this way, it starts by defining the neighborhood of each minority instance, which is comprised by both majority and minority observations, and calculates the ratio of dominance of the majority class for each, 𝑟𝑖 (see Equation 4). Then, this ratio will weight on the number of observations to be created in each neighborhood, such that a higher number of synthetic examples will be generated in the neighborhoods with higher dominance of the majority class. The new observations are then generated using the same linear combination between the minority observations within the same neighborhood, as in SMOTE (see Equation 3). 𝑟𝑖= 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑛𝑒𝑖𝑔ℎ𝑏𝑜𝑟𝑠 𝑜𝑓 𝑡ℎ𝑒 𝑚𝑎𝑗𝑜𝑟𝑖𝑡𝑦 𝑐𝑙𝑎𝑠𝑠 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑛𝑒𝑖𝑔ℎ𝑏𝑜𝑟𝑠 ( 4 ) Figure 1: SMOTE. The axes represent the values of features 𝑥1 and 𝑥2. A) is a point from the minority class where the lines correspond to the distance to the nearest neighbors. B) is a chosen neighbor from the 3 nearest neighbors. C) is the new generated data point. A B C 𝑥1 𝑥 2
9 2.1.6. K-fold Cross Validation The k-fold cross validation aims to foresee the behavior of a model on unseen data [13]. As such, it splits the train set into k groups and for each unique group, holds out the respective group as unseen data and fits the model on the observations of the remaining groups (see Figure 2). Afterwards, the model is evaluated on the unseen set and the evaluation measure is kept. In the end, the performance of the model is given by the average value along the groups. In this way, the unseen data sets should resemble the test set and be as independent as possible from the train data, thus any preparation of the data should be made inside the loop. In addition, when using the stratified k-fold cross validation, one can ensure that the unseen set has the same proportion of observations from the minority class as the train set. This procedure is also advantageous when the available data is limited and usually presents less biased estimations of the performance of the model than the simple train-test split method. The k-fold cross validation is commonly performed simultaneously with the optimization of the hyperparameters of the model. In this matter, grid search can be applied to tune the model, where all possible combinations between the hyperparameters values are explored in order to find the configuration that results in the best performance of a model, given an evaluation measure. 2.1.7. Machine Learning Algorithms In what concerns to the machine learning algorithms, there are several ones specific for classification problems purposes. In accordance with the NFL theorem, there is not an algorithm that performs better than the others in a given problem and dataset, so several models should be trained. Below are detailed the ones that are relevant for this project. Unseen Set Train Set Train Set Unseen Set Train Set Train Set Unseen Set Train Set Train Set Original Train Data Iteration 1: Iteration 2: Iteration 3: Evaluation Measure 1 Evaluation Measure 2 Evaluation Measure 3 Final Average Performance Figure 2: 3-Fold Cross Validation. In each iteration, the original train data is divided into 3 folds: one is held as the unseen data and the remaining as the train data. After training a model on the train data, the chosen evaluation measure is calculated based on the results of the model on the unseen data. The final performance is given by the average of the values of the chosen evaluation measure along the different iterations.
10 2.1.7.1. Logistic Regression The logistic regression is a technique with its root on the statistics field, although can be also seen in a machine learning perspective. Following similar reasoning of the linear regression, the logistic regression is considered to be a linear method as it aims to fit a regression to the data. However, it has the particularity of being applied in binary classification problems, being the appropriate method of describing the relationship between one binary dependent variable and one or more independent variables (that can be discrete or continuous) [14]. For this purpose, the logistic regression fits a logistic function to the data, which limits the predictions to assume probability values between 0 and 1 of belonging to the positive class. In order to overcome these boundaries and be able to fit a line where the dependent variable can assume any value (just like in linear regression), the analysis is conducted on the log of the odds space of belonging to the positive class (see Equation 5) instead of the probability scale. This implies that the residuals (distance from the data points to the line) can as well assume values from negative to positive infinity. In this way, it is employed the maximum likelihood in order to find the best fitting line to the data. log(odds)= log ( 𝑝𝑟𝑜𝑏𝑎𝑏𝑖𝑙𝑖𝑡𝑦 1−𝑝𝑟𝑜𝑏𝑎𝑏𝑖𝑙𝑖𝑡𝑦) ( 5 ) The maximum likelihood starts by generating a candidate line on the log of the odds space. When projecting the data points onto this line, one can obtain the respective value of the log of the odds, which can be converted to the probability by means of Equation 6. Once all the probabilities of the data instances are obtained, a logistic regression is defined. Afterwards, it is possible to calculate the log-likelihood of this candidate logistic line by adding all the logs of individual likelihoods of the data points. In this matter, the predicted probability given by the candidate line corresponds to the probability of the data point belonging to the positive class, and thus, the likelihood of an observation belonging to the positive class is the same as the predicted probability, while for an observation of the negative class it corresponds to 1 minus the predicted probability. In this way, a line that better fits the data (and therefore has less misclassified data points) have a higher log of likelihood. Then, a new candidate line on the log of the odds space is drawn by rotating the previous one and the same procedure is followed in order to achieve the log of likelihood of the new candidate. The line on the log of the odds space keeps rotating towards the maximization of log likelihood of the associated logistic line and the best fitting line is the one with higher log likelihood. 𝑝𝑟𝑜𝑏𝑎𝑏𝑖𝑙𝑖𝑡𝑦 = 𝑒log (𝑜𝑑𝑑𝑠) 1+ 𝑒log (𝑜𝑑𝑑𝑠) ( 6 ) The usage of the logistic regression implies the verification of some assumptions such as a binary dependent variable, low multicollinearity (meaning the correlation of the dependent variables should be low) and the existence of a linear relationship between the independent variables and the log of odds. However, when conducting an analysis on a machine learning point of view these assumptions are more flexible as the priority is the performance of the model on unknown data.
11 On the other hand, when interpretation of the obtained regression is relevant, one can obtain the coefficients on the generated line on log of odds space, which can be defined by Equation 7. In this way, the intercept 𝛽0 can be interpreted as the log of odds when all the input variables assume the value 0, while the coefficients 𝛽1,𝛽2,…,𝛽𝑖 can be seen as the effect of one-unit increase of the respective variable, 𝑥1,𝑥2,…,𝑥𝑖, in the log of odds. For better interpretability, it is possible to convert these effects in the log of odds to the odds, by means of 𝑒𝛽 and thus, obtaining the percentual effect on the odds of belonging to the positive class, given a one-unit increase in the respective variable. When in the presence of discrete variables, the algorithm will generate a line for each category, representing the associated log of odds of each one. The coefficients are obtained by Equation 8 (as an example of a binary input), where the first component correspond to the effect of the reference group, while the second one represents how much the non-reference group increases or decreases the odds of belonging to the positive class, on a log scale. To note that to identify if these coefficients are statistically significant for the model, one can additionally perform some statistical tests (which some software automatically calculate with the output of the model). 𝑦 = 𝛽0+ 𝛽1𝑥1+ 𝛽2𝑥2+⋯+𝛽𝑖𝑥𝑖 ( 7 ) log(𝑜𝑑𝑑𝑠 𝑟𝑒𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑔𝑟𝑜𝑢𝑝)𝑥1+log (𝑜𝑑𝑑𝑠 𝑛𝑜𝑛−𝑟𝑒𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑔𝑟𝑜𝑢𝑝 𝑜𝑑𝑑𝑠 𝑟𝑒𝑓𝑒𝑟𝑒𝑛𝑐𝑒 𝑔𝑟𝑜𝑢𝑝 )𝑥2 ( 8 ) Where 𝑥1corresponds to the reference group and 𝑥2to the non-reference group of a binary variable. Moreover, it is possible to ascertain if independent variables used in the model are good indicators of the class to predict by calculating the 𝑅2, which takes the values of the log likelihood of the fitted line and the log-likelihood of the worst fitting line that, on the log scale, corresponds to the log of odds without taking into account any input variable (see Equation 9) [15]. In the same way, one can also obtain the respective p-values with the help of the test statistic given by Equation 10, which follows a 𝜒2 distribution with the degrees of freedom defined by the difference between the number of parameters in both models [16]. 𝑅2= 𝐿𝑜𝑔 𝐿𝑖𝑘𝑒𝑙𝑖ℎ𝑜𝑜𝑑 𝑜𝑓 𝑤𝑜𝑟𝑠𝑡 𝑓𝑖𝑡− 𝐿𝑜𝑔 𝐿𝑖𝑘𝑒𝑙𝑖ℎ𝑜𝑜𝑑 𝑜𝑓 𝑓𝑖𝑡𝑡𝑒𝑑 𝑙𝑖𝑛𝑒 𝐿𝑜𝑔 𝐿𝑖𝑘𝑒𝑙𝑖ℎ𝑜𝑜𝑑 𝑜𝑓 𝑤𝑜𝑟𝑠𝑡 𝑓𝑖𝑡 ( 9 ) 2 × (𝐿𝑜𝑔 𝐿𝑖𝑘𝑒𝑙𝑖ℎ𝑜𝑜𝑑 𝑜𝑓 𝑓𝑖𝑡𝑡𝑒𝑑 𝑙𝑖𝑛𝑒− 𝐿𝑜𝑔 𝐿𝑖𝑘𝑒𝑙𝑖ℎ𝑜𝑜𝑑 𝑜𝑓 𝑤𝑜𝑟𝑠𝑡 𝑓𝑖𝑡) ( 10 ) The logistic regression is compatible with several optimizers for the cost function [17] and has a hyperparameter, C, that aims to control overfitting by penalizing large magnitudes of the parameters. In order to build a cost-sensitive logistic regression, the respective adjusted weights of each class are taken into consideration in the loss function used to optimize the coefficients of the fitted line [18]. Thus, a larger weight will lead to higher errors and therefore to the need of changing the coefficients of the regression to minimize it. Finally, once achieved a best fit model, the predictions are made based on the respective probabilities. In this way, accordingly with the default threshold, if the probability is higher than 0.5 than the observation is predicted as belonging to the positive class, otherwise the prediction falls on the negative class.
12 2.1.7.2. Decision Tree Decision trees are a supervised method that can be used to solve both classification and regression problems. It differs from the remaining models due to its tree-like graphic that comprises of a series of binary questions (sets of if-then-else rules) that when answered in sequence ultimately achieve a prediction. In this way, the decision trees have a particular terminology (see Figure 3) [19]: • A node corresponds to a group of the data that met a particular rule. The first node where the decision tree starts, and thus includes all the observations, is called the root node. This node is subsequently divided into sub-nodes, which can be recursively divided again. A node that originates sub-nodes is known as decision node. Finally, a node that is not divided is called leaf; • Splitting is the process of dividing the observations of a node accordingly to a defined rule; • Branch is a sub-section of the decision tree that includes all the decisions taken from the root node until one leaf; • Pruning is the process of removing sub-nodes. Starting from the root node, the decision tree classifier is built interactively by one split at a time. Each time a node is divided there is a decision on which is the best variable to split on and where in the range of values of the feature to split. The splitting process continues until all the observations in each partition are exclusively of one category or until some stopping criteria is met (such as the maximum depth of the decision tree) [19]. The decision on the splitting attribute is done by a criterion that maximizes the segregation of the target value, this is, that separates the data in a way that the observations at each node are increasingly dominated by just one category. The information gain and the Gini gain are two examples of decision criterions [3]. Root Node Leaf Node Decision Node Leaf Node Leaf Node Figure 3: Decision Tree architecture. From the root node, the observations are divided accordingly with the decision taken on the decision node. The observations on a leaf node will not be further divided.
13 The information gain can be seen as the expected reduction in the target values diversity of the group by splitting the observations accordingly to a certain feature. This can be calculated based on entropy which measures the impurity of the data. The information gain of a particular attribute is computed accordingly with the following Equations 11, 12 and 13 [3]. 𝐺𝑎𝑖𝑛(𝐴)= 𝐸𝑛𝑡(𝐷)−𝐸𝑛𝑡𝐴(𝐷) ( 11 ) Where 𝐸𝑛𝑡(𝐷) = −∑𝑝𝑖𝑙𝑜𝑔2(𝑝𝑖) 𝐶 𝑖=1 ( 12 ) Where 𝐷 is the complete dataset, 𝐶 represents the classes of the target variable, 𝑝𝑖 is the probability of an observation being from the class 𝑖, and 𝐸𝑛𝑡𝐴(𝐷)= ∑|𝐷𝑗| |𝐷|×𝐸𝑛𝑡(𝐷𝑗) 𝑚 𝑗=1 ( 13 ) Where 𝑚 represents the different values that the attribute 𝐴 can assume, |𝐷𝑗| corresponds to the number of observations where the attribute 𝐴 has the value 𝑗, |𝐷| is the length of the dataset and 𝐸𝑛𝑡(𝐷𝑗) is the entropy on the subset of the dataset where the variable 𝐴 has the value 𝑗. In this way the minimum value that entropy can assume is 0, meaning that all the observations belong to one single category, while the maximum value is 1, which can happen when half of the observations belong to one category and the second half to another category [3]. The Gini gain is similar to the information gain but uses the Gini impurity to measure the impurity present in the data. The Gini impurity corresponds to the likelihood of incorrectly classify an observation, when that observation is randomly classified accordingly with the distribution of the target values. The formulas for the computation of the Gini gain of a feature are identical to the ones of the information gain and can be seen in the Equations 14, 15 and 16 [3]. 𝐺𝑎𝑖𝑛(𝐴)= 𝐺𝑖𝑛𝑖(𝐷)−𝐺𝑖𝑛𝑖𝐴(𝐷) ( 14 ) Where 𝐺𝑖𝑛𝑖(𝐷)= 1 − ∑𝑝𝑖 2𝐶 𝑖=1 ( 15 ) And 𝐺𝑖𝑛𝑖𝐴(𝐷)=∑|𝐷𝑗| |𝐷|𝐺𝑖𝑛𝑖(𝐷𝑗 𝑚 𝑗=𝑖 ) ( 16 ) The Gini impurity ranges from 0 to 0.5, with 0 occurring when all observations are from the same category and 0.5 occurring when each category has an equal number of observations. Thus, the decision trees can also be used as a method for feature selection, where the most important features, the ones with higher values of information or Gini gain, appear at the top of the built tree [19].
14 A cost-sensitive tree can be built by taking into account the importance of each class when calculating the splitting criterion, such that a larger weight will have a higher impact on the node purity [20]. In addition, there are various decision tree algorithms where all the process described above is implemented with slight differences (namely in the way of dealing with the different types of variables). An example of an algorithm is the CART which is implemented on the Python library Scikit- Learn and essentially differs from the remaining algorithms as it supports numerical target features [19]. The major advantages of the decision trees are the ease of interpretation, as they can be displayed graphically and are similar to the human decision-making process, and the least effort for data preprocessing. However, decision trees are data sensitive and thus can easily overfit. This drawback can be overcome by means of pruning, which can be achieved by, for example, defining a maximum depth of the tree or a minimum number of observations in each leaf. In this way, having final nodes with a narrow number of observations that denotes very particular cases on the data is prevented. Another solution to control the decision trees data overfitting issue is to use the ensembles methods, as they join the output from several models. 2.1.7.3. Ensemble Methods The ensemble methods of learning consist of combining the decisions of several models in order to improve the classification performance. This is based on the principle that taking into consideration the outputs of a group of weak models can originate a strong model capable of surpassing the performance of an individual one. In other words, it assumes that these independent models can only see a slice of the data but not the entire picture, thus when joined together it is possible to have a broader perspective of the data [13][3]. The ensembles are composed of individual algorithms, known as base learners, which should be as diverse as possible. The classification of a new data tuple is done by the combination, for example the majority, of the predicted classes by each of the base learners. The following are examples of ensemble methods. 2.1.7.3.1. Random Forest The random forest has as its base learner the decision trees. Each of these classifiers is applied on a sub-sample of the original dataset, where the observations are sampled with replacement by default. In addition, at each node it is also randomly selected a predefined number of attributes to determine the split. To note that the base learners are independent from each other. The final scores of a random forest are given by the average of the votes from the classification trees [3]. 2.1.7.3.2. AdaBoost The AdaBoost is an ensemble method that can receive as base learner other algorithms than just decision trees and, as a boosting method, it has the particularity of focus its attention on the misclassified data instances generating dependency between the base classifiers [3].
15 In this way, for each estimator, a sample of observations is selected from the original dataset with replacement. This selection is based on the weight given to each of the data tuples, which at the starting point will be equal for all the observations and then is interactively adjusted accordingly with the classification accuracy obtained by the current estimator (see Equation 17 for the incorrectly classified samples and Equation 18 for the correctly classified samples) and normalized such that the sum is equal to 1. Thus, it is given a higher weight to the tuples where the model failed to predict the class, which gives them a higher probability of being selected as input for the following estimator. Due to this process, there is still a risk of overfitting, as the misclassified samples will increase their presence on the selected observations by means of repetition. 𝑛𝑒𝑤 𝑠𝑎𝑚𝑝𝑙𝑒 𝑤𝑒𝑖𝑔ℎ𝑡 = 𝑐𝑢𝑟𝑟𝑒𝑛𝑡 𝑠𝑎𝑚𝑝𝑙𝑒 𝑤𝑒𝑖𝑔ℎ𝑡× 𝑒𝑐𝑙𝑎𝑠𝑠𝑖𝑓𝑖𝑒𝑟 𝑤𝑒𝑖𝑔ℎ𝑡 ( 17 ) 𝑛𝑒𝑤 𝑠𝑎𝑚𝑝𝑙𝑒 𝑤𝑒𝑖𝑔ℎ𝑡 = 𝑐𝑢𝑟𝑟𝑒𝑛𝑡 𝑠𝑎𝑚𝑝𝑙𝑒 𝑤𝑒𝑖𝑔ℎ𝑡× 𝑒−𝑐𝑙𝑎𝑠𝑠𝑖𝑓𝑖𝑒𝑟 𝑤𝑒𝑖𝑔ℎ𝑡 ( 18 ) Where, 𝑐𝑙𝑎𝑠𝑠𝑖𝑓𝑖𝑒𝑟 𝑤𝑒𝑖𝑔ℎ𝑡 = 1 2 log (1−𝑡𝑜𝑡𝑎𝑙 𝑒𝑟𝑟𝑜𝑟 𝑡𝑜𝑡𝑎𝑙 𝑒𝑟𝑟𝑜𝑟 ) ( 19 ) And 𝑡𝑜𝑡𝑎𝑙 𝑒𝑟𝑟𝑜𝑟 = ∑𝑚𝑖𝑠𝑙𝑎𝑠𝑠𝑖𝑓𝑖𝑒𝑑 𝑠𝑎𝑚𝑝𝑙𝑒𝑠 𝑤𝑒𝑖𝑔ℎ𝑡 ( 20 ) A weight is also assigned to the vote of each classifier based on how well it performed, such that the more accurate the prediction, the higher the weight (see Equations 19 and 20). For each class, the respective scores are added, and the final predicted class is given by the vote with the highest score. 2.1.7.3.3. XGBoost Similar to the AdaBoost, the XGBoost is an ensemble method that applies the concept of boosting and thus, the selection of the subset of observations to learn from is not completely random as the consequent individual model will put more focus on the misclassified data instances with a higher error associated and the final predicted class is a weighted decision of the votes obtained by each individual model as well. The XGBoost is most commonly used with decision trees as base learners. The main differences from the previous presented ensemble methods is that it follows the gradient descent to minimize the loss function and introduces a regularization parameter to prevent overfitting [21] [13].
22 Where 𝑁 is the number of samples and 𝑒−𝑗2𝜋𝑘𝑛 𝑁 is a complex exponential that can be simplified Euler’s formula: 𝑒𝑗𝑥 = cos𝑥 + j sin𝑥 ( 31 ) 𝑋𝑘 = 𝐴𝑘+ 𝐵𝑘𝑗 ( 32 ) On the other hand, the wavelet transformation looks for similarities between a given function (or small wave, in this case the Ricker wavelet [38]) and the time series data, with the particularity of being able to scale and translate the wavelet function, and thus, considers both time and frequency domain (see Figure 7) [36][39]. The scale consists in compressing (generating a high frequency wavelet) or stretching (generating a low frequency wavelet) the wavelet, in order to detect fast and low variations on the signal, respectively. The translation parameter is responsible for the shifting of the wavelet along the time. In this way, for different values of scale, 𝑎, and position, 𝑏, it takes into consideration the value of the signal in the time domain and the wavelet function, and returns the values of the coefficients of the wavelet, 𝐶(𝑎,𝑏) (see Equation 33). A spectrum of magnitudes of the coefficients can be built to better visualize the changes on the original signal over time and in different frequencies. Thus, the original signal can be transformed into several wavelets with different scales and at different positions. 𝐶(𝑎,𝑏) = 1 √𝑎 ∫𝑓(𝑡).𝜓(𝑡−𝑏 𝑎)𝑑𝑡 +∞ −∞ ( 33 ) Where 𝑓(𝑡) is the signal and 𝜓 is the mother wavelet. Due to the high number and diversity of features that can be extracted from a time series, the feature extraction process is usually followed by methods of feature selection. These aim to reduce the number of features to the ones that are the most useful to predict the class that an observation belongs to. For this, they can rely on the discrimination ability or in the relation between the features, for instance. Figure 7: Wavelet transform properties. A) Scaling the wavelet to detect different frequency resolutions. B) Translation of the wavelet over time A B time amplitude time amplitude time amplitude
23 To sum up, when in the presence of a classification problem with time series data, the related work shows that a common approach is to follow a feature-based analysis. This involves extracting features from the time series and then conduct the analysis based on the new variables. In this way, it is possible the usage of conventional machine learning classifiers such as decision trees, ensemble methods, logistic regressions and SVMs. Moreover, the literature also refers to multiple methods to mitigate the presence of problems that may affect the performance of the models, namely the existence of missing values, the imbalance on the data and the overfitting.
24 3. TOOLS AND TECHNOLOGY The support of tools and technologies is essential to perform machine learning tasks. The present project relied majorly on the ones presented throughout the curricular year of the Master’s degree, namely the Jupyter Notebook tool and the Python programming language. On the last one, the following libraries can be highlighted: • SciPy, NumPy, Pandas and Matplotlib mostly for the data analysis of the dataset; • Scikit-Learn which contains a considerable portfolio of implementations of machine learning algorithms, as well as utility functions for data preprocessing. Besides the libraries mentioned above, the tsfresh [35] and XGBoost [22] Python packages were also used, which are further detailed in this chapter. 3.1. TSFRESH Tsfresh is a Python package that performs feature extraction from a time series dataset, with additional support for doing feature selection over the calculated features [40]. In a nutshell, this library comprises of 65 functions to create new variables related with basic statistics, correlations, distribution and Fourier and wavelet transforms. The mean value, number of peaks, quantile and skewness are just some examples of these functions. Thus, the number of final calculated features can be larger than 65 (by default it outputs 794 time series features), considered that for the same function, different values of the parameters are used by default, although there is the option of manually defining these values. The list of all the methods to calculate features as well as their description and parameters can be accessed in the documentation page of the package [35]. For each univariate timeseries present in the dataset, tsfresh calculates the portfolio of features, and then, in order to filter out the irrelevant ones for the classification task, it will additionally perform significance hypothesis tests which will output an array of p-values and, finally, apply the Benjamini Hochberg procedure to control the number of false positives (the ones that accordingly with the pvalue are considered relevant, but they are actually not) [35]. In this way, it is possible to transform the original dataset that contains multiple time series of one or more variables, into a dataset with several features that characterize those series. A visual support of the whole process can be seen in Annexure 1. Currently, there is an alternative to the tsfresh package named hctsa, which was developed for MATLAB (although it is also possible to use it with Python through pyopy). Just like tsfresh, its ultimate goal is to extract features from time-series data, and, for this purpose, it includes around 155 functions that allow to create more than 7700 features, when using different values in the parameters of each one of them. Hctsa also contains visualizations and functions to analyze the results and to support the feature selection process [41][42].
25 Nevertheless, the tsfresh package presents some leverages. Firstly, it can be directly used with Python, the programming language most commonly used for data science at the telecommunications and technology company. Moreover, it is compatible with Scikit-Learn, which implies that it can be easily integrated in machine learning pipelines and it is fast in calculating the features [40]. Taking into consideration that the majority of the data that the telecommunications and technology company deals with has a timestamp, this package is seen as a useful and time saving technology because it creates a diversity of time series features in one single line of code, instead of having to generate them individually. In the present project, the tsfresh was used to perform feature engineering by calculating new features for the network traffic received from each device. In addition, the option of extract the relevant features was used. The transformations on the original dataset can be visualized in Figure 8. In this way, the new variables incorporate the time factor and can later be used as input for the common machine learning classifiers, which will be deepened in the next chapter. 3.2. XGBOOST XGBoost is a library that provides a high-performance implementation for gradient boosting decision trees (see section 2.1.7.3.3.). The introduction of systems and algorithmic optimizations, such as the handling of missing values, the parallel and distributed computing, makes it a scalable and efficient resource [21]. It also has implementations in several programming languages, including Python, where it provides integration with Scikit-Learn [22]. Currently, there are similar libraries to build gradient boosting trees, such as CatBoost [43] and LightGBM [44], that implement slightly different variations of the algorithm, as for instance on the procedures to handle categorical features. The XGBoost library was applied in this project in order to implement the gradient boosting algorithm (XGBoost). Device Time Bytes Received isAmazon 1 T1 Bytes at T1 0 T2 Bytes at T2 0 … … 0 T168 Bytes at T168 0 2 T1 Bytes at T1 1 T2 Bytes at T2 1 … … 1 T168 Bytes at T168 1 … … … … Device Mean Maximum … Skewness isAmazon 1 Mean 1 Maximum 1 … Skewness 1 0 2 Mean 2 Maximum 2 … Skewness 2 1 … … … … … … Figure 8: Tsfresh. The original dataset with the time series of each device is transformed into a dataset with the respective extracted features of each time series. ORIGINAL DATASET RELEVANT EXCTRACTED FEATURES
26 4. THE PROJECT The internship consisted of one single project that aimed to develop a machine learning model for device fingerprinting, which can be translated into a multiple time series classification problem. This section aims to present the details of the project and to explain the whole execution process from the reasoning behind on each decision to the obtained results and final conclusions. 4.1. TIMELINE The project described in the present document lasted for a period of 6 months, which can be split into two phases: • The first half of the period was dedicated to domain knowledge, to research on related work and to define the strategy to take; • The remaining half was reserved to the implementation of the defined strategy and, when needed, to proceed to changes on it, as well as to the analysis of the final results. To be more precise, the domain knowledge included the understanding of the operation of the company’s product, which includes the data collection process, as well as getting familiar to telecommunications related data. The related work had also an important role as timeseries classification problems are not a very common type of data science problem and thus the experience on this topic was limited. Based on this research and after some exploratory data analysis, it was possible to plan the approaches to tackle the problem in hands, being that this was a dynamic process, suffering changes along time, while the implementation was taking place. 4.2. DEVICE FINGERPRINTING PROJECT The project consisted in developing a machine learning model for device fingerprinting, in other words, to associate a certain pattern to a specific device. In particular, the model should be able to classify if a device is from Amazon or not based on the bytes received by the home router over time. The reason why this project targets the Amazon devices instead of devices from any other maker and the focus on the variable bytes received by the router in place of any other available feature, is due to a previously conducted analysis. In accordance to the analysis, some Amazon devices seem to present a pattern, showing regular peaks of bytes received by the router from time to time, what can be considered as ‘stay alive’ messages. Figure 9 shows an example from an Amazon device where this happens. On the other hand, the devices from remaining makers seem to have a more random pattern, as is possible to see on Figure 10. The difference between the patterns is more visible when the devices are always connected to the network. Either way, it is not possible to generalize, this is, to state that these patterns are verified for all the Amazon and non-Amazon devices, as the analysis was conducted on a small sample and on a restricted number of makers. Nevertheless, the analysis may indicate that the variable bytes received could lead to the maker of a device, at least in the case of the Amazon devices.
27 In this way, the main goal is to check if it would be possible to build an accurate machine learning model to identify the Amazon devices, based on the variable bytes received by the router over time. If so, one could recognize these devices more accurately and also have an idea of the most important characteristics that make them distinguishable from the remaining ones, for future exploration and association of a signature pattern to them. This would additionally allow to set an alarm when the expected pattern is not verified, leading to further investigation. Along the process of developing the model, two main challenges can be pointed out: the lack of field data because it was not possible to access to more data for this purpose; and the quality of the data, as, due to the nature of the devices, they can be frequently disconnected, causing a high number of missing values. Regardless of the measures taken to mitigate these challenges, there will always be an impact on the final results obtained. Figure 9: Example of the time series with a clear pattern of bytes received by the router over time for an Amazon device Figure 10: Example of the time series of bytes received by the router over time for a non-Amazon device
28 4.2.1. Motivation The device fingerprinting project has an academic nature and its purpose is to provide more accurate knowledge on which devices are used in each home network to the service providers. Currently, the information on the maker of a device is not always available and thus, it is necessary to find an approach that could provide a truthful identification of the manufacturer of these devices. A solution in study is to develop a model that clearly associates certain characteristics of the internet usage to the Amazon devices. In this way, it would be possible to identify more precisely the devices, at least the ones from Amazon, even when the maker is not trackable. Therefore, the main takeaway of this project will be to verify if a machine learning model that uses the bytes received by the router over time, as an indicator of the network usage of a device, is able to identify the Amazon devices precisely. If successful, the study can be deepened with the analysis of the characteristics that make these devices distinguishable from the remaining ones in order to associate a pattern to them. 4.2.2. Data Description The provided dataset is composed by a total of 3768 observations (or devices) and 169 columns: the binary target, that assumes the value 1 if the respective device is from Amazon and 0 otherwise; and the remaining 168 columns that have the information of the bytes received by the respective router per hour and along one week (from 08/24/2019 to 08/31/2019). The first step taken was the elimination of duplicated information present in the original dataset in order to prevent data leakage, this is, to avoid having the same information simultaneously on the train and test set and/or having several repeated information in the training set. These scenarios can contribute to the lack of diversity, to overfitting in this subset of data and to an unrealistic performance of the model, and therefore, should be mitigated. In this way, it was found 32 rows with duplicated information. None of these devices were from Amazon and a big slice of them consists of constant arrays with the value 0. In sum, these observations hold only 0.85% of the dataset and by being eliminated the original dataset remained with 3736 devices. Afterwards, the next decision taken corresponds to the splitting of the original dataset into the train and the test sets. This was done in a way where the first set holds 70% of the observations (which corresponds to 2615 devices) and the second set holds the remaining 30% of the observations (which corresponds to 1121 devices). In addition, both sets have a similar distribution of the values as well as the same proportion of Amazon devices (around 5%), to avoid, for instance, having a test set only with non-Amazon devices. From this point forward, all the conclusions are taking into consideration only the training set. After the exploratory data analysis, it was possible to check that there is no errors nor inconsistencies in the data, such as negative values. It was also verified that there are devices that present very high values in some hours, but as the respective values were plausible, these observations ended up being considered just as extreme values.
29 At this point, two major risks were detected: a) the high number of missing values and b) the degree of imbalance of the dataset. In what concerns to a), the big majority of the devices have at least one missing value throughout the whole week, as perceived in Figure 11, and there are not devices where all the values are null. Missing values occur when there is no reported value from the router, which can happen when there is a data collection problem from the service provider side, or when the devices are disconnected to the network, either intentionally (for instance, users may disconnect the router when on holidays) or not (for example, in the presence of network failures). However, it is not possible to state the real cause. Given that a high percentage of the observations in the dataset has at least one missing value, dropping these observations did not seem to be a valid solution. In addition, 0 means that no information was exchanged between the device and the router (although the device is connected), and thus it differs from having a null value. Hence, the possibility of fulfilling the missing values with 0 was also discarded. In this way, three solutions were taken into consideration in order to mitigate this problem: 1) fulfill with -1, which is an impossible value with no meaning in this context, representing the value for the missing data, 2) using mean imputation which is a common technique used across many types of problems and datasets, and 3) fulfill with a mix of the previous (LOCF) and next values (NOCB) which is a common technique used in time series data. Regarding b), as it is shown on Figure 12, only 5,12% of the observations belong to Amazon devices. This has an influence in the learning process because the model does not see enough examples from this minority class, and thus it may not learn the characteristics from these devices. Once that it was not possible to obtain more field data to use for this purpose, to minimize the imbalance problem were used methods that aim to create synthetic observations based on the existing data. In this matter, the over-sampling techniques were prioritized over the under-sampling techniques because the last ones have the disadvantage of causing information loss, in particular when used alone, which is something that was avoided as the original dataset is already not very large. In addition, there is also the option of conducting a cost sensitive analysis by defining a specific weight to each class and thus increasing the importance of the minority class on the loss function used by the algorithms, without the need of creating artificial observations. In this way, in order to increase the number of Amazon devices, as well, as to bring diversity into the dataset, the following techniques were taken into consideration: 1) SMOTE, 2) ADASYN and 3) cost sensitive learning (using the class weight option). Figure 11: Number of missing values on the train set. A high number of devices have at least one missing value.
30 Once that these threats to the quality of the data were identified, the analysis can continue with the implementation of the mentioned approaches to soften them and the training phase of the models. 4.2.3. Model and Analysis Given the different combinations of paths that can be pursued to mitigate the problems of having a big number of missing values and an imbalanced dataset, several scenarios were built. The differences between them can be seen in Table 1. For each of the scenarios, the pipeline sequence of steps, which will be detailed below, is similar as well as the trained machine learning algorithms: Decision Trees, Random Forest, Adaboost, XGBoost, Logistic Regression and SVM. Table 1: Differences between the scenarios regarding the followed techniques to impute the missing values and to balance the data. Scenario Missing Values Imputation Technique to balance the dataset A -1 SMOTE B -1 ADASYN C -1 Cost Sensitive D Mean Value SMOTE E Mean Value ADASYN F Mean Value Cost Sensitive G LOCF & NOCB SMOTE H LOCF & NOCB ADASYN I LOCF & NOCB Cost Sensitive Figure 12: Train set data imbalance. Only 5% of devices are Amazon devices.
31 For each of the scenarios above, the splitting of the original dataset was followed by the imputation of the missing values with the respective technique and by the extraction of features from the time series by means of the extract_features() function from tsfresh package (see Chapter 3). The extracted features are from different natures, ranging from basic statistical ones such as mean, minimum and maximum values, to advanced features like the coefficients from the Fourier transformations. Afterwards, a pipeline to prepare the data to input into a model was built. This pipeline is composed of several steps, starting with the selection of the relevant features on the train set (which will be later filtered on the test set). This is accomplished by the tsfresh package’s select_features() function. Then, in the scenarios where SMOTE and ADASYN methods are applied, the variables were normalized before, in order to ensure that all had the same weight (as they rely on distance-based methods which are scale dependent) and inversed again after. When using these methods, it was considered a number of neighbors of 3 and two balance rates: a perfect balance of 50% of observations for both the minority and majority classes; and a balance of 40% of observations for the minority class and remaining 60% for the majority class. Additional steps were added when training logistic regression and SVM: one of feature selection using RFE, applied before SMOTE, in order to reduce the number of selected features to 20 to avoid overfitting and unnecessary complexity; and a step to rescale the data (either normalization or standardization) in order to improve their performance as distances are calculated. To note that it was also tested the performance of these algorithms without these additional options. In addition, care was taken, especially when dealing with Logistic Regression and SVMs, to identify and eliminate any feature that shown a high correlation (> 0.9) with other(s), in order to avoid the multicollinearity problem. The following step of the pipeline comprises of the model’s training phase. Regarding the selected group of algorithms to use, two factors were key: the ease of interpretation of the final results and the variety of exploring different types of relationship (linear and non-linear). In this way, the choice was reduced to tree-based algorithms, Logistic Regression and SVM. As for the tree-based algorithms, these consisted of Decision Tree, Random Forest, AdaBoost and XGBoost; thus, ranging from simpler forms to more complex and high-performance ones. The training phase of the models includes the hyperparameter tuning, which was accomplished by means of stratified k-fold cross validation grid search over a parameter grid. The k-fold cross validation is a procedure to evaluate the performance of the model on unseen data and generally results in less biased estimations. For this, the training set was split into 4 folds, all with the same proportion of observations from the minority class, and for each combination, one-fold was hold out as the validation set and the remaining 3 as the train set. In this way, the pipeline described above was incorporated inside the k-fold process to avoid any possible data leakage to the validation sets created inside the kfold cross validation and thus, to ensure they resemble the independence from the train set as much as possible, just like the test set. To note that whenever features were selected on the train set, the same variables were filtered on the validation set. For each grouping of folds, after the steps from the pipeline were applied, the grid search started to explore the best combination of values for the hyperparameters. To do so, the model was trained on the train set using all possible combinations of hyperparameter’s values, given the defined grid of hyperparameters, and later the performance was evaluated on the respective validation set. The optimization was made in order to maximize the f1- score on the validation set. The grid search then returns the combination of values for the hyperparameters that present the best average performance along the validation, this is the combination that returns the highest average f1-score.
38 5. CONCLUSIONS The project developed during the internship consisted of creating a machine learning model for device fingerprinting, namely, to explore the identification of the Amazon devices based on the bytes received by the router over time in order to associate a pattern with certain characteristics to these devices. However, it was concluded that the best model did not present reasonable results as it could not easily distinguish the Amazon devices from the remaining devices of different makers which can indicate that either these devices in general do not present a particular pattern and/or the variable chosen (bytes received) may not be the best choice for this purpose. Either way, the project allowed the coverage of all data science steps, from the data cleaning to the evaluation of the trained models, as well as the exploration of a feature-based analysis for a time series classification problem. In this chapter, some additional notes on the project and the period of the internship are presented. 5.1. CONNECTION TO THE MASTER PROGRAM The master program provided the foundation knowledge on concepts, techniques, tools and algorithms to apply on the proposed project that covers all the phases from the traditional end-to-end data science process. In this context, it is possible to highlight the following learned takeaways that helped to meet the final goals of the project: • Identification of the type of problem in hands and the algorithms that are the best fit for it; • Build the data science process avoiding common mistakes at each step; • Identification of the problems that affect the data quality, such as the number of missing values, duplicates and the balance of the data, and possible approaches to tackle them; • Identification of problems during the training process of a model, such as overfitting or underfitting, and alternatives to prevent it given the algorithm in training; • Selection of the appropriate evaluation measures of the models’ performance considering the type of problem. 5.2. INTERNSHIP EVALUATION Overall, the internship was an opportunity to apply the data science knowledges presented in the master’s program and to have contact with state-of-the-art tools and technologies, while in the context of a company. In addition, it was also a learning experience as the proposed project consisted of a type of problem (the classification of time series data) that was not explored during the curricular year of the master’s program, which lead to the search of alternative techniques and models that could be applied in this particular case. However, the team was starting to introduce data science in the daily work and thus both the knowhow and the existence of meaningful projects with the available data and in the domain of data science were limited.
39 5.3. LIMITATIONS Due to the nature of the data, having missing values in a considerable number is unavoidable and thus this will have an impact on the quality of the available data. Moreover, the small number of examples of Amazon devices also decreased the quality of the data. The possibility of adding more data could have helped to mitigate the quality issue and allowed the models to observe more examples, however, it was not possible to obtain access to extra field data for this purpose and in useful time. Alongside these, as the project was not a priority some depreciation was felt, and it was difficult to learn the standard data science approaches used in other projects as the team was recent in this area as well. Hence, all of the above points worked in their own way as a limitation while executing the project during the internship. 5.4. LESSONS LEARNED There are some key points learned during the internship and that will be taken into account in future projects. To start, real-world field data is not perfect and thus all the steps taken before inputting it to a model should be carefully carry on as they can bias the final conclusions and one should also consider in this stage that not all the options can be tested and choices need to be made. The domain knowledge is at this point a must in order to understand the data, detect any inconsistency, as well as to identify possible future projects to explore. In addition, one should be aware that the commonly used techniques to prevent issues that the data may present are not always the best fit for the concerned problem and data, while the least favorable alternatives are worth the try and may show surprising results. In what concerns to dealing with time series data, a feature-based analysis seems an interesting approach where feature engineering takes a central role to be able to select simpler (yet powerful) algorithms and consequently ease the training process and the interpretation of the models which is particularly important when in the context of a company. 5.5. FUTURE WORK In line with the conclusions obtained in the present project and the still existing need of accurately identify the devices associated to a router, there are some steps left to be explored in the future. Firstly, this project was focus on a feature-based analysis, hence it could be interesting to study the performance of an approach based on the real values of the time series (without the feature extraction stage) and compare the results with the ones obtained in this project. Secondly, the exploration of different methods, namely for the imbalance present in the data (for example, under-sampling techniques or threshold moving) and for the missing values imputation (in this matter, more complex techniques can be taken into account, such as the interpolation of missing data) are welcomed. Gather more field data can potentially help in both points as well. It could also be relevant to study alternative algorithms than the ones mentioned and a more detailed feature extraction process.
40 Thirdly, one can consider performing small mutations on the scope of the project, such as considering other variable(s) than the bytes received (or add new variables), that may reflect better the existence of a potential pattern of network usage. Expand the classifiers to identify the remaining makers can also be an option for future developments. Lastly, if reasonable results are achieved, it would also be challenging to implement the achievements into the company product.
41 6. BIBLIOGRAPHY [1] T. Mitchell, Machine Learning, vol. 17. 1997. [2] M. Svensson and J. Söderberg, “Machine-learning technologies in telecommunications,” Ericsson Rev. (English Ed., vol. 85, no. 3, pp. 29–33, 2008. [3] J. Han, M. Kamber, and J. Pei, Data mining: Data mining concepts and techniques, 3rd ed. 2012. [4] J. M. Engels and P. Diehr, “Imputation of missing longitudinal data: A comparison of methods,” J. Clin. Epidemiol., vol. 56, no. 10, pp. 968–976, 2003. [5] M. C. Bishop, Pattern Recognition and Machine Learning. Springer-Verlag New York, 2006. [6] B. Ghojogh et al., “Feature Selection and Feature Extraction in Pattern Analysis: A Literature Review,” 2019. [7] J. Goscik and T. Łukaszuk, “Application of the Recursive Feature Elimination and the Relaxed Linear Separability Feature Selection Algorithms To Gene Expression Data Analysis,” Adv. Comput. Sci. Res. Appl., vol. 10, pp. 39–52, 2013. [8] C. X. Ling and V. S. Sheng, “Cost-Sensitive Learning and the Class Imbalance Problem,” Encycl. Mach. Learn., pp. 231–235, 2008. [9] N. Thai-Nghe, Z. Gantner, and L. Schmidt-Thieme, “Cost-sensitive learning methods for imbalanced data,” 2010 Int. Jt. Conf. Neural Networks, pp. 1–8, 2010. [10] M. S. Shelke, P. R. Deshmukh, and V. K. Shandilya, “A Review on Imbalanced Data Handling Using Undersampling and Oversampling Technique,” Int. J. Recent Trends Eng. Res., vol. 3, no. 4, pp. 444–449, 2017. [11] W. P. K. Nitesh V. Chawla, Kevin W. Bowyer, Lawrence O. Hall, “SMOTE: Synthetic Minority Over-sampling Technique,” J. Artif. Intell. Res., no. 16, pp. 321–357, 2002. [12] H. He, Y. Bai, E. A. Garcia, and S. Li, “ADASYN: Adaptive synthetic sampling approach for imbalanced learning,” Proc. Int. Jt. Conf. Neural Networks, no. July 2008, pp. 1322–1328, 2008. [13] F. Chollet, Deep Learning with Python. 2018. [14] J. Peng, K. Lee, and G. Ingersoll, “An Introduction to Logistic Regression Analysis and Reporting,” J. Educ. Res. - J EDUC RES, vol. 96, pp. 3–14, 2002. [15] E. Shtatland, K. Kleinman, and E. Cain, “One more time about R2 measures of fit in logistic regression,” NESUG 15 Proc., vol. 15, 2002. [16] V. Bewick, L. Cheek, and J. Ball, “Statistics review 14: Logistic regression,” Crit. Care, vol. 9, pp. 112–118, 2005. [17] “Linear Models.” [Online]. Available: https://scikitlearn.org/stable/modules/linear_model.html#logistic-regression. [Accessed: 19-Dec-2019]. [18] G. King and L. Zeng, “Logistic Regression in Rare Events Data,” Polit. Anal., vol. 9, 2002. [19] L. Rokach and O. Maimon, “Decision Trees,” in Data Mining and Knowledge Discovery
42 Handbook, O. Maimon and L. Rokach, Eds. Boston, MA: Springer US, 2005, pp. 165–192. [20] Kai Ming Ting, “An instance-weighting method to induce cost-sensitive trees,” IEEE Trans. Knowl. Data Eng., vol. 14, no. 3, pp. 659–665, May 2002. [21] T. Chen and C. Guestrin, “XGBoost: A Scalable Tree Boosting System,” 2016, pp. 785–794. [22] “xgboost Documentation.” [Online]. Available: https://xgboost.readthedocs.io/en/latest/index.html. [Accessed: 16-Jun-2020]. [23] T. Evgeniou and M. Pontil, “Support Vector Machines: Theory and Applications,” 2001, vol. 2049, pp. 249–257. [24] A. Iranmehr, H. Masnadi-Shirazi, and N. Vasconcelos, “Cost-sensitive support vector machines,” Neurocomputing, vol. 343, pp. 50–64, 2019. [25] J. Brank, M. Grobelnik, N. Milic-Frayling, and D. Mladenic, “Feature Selection Using Support Vector Machines,” WIT Trans. Inf. Commun. Technol., vol. 28, 2002. [26] K. Buza, “Time series classification and its applications,” ACM Int. Conf. Proceeding Ser., no. June, 2018. [27] S. Kotsiantis, D. Kanellopoulos, and P. Pintelas, “Handling imbalanced datasets : A review,” GESTS Int. Trans. Comput. Sci. Eng., vol. 30, 2006. [28] A. Nanopoulos, R. Alcock, and Y. Manolopoulos, “Feature-based Classification of Time-series Data,” Int. J. Comput. Res., vol. 0056, 2001. [29] R. Devaki and V. Kathiresan, “Credit Card Fraud Detection using Time Series Analysis,” IJCA Proc. Int. Conf. Simulations Comput. Nexus, vol. ICSCN, no. 3, pp. 8–10, 2014. [30] N. Mehdiyev, J. Lahann, A. Emrich, D. Enke, P. Fettke, and P. Loos, “Time Series Classification using Deep Learning for Process Planning: A Case from the Process Industry,” Procedia Comput. Sci., vol. 114, pp. 242–249, 2017. [31] S. Dheepadharshani, S. Anandh, K. B. Bhavinaya, and R. Lavanya, “Multivariate time-series classification for automated fault detection in satellite power systems,” Proc. 2019 IEEE Int. Conf. Commun. Signal Process. ICCSP 2019, pp. 814–817, 2019. [32] R. J. Hyndman and G. Athanasopoulos, Forecasting: principles and practice. OTexts, 2014. [33] A. Nanopoulos, R. Alcock, and Y. Manolopoulos, “Feature-based Classification of Time-series Data,” Int. J. Comput. Res., vol. 10, pp. 49–61, 2001. [34] L. Ge and L.-J. Ge, “Feature extraction of time series classification based on multi-method integration,” Optik (Stuttg)., vol. 127, no. 23, pp. 11070–11074, 2016. [35] M. Christ and Blue Yonder GmbH, “tsfresh Documentation,” 2018. [Online]. Available: https://tsfresh.readthedocs.io/en/latest/. [Accessed: 15-Dec-2019]. [36] C. Herff and D. J. Krusienski, “Extracting Features from Time Series,” in Fundamentals of Clinical Data Science, P. Kubben, M. Dumontier, and A. Dekker, Eds. Cham: Springer International Publishing, 2019, pp. 85–100. [37] P. J. Olver, Introduction to Partial Differential Equations. Springer International Publishing, 2013.
43 [38] Y. Wang, “Frequencies of the Ricker wavelet,” GEOPHYSICS, vol. 80, pp. A31–A37, 2015. [39] A.-H. Najmi, J. Sadowsky, O. Morlet, and W. Transform, “The Continuous Wavelet Transform and Variable Resolution Time-Frequency Analysis,” vol. 18, 1997. [40] M. Christ, N. Braun, J. Neuffer, and A. W. Kempa-Liehr, “Time Series FeatuRe Extraction on basis of Scalable Hypothesis tests (tsfresh – A Python package),” Neurocomputing, vol. 307, pp. 72–77, 2018. [41] “hctsa package.” [Online]. Available: https://hctsa-users.gitbook.io/hctsa-manual/. [Accessed: 15-Dec-2019]. [42] B. D. Fulcher and N. S. Jones, “hctsa: A Computational Framework for Automated Time-Series Phenotyping Using Massive Feature Extraction,” Cell Syst., vol. 5, no. 5, pp. 527-531.e3, 2017. [43] “CatBoost Documentation.” [Online]. Available: https://catboost.ai/docs/. [Accessed: 01-Aug- 2020]. [44] “LightGBM Documentation.” [Online]. Available: https://lightgbm.readthedocs.io/en/latest/. [Accessed: 01-Aug-2020].
44 7. ANNEXES Annexure 1: tsfresh’s process to extract relevant features Source: https://tsfresh.readthedocs.io/en/latest/text/feature_filtering.html Accessed: 19-Dec-2019
Page | i