scieee AI-readable full text Open interactive document viewer

Unsupervised Learning Applied to the Segmentation of Users of Online Gambling Platforms in Portugal - The effects of the Covid-19 Pandemic on User Behavior and Segmentation

Lannes, Leonardo Motta Perazzo

Abstract

Online gambling has become an increasingly relevant activity in the last years and is now available through a wide variety of technologies and platforms. This can be seen as an important addition to the entertainment industry since it has the potential of generating great economic impacts. The phenomenon, however, is not free of concerns considering that, like in any other type of gambling activities, online gamblers are susceptible to developing behavioral addiction. This has become a reason of concern to many governmental bodies around the world which are studying this issue due to its social impacts on the population. In this context machine learning algorithms can be applied to understand the behavior of online gamblers and to identify the characteristics of gambling addiction. This work project has the objective of segmentizing users of online gambling platforms in Portugal according to the tendency of these users to have compulsive gambling behavior. It also intends to evaluate the impacts of the Covid-19 pandemic on online gambling addiction by analyzing changes in user segmentation during the initial periods of the pandemic. This will be done by applying unsupervised learning algorithms, specifically K-Means and Self-Organizing Maps and by comparing user clusters from the years 2019 and 2020.

Full text

i Unsupervised Learning Applied to the Segmentation of Users of Online Gambling Platforms in Portugal Leonardo Motta Perazzo Lannes The effects of the Covid-19 Pandemic on User Behavior and Segmentation Project Work presented as partial requirement for obtaining the Master’s degree in Advanced Analytics ii NOVA Information Management School Instituto Superior de Estatística e Gestão de Informação Universidade Nova de Lisboa UNSUPERVISED LEARNING APPLIED TO THE SEGMENTATION OF USERS OF ONLINE GAMBLING PLATFORMS IN PORTUGAL The Effects of the Covid-19 Pandemic on User Behavior and Segmentation by Leonardo Motta Perazzo Lannes Project Work presented as partial requirement for obtaining the Master’s degree in Advanced Analytics Advisor: Mauro Castelli, Ph.D. Co Advisor: Fernando Peres November 2021 iii DEDICATION I would like to dedicate this thesis to my wonderful family. To my wife and daughter, who were always so supportive and understanding during the time in which I was committed to my studies. And to my mother and father, who have always encouraged me to pursue my objectives in life. Thank you. iv ACKNOWLEDGEMENTS I would like to thank my thesis advisers, Fernando Peres, and Mauro Castelli. Both were always available when I needed guidance and constantly helped me with interesting insights to improve this work. v ABSTRACT Online gambling has become an increasingly relevant activity in the last years and is now available through a wide variety of technologies and platforms. This can be seen as an important addition to the entertainment industry since it has the potential of generating great economic impacts. The phenomenon, however, is not free of concerns considering that, like in any other type of gambling activities, online gamblers are susceptible to developing behavioral addiction. This has become a reason of concern to many governmental bodies around the world which are studying this issue due to its social impacts on the population. In this context machine learning algorithms can be applied to understand the behavior of online gamblers and to identify the characteristics of gambling addiction. This work project has the objective of segmentizing users of online gambling platforms in Portugal according to the tendency of these users to have compulsive gambling behavior. It also intends to evaluate the impacts of the Covid-19 pandemic on online gambling addiction by analyzing changes in user segmentation during the initial periods of the pandemic. This will be done by applying unsupervised learning algorithms, specifically K-Means and Self-Organizing Maps and by comparing user clusters from the years 2019 and 2020. KEYWORDS Artificial Intelligence; Big Data; Clustering; Data Science; Machine Learning; Segmentation; Unsupervised Learning vi INDEX 1. Introduction .................................................................................................................. 1 1.1. Objectives .............................................................................................................. 2 1.2. Research Questions ............................................................................................... 2 1.3. Structure ................................................................................................................ 3 2. Theoretical Background ................................................................................................ 4 2.1. Artificial Intelligence and Machine Learning ......................................................... 4 2.1.1. Supervised Learning ....................................................................................... 4 2.1.2. Unsupervised Learning ................................................................................... 4 2.1.3. Semi-supervised Learning .............................................................................. 5 2.1.4. Reinforcement Learning ................................................................................. 5 2.2. Big Data .................................................................................................................. 5 2.3. Data Preparation and Preprocessing ..................................................................... 6 2.3.1. Outlier Treatment ........................................................................................... 6 2.3.2. Missing Values ................................................................................................ 8 2.3.3. Rescale Data ................................................................................................... 8 2.3.4. Feature Selection ............................................................................................ 9 2.3.5. Feature Engineering ..................................................................................... 11 2.4. Clustering Techniques ......................................................................................... 12 2.4.1. Hierarchical Methods ................................................................................... 12 2.4.2. Partitional Methods...................................................................................... 14 2.4.3. Variations of K-Means .................................................................................. 19 2.4.4. Self-Organizing Maps (SOM) ........................................................................ 20 2.4.5. Combination Methods.................................................................................. 22 2.5. Profiling ................................................................................................................ 22 2.5.1. Radar Chart ................................................................................................... 23 3. Cluster Analysis ........................................................................................................... 24 3.1. Cluster Analysis for 2019 Data ............................................................................ 25 3.1.1. 2019 Data Loading and Initial Analysis ......................................................... 25 3.1.2. 2019 Data Preparation ................................................................................. 29 3.1.3. Implementation of Clustering Techniques to 2019 Data ............................. 35 3.1.4. Model Selection for 2019 Data .................................................................... 46 3.1.5. Analysis of the Selected Model and Profiling ............................................... 48 vii 3.2. Cluster Analysis for 2020 Data And Comparison with Data From 2019 ............. 51 3.2.1. 2020 Data Loading and Preparation ............................................................. 51 3.2.2. Application of the Clustering Model to the 2020 Data ................................ 52 3.3. Cluster Shifts Between 2019 and 2020 ............................................................... 55 4. Results and Discussions .............................................................................................. 57 4.1. Answering Research Questions ........................................................................... 58 5. Recommendations for Future Work ........................................................................... 59 6. Bibliography ................................................................................................................ 60 viii LIST OF FIGURES Figure 2. 1: Boxplot .................................................................................................................... 7 Figure 2. 2: The Curse of Dimensionality ................................................................................. 10 Figure 2. 3: Heatmap of Correlation Matrix ............................................................................. 11 Figure 2. 4: Dendrogram .......................................................................................................... 12 Figure 2. 5: K-Means Algorithm ................................................................................................ 15 Figure 2. 6: Elbow Graph .......................................................................................................... 16 Figure 2. 7: Silhouette Analysis for K-Means on sample data with K=2 .................................. 17 Figure 2. 8: Silhouette Analysis for K-Means on sample data with K=6 .................................. 18 Figure 2. 9: Structural model of SOM ....................................................................................... 20 Figure 2. 10: Neurons of the Output Layer Space .................................................................... 21 Figure 2. 11: Example of a Radar Chart .................................................................................... 23 Figure 3. 1: Distribution of Betting Volume in 2019 ................................................................ 24 Figure 3. 2: Variation of attributes during 2019 ...................................................................... 27 Figure 3. 3: Pearson Correlation Matrix of Dataset Variables ................................................. 32 Figure 3. 4: Boxplots of Selected Variables .............................................................................. 34 Figure 3. 5: Python code for Outlier Transformation ............................................................... 35 Figure 3. 6: Elbow Graph of Model 1 ....................................................................................... 36 Figure 3. 7: Elbow Graph of Model 2 ....................................................................................... 37 Figure 3. 8: Elbow Graph for Model 3 ...................................................................................... 39 Figure 3. 9: Elbow Graph of Model 4 ....................................................................................... 40 Figure 3. 10: Elbow Graph for Model 5 .................................................................................... 41 Figure 3. 11: Elbow Graph for Model 6 .................................................................................... 42 Figure 3. 12: Elbow Graph for Model 7 .................................................................................... 43 Figure 3. 13: BMU Hits View for Model 8 ................................................................................. 45 Figure 3. 14: Hits Maps for Model 8 ......................................................................................... 45 Figure 3. 15: Silhouette Plot for Model 6 (with 6 clusters) ...................................................... 47 Figure 3. 16: Silhouette Plot for Model 7 ................................................................................. 48 Figure 3. 17: Distribution of Cluster 4 by Entity ....................................................................... 50 Figure 3. 18: Elbow Graph for Model 7 (2020)......................................................................... 53 ix LIST OF TABLES Table 3. 1: List of Variables in 2019 CSV File ............................................................................ 25 Table 3. 2: Number of records of each Entity .......................................................................... 26 Table 3. 3: Average Balance with Outliers ............................................................................... 28 Table 3. 4: Average Balance without outliers .......................................................................... 28 Table 3. 5: New Features .......................................................................................................... 29 Table 3. 6: Attributes of aggregated dataset ........................................................................... 30 Table 3. 7: Distribution of users according to frequency of play ............................................. 31 Table 3. 8: Percentiles of AMOUNT and BALANCE Variables ................................................... 33 Table 3. 9: Centroids of Model 1 .............................................................................................. 37 Table 3. 10: Centroids of Model 2 ............................................................................................ 38 Table 3. 11: Centroids of Model 3 ............................................................................................ 39 Table 3. 12: Centroids of Model 4 ............................................................................................ 40 Table 3. 13: Centroids for Model 5 .......................................................................................... 41 Table 3. 14: Centroids for Model 6 with 4 Clusters.................................................................. 42 Table 3. 15: Centroids for Model 6 with 5 Clusters.................................................................. 42 Table 3. 16: Centroids for Model 6 with 6 Clusters.................................................................. 42 Table 3. 17: Centroids for Model 7 .......................................................................................... 44 Table 3. 18: Centroids for Model 8 .......................................................................................... 46 Table 3. 19: Silhouette Scores of the Models .......................................................................... 46 Table 3. 20: Centroids for Model 7 .......................................................................................... 48 Table 3. 21: Number of Records in Each Cluster of Model 7 ................................................... 49 Table 3. 22: List of Profiles ....................................................................................................... 49 Table 3. 23: Proportional Distribution of Clusters by Entity .................................................... 50 Table 3. 24: Distribution of users according to frequency of play (2020) ............................... 52 Table 3. 25: Centroids for Model 7 (2020) ............................................................................... 53 Table 3. 26: Number of Records in Each Cluster of Model 7 (2020) ........................................ 53 Table 3. 27: List of Profiles (2020) ............................................................................................ 54 Table 3. 28: Proportional Distribution of Clusters by Entity (2020) ......................................... 54 Table 3. 29: Cluster Shifts ......................................................................................................... 55 6 2.3. DATA PREPARATION AND PREPROCESSING For the execution of any data related projected it is pivotal to perform certain procedures that will guarantee its quality. The quality of data can be measured by numerous factors such as accuracy, completeness, and consistency, all of which can be affected by faulty collection instruments, human or computer errors, technology limitations or unavailability (Han, Kamber, & Pei, 2012). Besides the procedures to improve data quality, other actions might be necessary to ensure data usability such as standardization and dimensionality reduction. 2.3.1. Outlier Treatment Outliers can be thought of as observations with significantly deviating characteristics (Madsen, 2018). In a ML model, if these observations are very extreme, they might interfere inappropriately with the results generated by the model. In an unsupervised learning model, for instance, outliers can generate individual clusters for only an isolated group of observations. In supervised learning models, outliers can cause severe deviations in the model’s predictions. Thus, it is important to perform some sort of outlier treatment to ensure the data is appropriate for training a model. Since the definition of what is a significant deviation is subjective, there are a few methods to deal with outlier detection. Depending on what the assumptions are, regarding the definition of outliers versus the rest of the data, outlier detection can be classified in two types: proximity-based methods, and statistical methods (Han, Kamber, & Pei, 2012). The former, considers objects as outliers when their locality is sparsely populated (Aggarwal, 2017). The latter, applies simple and powerful statistical techniques for the screening of outliers (Alam, 2020). For the purposes of this project, considering that it will be more relevant to identify extreme values, statistical methods will be discussed at more length and two specific methods will be detailed. The Z-Score is a parametric outlier detection method that assumes a gaussian distribution of the data and measures how distant the observation is from the mean (measured in standard deviations) (Widmann & Heine, 2018). In this method values that have a Z-Score higher or lower than predetermined limits are considered outliers. The Z-Score is calculated with the following formula: The Boxplot method is non-parametric statistical method for identifying outliers, since it does not assume the data has a normal distribution. It explores the concept of interquartile range (IQR) which is the difference between the 1st quartile (25th percentile) and 3rd quartile (75th percentile) of the data (Alam, 2020). Values greater than the upper bound or smaller than the lower bound are considered outliers. These boundaries can be calculated with the following formulas: 7 upper bound = Q3 + 1,5 * IQR lower bound = Q1 – 1,5* IQR Where Q1 and Q3 represent the values of the 1st and 3rd quartiles of the data and IQR represents the difference between Q1 and Q3. The Boxplot method is considered the default method to identify outliers in univariate data (Madsen, 2018). It has a graphical representation that helps understanding these concepts and its boundaries. This can be visualized in Figure 2.1. Figure 2. 1: Boxplot (Galarnyk, 2018) Identifying the outliers, however, is just the first step in outlier treatment. The next step is deciding what to do with these outliers. And in this case, there are three main possibilities to consider (Birkett, 2019): 1. Keep the outliers. 2. Remove the outliers. 3. Change their values to something that better represents the data, such as trimming extreme values and replacing them by percentiles (Birkett, 2019). The choice of one of these alternatives may greatly impact a project and the decision must take into consideration the specificities of the data at hand. 8 2.3.2. Missing Values Sometimes the data that has been made available for analysis has some missing values and these could be present in just a few observations or, even, in all the observations of the dataset. This anomaly can be present in one or more features and may cause trouble since some machine learning methods do not work with missing features (Géron, 2019). Other methods might generate inconsistent results if the proportion of data with missing values is extremely elevated. To deal with this problem there are different alternatives: 1. Delete all the records (observations) of the dataset that have missing values in at least one of their attributes. 2. Delete all the attributes in the dataset that have missing values in at least one of the observations. 3. Impute the missing values present in the dataset according to some sort of criterion. In this case the same criterion can be applied to all attributes, or it can be analyzed case by case, in order to apply the appropriate changes for each one. With respect to this last alternative, there are some possibilities in which missing values can be imputed. Firstly, it is possible to fill in missing values using statistical properties such as mean, median or mode. It is also possible to fill in missing values by applying algorithms that search for the records that are closest to the one that has missing values. And finally, regression can be applied by considering the missing values as dependent variables. 2.3.3. Rescale Data It is common for the various attributes of a dataset to be in different scales. However, most machine learning algorithms work better if all features are in the same scale. Otherwise, the algorithm could consider a few of the attributes as more relevant to the problem just because it has naturally higher numbers than some of the other features when, in fact, sometimes it could be quite the opposite. For this reason, there are some alternatives through which data can be rescaled. 1. Normalization: rescales all the attributes to a range between 0 and 1 (Brownlee, 2016). The following formula defines this kind of transformation: 𝑋′= 𝑋− 𝑋 𝑋 𝑋 Where Xmin and Xmax correspond to the minimum and maximum values encountered in the dataset. 9 2. Standardization: transforms attributes that have a Gaussian distribution into a standard Gaussian Distribution with a mean of 0 and a standard deviation of 1 (Brownlee, 2016). The following formula defines this kind of transformation: 𝑋′=𝑋− µ 𝜎 Where µ is the mean of the values and σ is the standard deviation. The choice of which type of data transformation to apply is not always simple. Normalization is usually better when the data does not follow a Gaussian Distribution and since Standardization does not have boundaries, it will not affect outliers. Anyhow, sometimes it is necessary to apply both transformations to the data and compare the performances (Bhandari, 2020). 2.3.4. Feature Selection Frequently, the excess of features in a dataset is prejudicial to machine learning models. It is the opposite of what happens with the number of observations, where the algorithms benefit from having more data available. This problem is referred to as the Curse of Dimensionality, meaning that it can be necessary to perform feature selection in order retain only the most relevant features for the purposes of training a model (Géron, 2019). The curse of dimensionality arises from the fact that irrelevant features can make it more difficult for the algorithms to identify interesting patterns since the data becomes sparser. These patterns would, otherwise, be more transparent in a lower dimensional space (Patel, 2019). Also relevant is the fact that an exaggerated number of features can make the algorithm unbearably computationally expensive. Specifically for unsupervised learning techniques, the addition of more dimensions to the data can make every observation in the dataset seem equidistant from all the others, since most algorithms use distance measures to identify similarities in the data (Yiu, 2019). This makes it harder to identify any significant clusters in the data. Figure 2.2 below is a simple example of this since it demonstrates that with only one dimension (one feature) it is very clear that the data can be divided into two clusters. However, when a new feature is considered, each of the data points seem to be isolated from the others and form a cluster of their own. 10 Figure 2. 2: The Curse of Dimensionality One method of evaluating attributes that can be disregarded is to consider the correlation between each of the features of the dataset. Attributes can be considered redundant if they can be derived from another set of attributes (Han, Kamber, & Pei, 2012). If a dataset has a great number of correlated attributes, ML algorithms that are applied to it might suffer bias towards those attributes and they could possibly end up contributing more to the results than what would be appropriate. However, in order to perform this type of evaluation it is necessary to quantify the correlations between each pair of variables. This process must take into consideration the types of attributes that are present in the dataset. For the purposes of this project only two types of attributes will be considered: categorical and continuous values. The former, represents values that have a finite number of distinct categories such as education level or gender and can be represented either by words or numbers. The latter, represents values that can have an infinite number of values such as salary or price. When analyzing correlation between attributes, different approaches must be applied, depending on the types of each one. - Correlation between two categorical attributes: A statistical test named Chi-squared test is applied to identify similarities or differences (Kumar, 2021) - Correlation between continuous and categorical attributes: If the categorical attribute is binary, a statistical test named T-test must be applied. If the categorical variable can have more than two possible values, then an ANOVA (Analysis of Variance) test must be applied (Kumar, 2021). - Correlation between two continuous attributes: In this case, correlation statistical tests can be used. The most common techniques are Pearson Correlation and Spearman Rank Correlation, both of which define correlation values between [-1,1], where proximity to 1 denotes positive correlation and proximity to -1 denotes negative correlation (Kumar, 2021). A positive correlation indicates that when one attribute increases, so does the other. A negative correlation indicates that when one attribute increases, the other decreases. These correlation values can all be viewed simultaneously through what is referred to as a heatmap of correlation matrix, as showed in Figure 2.3, below. This type of visualization indicates 11 through the intensity of the colors how strong is the correlation between each pair of attributes. Figure 2. 3: Heatmap of Correlation Matrix (Kho, 2019) 2.3.5. Feature Engineering Feature engineering is a mechanism by which new attributes are created based on the ones that are already available. This is something that could be pivotal in some scenarios since machine learning algorithms are only as good as the features that enable it to separate the data points in the feature space (Patel, 2019). There are many possibilities to consider in the creation of new attributes. Most of these options refer to the generation of categorical variables, such as in the following examples: - The prefix of a person’s name can be utilized to determine the gender of that person. - City names can be grouped into regions or countries. - Time of day can be used to segregate the data into periods of the day such as morning, afternoon, and night. - Dates can be separated into weekdays and weekends. - Continuous values can be aggregated into groups of delimited bins, each one representing a category. Nonetheless, feature engineering can also be applied to create new continuous variables. One example would be the determination of the age or time of usage of an observation, based on a birthday date or any other raw date. 12 Finally, feature encoding is a process in which categorical attributes are transformed into numerical variables. This is necessary because most ML algorithms do not work well with categorical variables (Kumar, Feature Engineering — deep dive into Encoding and Binning techniques, 2020). As an example, in a dataset where one of the attributes represents gender, the words Male and Female would be substituted by the numbers 0 and 1. 2.4. CLUSTERING TECHNIQUES Clustering techniques have the objective of classifying observations or data items into groups (clusters) based on similarities (Jain, Murty, & Flynn, 1999). It is useful in exploratory pattern analysis and ML situations that involve segmentation and pattern classification (Jain, Murty, & Flynn, 1999). As such, these techniques are appropriate for unsupervised learning problems, that is, situations in which the data has not been previously labeled. There are a great variety of clustering techniques that have been developed and tested. The choice of the best technique for a specific problem depends on the characteristics of the problem and of the data to be used. Three common clustering methods will be discussed in this section: Hierarchical Methods, Partitional Methods and Self-Organizing Maps. 2.4.1. Hierarchical Methods Hierarchical methods of data clustering separate the data into groups at different levels that represent a hierarchy or a “tree” of clusters. This type of technique is useful for data summarization and visualization since each cluster can be divided into smaller subgroups or grouped up with similar groups (Han, Kamber, & Pei, 2012). The implementation of hierarchical clustering does not require a previous definition of the number of clusters the data should be divided into. This type of method works by building a dendrogram, an upside-down tree, in which the leaves, at the bottom, represent the individual instances of a dataset. An iterative process joins the leaves as it moves vertically up the tree, based on how similar they are to each other and eventually all the instances will be linked together (Patel, 2019) as can be seen on Figure 2.4 below. Figure 2. 4: Dendrogram 13 Since hierarchical clustering does not have a predefined number of clusters, before the implementation of the method, this decision can be made based on the dendrogram. Just by visually inspecting the dendrogram one can have an intuition of how the data is distributed. In the above example, in Figure 2.4, a horizontal red line symbolizes an assumption of how the clusters could be defined. In this case, the red line crosses five vertical lines and each of these vertical lines represent one cluster. As this red line moves higher up the tree this would generate a smaller number of clusters but with more elements is each of those clusters. On the contrary, if the red line moved to lower positions in the tree, it would generate a greater number of clusters but with less elements in each one. The implementation of hierarchical clustering can be executed in two forms: - Divisive Clustering: this is a top-down technique in which, initially, all points of the dataset belong to the same cluster. A recursive implementation gradually splits the datapoints as one moves down the hierarchy (Kumar, 2020). - Agglomerative Clustering: this is a bottom-up technique in which, initially, each data point represents a cluster. The implementation of this technique groups these points into clusters as one moves up the hierarchy (Kumar, 2020). One important aspect of hierarchical methods is the definition of how to group or separate data points into clusters. Whether using agglomerative or divisive clustering, it is necessary to measure the distance between two clusters (Han, Kamber, & Pei, 2012). This is done based on how close the data points are to each other. Consequently, points that are close to each other tend to be a part of the same cluster and points that are very far apart tend to belong to different clusters. There are a few different metrics that can be applied to evaluate proximity between data points, but the most common are the following four: - Single-Linkage: this metric uses the distance between the two closest neighbors of different clusters in order to group data points into new clusters. It can generate clusters that are very spread-out and where observations in different clusters are closer to each other than observations within their own cluster (Clements, 2019). - Complete-Linkage: this metric considers the distance between the two farthest neighbors of each cluster to determine how clusters will be grouped to form new clusters. Usually, the final clusters are very close to each other (Clements, 2019). - Average-Linkage: this metric uses the average distance between each pair of observations of every combination of two clusters to determine which clusters are closer to one another (Clements, 2019). - Centroid-Linkage: this metric is based on the distance between the centroids of two clusters (Clements, 2019). Regardless of which metric is used to evaluate proximity between data points, it is essential to define a distance metric to be applied since this is what will be used to calculate the proximity matrix and define distance between observations (LZP, 2019). 14 Also relevant is the fact that, with any of the metrics described above, the implementation of hierarchical methods can be terminated when a maximum distance between nearest clusters exceeds a predefined threshold (Han, Kamber, & Pei, 2012). To summarize, Hierarchical methods have the advantage of being one of the easiest to understand in comparison to other methods. It is also relatively simple to implement and generates an appealing output which is the dendrogram. It does not, however, usually provide the best solutions, given the following factors (Bock): - It does not work with missing data. - It does not work well with categorical values. - It does not work well with large volumes of data. For large datasets the construction of a dendrogram is computationally prohibitive (Jain, Murty, & Flynn, 1999). 2.4.2. Partitional Methods Partitioning techniques organize the objects of a set into a predefined number of exclusive groups or clusters. These clusters are formed by optimizing a partitioning criterion such as a dissimilarity function based on distance, so that objects within a cluster are “similar” to each other and “dissimilar” to objects of other clusters (Han, Kamber, & Pei, 2012). The most commonly utilized partitioning method is the K-Means algorithm, which separates the data into clusters of equal variances and minimizes a criterion known as inertia or within-cluster sum-of- squares, as is represented by the formula bellow (sklearn.cluster.Kmeans - scikit-learn 1.0.1 documentation): 0   𝑚𝑖𝑛 ∈(||𝑥−𝜇||) Where (𝑥) represents each of the observations in the cluster and (𝜇) represents the mean of the cluster, which is also known as the centroid. As the formula shows, the objective of K-Means algorithm is to execute iteratively, by dividing the observations into clusters, until the distances of each observation to its centroid are minimal. It can be intuitive to conclude that a big number of clusters would naturally reduce the intra-cluster distances. However, one of the most important aspects of K-Means is exactly the definition of the number of clusters in which the data will be divided. The number of clusters should ideally illustrate the groups that represent the data and, since this can be a very subjective matter, there are a few tools to help with this judgment. 15 Basically K-Means algorithm can be implemented in the following five steps: 1. Step 1: Choose the number of clusters (K). 2. Step 2: Select K random points as centroids. 3. Step 3: Assign each observation in the dataset to one of the centroids, the closest one. 4. Step 4: Recompute the centroids of the newly formed clusters 5. Step 5: Repeat steps 3 and 4 until a stopping criterion is achieved. The computation of the new centroids after each iteration is calculated as the mean (average of all attributes) of all the observations that belong to each cluster, i.e., all the observations that are associated to a centroid. Regarding step 5, there are basically three stopping criteria that can be applied to interrupt the iteration (Sharma, 2019): - The centroids of the newly formed clusters do not change from the previous iteration. - All the data points remain in the same clusters as they were in the previous iteration. - A maximum predefined number of iterations has been achieved. Figure 2.5, below, shows the basic evolution of a K-Means algorithm execution. Figure 2. 5: K-Means Algorithm (Piech, 2013) 22 would be practically identical to the K-Means algorithm (Bação, Lobo, & Painho, 2005). In this case, if we consider each unit as a centroid and if the radius of the neighborhood function were equal to zero, the centroid would only be influenced by the data points that are related to it. 2.4.5. Combination Methods An alternative to utilizing just one of the clustering techniques described above is to implement a combination of two of these methods. Two combinations can be particularly useful: K-Means with Hierarchical and SOM with K-Means. 2.4.5.1. K-Means with Hierarchical This is a strategy that can be applied in order to identify the appropriate number of clusters in a dataset before applying K-Means. This is done by firstly applying a Hierarchical clustering algorithm to define what would be the ideal number of clusters and then applying the result of this as the K in a K-Means implementation. Another option is to do the inverse by, initially, implementing K-Means with a large number of clusters and then applying a hierarchical method in order to determine the appropriate number of clusters. 2.4.5.2. K-Means with SOM The implementation of SOM is done based on a n-dimensional grid of neurons which represents the output space. The problem is that usually this grid is formed by a large number of neurons and, consequently, a large number of clusters. So, in most cases, after applying a SOM algorithm it is necessary to apply another clustering algorithm to the results of SOM. One of the preferred choices for this is the K-Means algorithm since it will cluster the grid of neurons instead of the initial data. By doing this, the algorithm will try to identify clusters of data based on the proximity of the neurons, since during the execution of the first algorithm each of them will move throughout the output space according to the number of data points that are close by. By using this strategy, one will be taking advantage of both clustering techniques. First, the SOM algorithm will make it possible to analyze the distribution of the data through the output space. And, later, K-Means will translate this into a reasonable number of clusters that can be clearly identified and represented. 2.5. PROFILING One of the last steps, but not less important, during the process of implementing clustering techniques is to perform cluster profiling. This is done by analyzing the results that were achieved and trying to make sense of them. This process usually involves the participation of business experts that are more accustomed to the nuances of the field of study. 23 The objective of cluster profiling is to verify if the clusters that were generated by the algorithm translate into real world clusters for the problem at hand and if they clearly identify and separate the data points in a way that makes sense for any future analysis and decision making. 2.5.1. Radar Chart A very useful tool to compare different clusters and profiles is the radar chart. With this tool it is possible to compare the behavior of numerical variables amongst different observations. Since clusters can be represented by a centroid or an average value, radar charts can be applied to compare these values to perform graphical analysis of their characteristics. Radar charts are built by attributing each variable to an individual axis, which are spaced equally, and arranging them around the center. Each observation is then plotted along each axis like a scatter plot and the points are connected to form a polygon (Radečić, 2021). Afterwards, each observation can be plotted into the same plot. Alternatively, individual plots can be generated for each observation. Figure 2.11 below shows an example of a radar chart that was built to compare variables of three different observations. Figure 2. 11: Example of a Radar Chart (Radečić, 2021) This example compares 5 variables regarding the qualities of three restaurants. The radar chart helps in identifying the strengths of each one of these restaurants. One performs better in terms of affordability while another performs better in terms of food variety, quality, and ambience. However, the important aspect of this analysis is that it could be applied for a group of observations (clusters) such as different restaurant chains. 24 3. CLUSTER ANALYSIS In this section the gambling data regarding user behavior on online platforms in Portugal will be analyzed. Initially, the data from 2019 will be examined in order to identify user clusters. Afterwards, the data from 2020 will also be analyzed and the results will be compared to those of 2019. All the data analysis will be performed in Python through the use of Jupyter Notebooks and during the presentation of the results some of these steps will be shown. First it is important to highlight that a decision was made in terms of the scope of this work. The platforms that have authorization to promote online gambling in Portugal offer two types of activities: sports bets and games of chance. In 2019 sports bets generated a gross income close to 107 million euros and games of chance generated a gross income close to 109 million euros, indicating both had almost equal relevance in the business. In terms of betting volumes sports bets totaled something around 543 million euros while games of chance reached values of 2,9 billion euros (Turismo de Portugal, 2019). With that in mind, and considering that sports bets probably suffered impacts in 2020 caused by the Covid-19 pandemic that would complicate any comparison with data from 2019, a decision was made to limit the scope of this work to data regarding games of chance. Regarding the scope of games of chance, the following four games were made available for playing during the fourth trimester of 2019: slot machines, roulette, blackjack, and poker (two types). The distribution of the betting volumes between these games is shown in Figure 3.1 below. Figure 3. 1: Distribution of Betting Volume in 2019 (Turismo de Portugal, 2019) 25 As the image shows, slot machines represented almost 69% of betting volumes in the fourth trimester of 2019. Since this indicates that slot machines are very significant to this business and that it is a form of game that attracts intense level of gaming, it has been chosen for the analysis that has been proposed in this work. Consequently, the scope of the work will be limited to the data regarding user activity while playing online slot machines. 3.1. CLUSTER ANALYSIS FOR 2019 DATA The first portion of this work will be dedicated to the evaluation of data from 2019. 3.1.1. 2019 Data Loading and Initial Analysis The original and raw data regarding user activity within the ten entities that had permission to provide online gambling in 2019 were delivered to NOVA IMS by SRIJ. The raw data contains specific details of each transaction executed in the platforms throughout the year. This data was consolidated by the staff of NOVA IMS into the form of daily records, which will be the starting point of all analysis performed in this work. The consolidated file was delivered in the form of a CSV file with 3.512.157 entries and with no missing values. The file contains the following variables: Table 3. 1: List of Variables in 2019 CSV File Variable Description operation Variable created during the consolidation of the data entity_id Id of the Entity (1,2,3,4,5,6,7,9,10,11) player_id Id of the Player in that Entity day_dt Date in the format 'YYYYMMDD' day_num Day of Month day_of_week Day of Week (0,1,2,3,4,5,6) amount Total Amount played during the day amount_var Variation of the Amount during the day amount_std Standard Deviation of the Amount during the day hours_played Hours played during the day count Number of bets placed during the day wins Number of wins during the day balance Finantial Balance at the end of the day dawn Number of bets placed during the dawn period (00:00 to 5:59) morning Number of bets placed during the morning period (06:00 to 11:59) afternoon Number of bets placed during the afternoon period (12:00 to 17:59) night Number of bets placed during the night period (18:00 to 23:59) amount_mean Avarage Amount for each bet wins_perc Percentage of wins during the day dawn_perc Percentage of bets placed during dawn morning_perc Percentage of bets placed during the morning afternoon_perc Percentage of bets placed during the afternoon night_perc Percentage of bets placed during the night balance_perc Ratio of balance and amount player_uid Unique User Id self_excluded Indication if the user has ever been self excluded 26 In summary, each record contains the description of user activity during a specific day in which that player was active in one of the ten online platforms. To better understand this information a few of the variables listed on Table 3.1 must be better explained: - PLAYER_ID: this variable refers to the identification of a user in a specific platform. This means that the same person can be registered in two or more platforms and will consequently have a different PLAYER_ID in each one of them - PLAYER_UID: this refers to a unique user identification and indicates that a person will have the same ID throughout all the records in the dataset. - WINS: since the concept of victory in gambling can be considered subjective, for this study only situations in which the player finishes the bet with more money than what was invested initially will be considered a win. So, for instance, if a player invests 10 euros in a bet and ends up with 8 euros that will not be considered a win, since the player’s balance will be of minus 2 euros. - SELF_EXCLUDED: all online platforms must provide an alternative for users that feel they do not have a healthy gambling behavior to exclude themselves from the platforms. This binary variable indicates if the user has, at any time, been self-excluded in that specific platform. It is important to mention that this variable is just an indication if the player has ever been selfexcluded with no indication of the period in which this happened. An important aspect to consider in this initial analysis of the raw data is that the records are not evenly distributed among the 10 platforms. Table 3.2 below shows the number of records of each entity and, also, the percentage of records of each entity in relation to the total number of records of the dataset (3.512.157 entries). Table 3. 2: Number of records of each Entity Entitity ID Number of Records Percentage 1 635.367,00 18,1% 2 479.268,00 13,6% 3 872.422,00 24,8% 4 624.067,00 17,8% 5 184.364,00 5,2% 6 327.880,00 9,3% 7 115.731,00 3,3% 9 15.626,00 0,4% 10 121.856,00 3,5% 11 135.576,00 3,9% Total 3.512.157,00 100% 27 The information in the table shows that while some entities have a very significant participation in online slot machine gambling others have very little representation. This could be caused by the fact that some entities are newer to the business and have not yet achieved a relevant user base. This also indicates that the results achieved during this work could have variations based on the business strategies implemented by each entity since some of them might be willing to accept smaller profits than others. Another relevant matter that can be analyzed in the raw data is the variation of the attributes during the year since some specific user behaviors can be influenced by seasonality. Figure 3.2 below shows the graphic representations of the variation of four major attributes in this dataset based on the average values of each month. Figure 3. 2: Variation of attributes during 2019 This image demonstrates that the number of bets and the total number of hours played during the day did not change very much during the year. It is noticeable, however, that the amount variation and balance increased towards the end of the year. Given that the increase is relatively significant for both variables it is conceivable that this is caused by outliers. The increase in balance is especially intriguing since it has a negative value throughout the year and jumps to a positive value in the month of December. Buy looking at the average values for each month it becomes clear that in fact the values that represent the balance are unexpected. Between the months of January and November the highest value for balance was -4,69 and the lowest value was - 9,90. In December the average balance becomes 6,63 and this would indicate that on average the players would have had a profit over the online platforms during this month. Since this wouldn’t be reasonable from a business standpoint it very likely that these numbers are being inflated due to 28 outliers and that some sort of treatment will be necessary to avoid that these outliers pollute the models that will be created. Outliers can represent actual values that indicate extreme values can occur in the dataset. They can also, however, be generated by data entry errors and interface problems while data is being transferred from one system to another. In the case of the variable BALANCE there are records that indicate daily balances of over 200.000 euros, which seems extremely unreasonable. So, as a way of analyzing the effects of extreme values in this dataset, the monthly average of the variable BALANCE will be calculated, firstly with all the records and secondly with a limitation of the values, considering the number that represents the 0,99 percentile, i.e., all values that are higher than the 0,99 percentile will be changed to this maximum value. Tables 3.3 and 3.4 show the results of this comparison. Table 3. 3: Average Balance with Outliers Table 3. 4: Average Balance without outliers Month Average Balance (€) January -7,99 February -4,69 March -5,46 April -5,58 May -7,72 June -9,90 July -8,49 August -5,66 September -6,71 October -6,18 November -7,99 December 6,63 Month Average Balance (€) January -23,92 February -26,39 March -25,76 April -27,00 May -29,58 June -29,42 July -27,58 August -25,28 September -26,54 October -26,93 November -25,23 December -20,86 29 First, it is noticeable how these outliers affect the average monthly values. But more importantly is the fact that specifically for the month of December the outliers caused the average value to be totally incoherent with what had happened in previous months and even with what would be expected as a normal balance value from a business point of view. 3.1.2. 2019 Data Preparation As it has been demonstrated previously, it is important to perform some level of preparation of the dataset. This involves things like feature engineering, variable selection, exclusion of outliers, among others, and will be addressed in the following sections. 3.1.2.1. Feature Engineering One aspect of this dataset that stands out is the fact that it does not contain many categorical variables that would help describe the users such as age, gender, and location. The only categorical variables that are present in the dataset are ENTITY_ID and SELF_EXCLUDED which indicate the platform entity identification and if the player has ever been self-excluded from that platform respectively. Given this fact and considering that feature engineering can generate important information for machine learning models, a few attributes were created to enhance these models. Table 3.5 below shows a list and description of these new features. Table 3. 5: New Features Variable Description day_type Categorical variable to determine if the day related to the record refers to a weekday or a weekend. For this purpose, Monday, Tuesday, Wednesday and Thursday will be considered weekdays and Friday, Saturday and Sunday will be considered weekends. Weekdays will have value 0 and weekends will have value 1. user_id An identification of the player in each entity. This attribute will be a concatenation of the entity_id and player_id variables. avg_play_per_hour This will be a calculated attribute that will show how many bets the user made on average each hour of the day. It will be calculated by dividing the hours_played variable by the count variable. automated_play Binary categorical variable to determine if the player used any form of automated tool to play during the day. Whenever the avg_play_per_hour is greater than 360 this will be considered true and receive value 1. Otherwise, it will have value 0. winning_day Categorical variable that indicates if the player had a "winning" day. This attribute will receive value 1 if the player balance is positive and will receive 0 otherwise. 30 3.1.2.2. Data Aggregation Another relevant aspect of this dataset is that the data is grouped in the form of daily records. This means that the information regarding user activity is organized in a way that shows the totality of the interactions the user had in each day of the year. As a result, each user will have as many records in the dataset as the number of days in which he or she was active in online gambling platforms. For instance, if a player was active on 10 different days of the year, that player will have 10 records in the dataset. Since the objective of this work is to understand player behavior and to analyze how the average behavior might have changed from 2019 to 2020, a decision was made to group the data considering user identifications. In this manner a dataset will be generated in which each record will show the “average” behavior of one specific user during the year of 2019. For the purposes of aggregation, the variable USER_ID that represents the identification of users in each entity has been chosen instead of the variable PLAYER_UID that represents a unique identification of users across all platforms. This is due to the fact that the PLAYER_UID attribute is not considered completely reliable and could generate inconsistencies in the result of the aggregation. The table below shows the list of the attributes of the dataset that were generated to aggregate data of users into individual records. Table 3. 6: Attributes of aggregated dataset Variable Description user_id (index) User Id that combines original Id and Entity Number days_played Number of days of the year in which the user played slot machine avg_count How many time the user played on average each day avg_win_perc How many wins the player had on average each day avg_amount The finantial amount the player bet on average each day avg_amount_mean The average of the mean amount per bet avg_amount_var The average of the amount variation avg_amount_std The average of the amount standard deviation avg_balance The average of user balance per day avg_auto_play The percentage of days in which the player used auto play mecanism avg_day_type The pecentage of days that were weekends (Friday-Sunday) avg_hours_played How many hours the user played on average per day avg_dawn_perc Average percentage of dawn play avg_morning_perc Average percentage of morning play avg_afternoon_perc Average percentage of afternoon play avg_night_perc Average percentage of night play self_excluded Indicates if player was ever self exluded entity_id Entity Id winning_day_avg Percentage of days in which the player had a winning day 31 The decision to aggregate the dataset based on the users may cause the loss of specific daily information which will have to be analyzed as an average throughout the year. It will, on the other hand, allow for a better understanding of general characteristics of each user. And by doing this it will be possible to separate these users in clusters based on their behavior during the year. The dataset that was generated with information aggregated by users has 253.826 records, meaning this is the number of users that played online slot machine at least once in 2019. 3.1.2.3. Scope Limitation Following this decision to group the dataset into records that identify each user, comes the decision of which records should be considered for this analysis. Since the idea is to understand the typical user behavior and later to compare this with data from 2020 to identify any behavior shifts, it would not make sense to keep in the dataset records related to users that have had limited amount of interaction with the online gambling platforms. Table 3.7 below shows the distribution of users according to the frequency in which they played. In this case the frequency is calculated based on the number of days of the year in which the player placed at least one bet. Table 3. 7: Distribution of users according to frequency of play As Table 3.7 shows, 67% of users were only active in online gambling in five days or less during 2019. For the purposes of understanding user profiles and identifying specific user behaviors these users can be considered irrelevant and could actually harm the analysis. In a more direct conclusion, and for the objectives of this work, these users can be classified as “non-players”. With this evaluation it was decided to exclude these users from the dataset and to proceed in the analysis only with users that were active in at least 6 days of the year. This represents around 33% of the data and reduces the dataset to 92.021 records. Days Played Percentage (0,1] 37% (1,5] 30% (5,10] 10% (10,50] 16% (50,100] 4% (100,300] 3% (300,365] 0% 38 The intra-cluster distances (inertia) of this model are slightly better than of the previous model and the elbow graph suggests the model should have six clusters. Table 3.10 shows the centroids of this model. Table 3. 10: Centroids of Model 2 This model also does not generate interpretable clusters. Some variables seem irrelevant in terms of cluster differentiation. Cluster distribution also was not ideal with cluster 1 having only 3 records. 3.1.3.3. Model 3 This model will be implemented with the following configuration: - Algorithm: K-Means - Variables: Excluding ENTITY_ID and SELF_EXCLUDED; keeping only one AMOUNT variable; keeping two FREQUENCY variables; keeping one WINNING variable; excluding all PERIOD OF DAY variables - Scaler: Standard Scaler - Outliers: Outliers will not be altered Cluster AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE AVG_HOURS_PLAYED AVG_AUTO_PLAY AVG_DAY_TYPE 0 0.17 1.81 -10.09 2.47 0.02 0.40 1 0.32 7142.50 15401.52 5.25 0.35 0.44 2 0.30 3.07 43.44 2.78 0.04 0.42 3 0.16 1.28 -9.14 2.20 0.03 0.44 4 0.16 2.89 -10.63 2.25 0.04 0.42 5 0.19 3.00 -21.14 4.76 0.32 0.43 Cluster WINNING_DAY_AVG AVG_DAWN_PERC AVG_MORNING_PERC AVG_AFTERNOON_PERC AVG_NIGHT_PERC WINNING_DAY_AVG 0 0.19 0.10 0.26 0.48 0.23 0.19 1 0.32 0.27 0.14 0.35 0.32 0.32 2 0.49 0.18 0.15 0.35 0.36 0.49 3 0.19 0.15 0.08 0.25 0.54 0.19 4 0.20 0.50 0.08 0.18 0.26 0.20 5 0.29 0.25 0.13 0.28 0.36 0.29 39 The elbow graph for this model is shown on Figure 3.8. Figure 3. 8: Elbow Graph for Model 3 The intra-cluster distances seem to have improved in this model and the graph suggests five clusters. Which are represented by its centroids on Table 3.11 below. Table 3. 11: Centroids of Model 3 Model 3 is the best model until now, since it seems to generate reasonably interpretable clusters, even though some variables remain irrelevant to the model such as AVG_WIN_PERC and AVG_DAY_TYPE. Additionally, cluster 3 contains only three records, probably due to outliers. 3.1.3.4. Model 4 This model will be implemented with the following configuration: - Algorithm: K-Means - Variables: Excluding ENTITY_ID and SELF_EXCLUDED; keeping only one AMOUNT variable; keeping two FREQUENCY variables; keeping one WINNING variable; excluding all PERIOD OF DAY variables - Scaler: Normalization (Minmax) - Outliers: Outliers will not be altered Cluster DAYS_PLAYED AVG_HOURS_PLAYED AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE AVG_DAY_TYPE 0 17.83 2.58 0.35 4.49 53.33 0.40 1 19.94 2.20 0.17 1.01 -7.29 0.57 2 110.18 4.40 0.18 3.81 -13.33 0.42 3 15.00 5.25 0.32 7142.50 15401.52 0.44 4 21.00 2.21 0.16 1.71 -10.88 0.32 40 The Elbow Graph of this model is shown on Figure 3.9. Figure 3. 9: Elbow Graph of Model 4 The elbow graph suggests four clusters, which are represented by its centroids on Table 3.12. Table 3. 12: Centroids of Model 4 This model generates clearly identifiable clusters. Cluster 3, for example, represents high intensity gambling with greater losses. Clusters 1 and 2 represent users that make profits but have specific gambling habits. 3.1.3.5. Model 5 This model will be implemented with the following configuration: - Algorithm: K-Means - Variables: Excluding ENTITY_ID and SELF_EXCLUDED; keeping only one AMOUNT variable; keeping two FREQUENCY variables; keeping one WINNING variable; excluding all PERIOD OF DAY variables - Scaler: Standard Scaler - Outliers: Outliers will be limited to the 99th Percentile Cluster DAYS_PLAYED AVG_HOURS_PLAYED AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE AVG_DAY_TYPE 0 29.61 2.76 0.19 2.07 -2.62 0.43 1 13.75 2.17 0.20 3.64 0.62 0.23 2 13.60 2.21 0.19 1.34 0.64 0.64 3 166.23 3.78 0.18 3.35 -9.83 0.42 41 The elbow graph for this model is show on Figure 3.10. Figure 3. 10: Elbow Graph for Model 5 The elbow graph indicates that the ideal number of clusters is seven. Since this seems exaggerated for the problem at hand the model will be implemented with six clusters. They are represented by the centroids in Table 3.13. Table 3. 13: Centroids for Model 5 This model minimizes the negative effects that outliers had caused in previous models that used Standard Scaler. Clusters can be visualized mainly due to the FREQUENCY variables and the monetary values (AMOUNT and BALANCE). The clusters are well distributed and clusters numbers 1 and, 2 that represent intensive gamblers (possibly addictive behavior), represent around 22% of users. 3.1.3.6. Model 6 This model will be implemented with the following configuration: - Algorithm: K-Means - Variables: Excluding ENTITY_ID and SELF_EXCLUDED; keeping only one AMOUNT variable; keeping two FREQUENCY variables; keeping one WINNING variable; excluding all PERIOD OF DAY variables - Scaler: Normalization (Minmax) - Outliers: Outliers will be limited to the 99th Percentile Cluster DAYS_PLAYED AVG_HOURS_PLAYED AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE AVG_DAY_TYPE 0 17.67 2.44 0.36 0.34 37.49 0.40 1 169.61 3.64 0.17 0.42 -7.47 0.42 2 46.46 3.19 0.20 18.35 -154.28 0.40 3 19.54 2.04 0.17 0.20 -5.68 0.58 4 35.07 4.76 0.18 0.36 -11.54 0.42 5 22.20 2.03 0.16 0.24 -7.53 0.32 42 The elbow graph for this model is show on Figure 3.11. Figure 3. 11: Elbow Graph for Model 6 The elbow graph indicates that the ideal number of clusters could be either four or five. Since in the previous model six clusters were utilized, this model will also be tested with six clusters. The clusters for each of these three options are represented in the following tables: Table 3. 14: Centroids for Model 6 with 4 Clusters Table 3. 15: Centroids for Model 6 with 5 Clusters Table 3. 16: Centroids for Model 6 with 6 Clusters Cluster DAYS_PLAYED AVG_HOURS_PLAYED AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE AVG_DAY_TYPE 0 21.38 2.49 0.19 0.27 -2.73 0.32 1 20.30 2.44 0.19 0.23 -2.13 0.56 2 47.01 3.16 0.20 18.41 -125.68 0.40 3 151.51 3.73 0.17 0.40 -8.08 0.42 Cluster DAYS_PLAYED AVG_HOURS_PLAYED AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE AVG_DAY_TYPE 0 13.66 2.17 0.20 0.25 -1.95 0.23 1 29.51 2.74 0.19 0.27 -3.44 0.43 2 46.97 3.16 0.20 18.43 -125.96 0.40 3 166.30 3.78 0.18 0.41 -7.90 0.42 4 13.58 2.20 0.19 0.21 -1.15 0.64 Cluster DAYS_PLAYED AVG_HOURS_PLAYED AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE AVG_DAY_TYPE 0 31.26 2.75 0.17 0.27 -7.54 0.43 1 13.56 2.15 0.17 0.24 -6.70 0.23 2 47.08 3.17 0.20 18.46 -126.69 0.40 3 168.32 3.80 0.18 0.42 -7.87 0.42 4 17.01 2.58 0.37 0.30 33.25 0.39 5 13.55 2.18 0.18 0.21 -3.54 0.65 43 All three alternatives generate reasonable clusters that can be clearly defined. The alternative with 6 clusters, however, seems to generate a more interesting division since cluster four represents players that have a winning pattern of gambling. One thing that stands out is that the variables AVG_WIN_PERC and AVG_DAY_TYPE do not seem relevant to separate users. In the case of the variable AVG_DAY_TYPE, it only serves to separate clusters 1 and 5 indicating that players on cluster 5 have a tendency to play more frequently on weekends. This, however, does not seem to improve user segmentation. 3.1.3.7. Model 7 This model will be implemented with the following configuration: - Algorithm: K-Means - Variables: Excluding ENTITY_ID, SELF_EXCLUDED and AVG_DAY_TYPE; keeping only one AMOUNT variable; keeping two FREQUENCY variables; keeping one WINNING variable; excluding all PERIOD OF DAY variables - Scaler: Normalization (Minmax) - Outliers: Outliers will be limited to the 99th Percentile The elbow graph for this model is show on Figure 3.12. Figure 3. 12: Elbow Graph for Model 7 The elbow graph indicates that the number of clusters could be between 3 and 6, so the model will be implemented with 5 clusters to evaluate if there can be any reduction in comparison to the last model. The centroids for these five clusters are represented in the following table. 44 Table 3. 17: Centroids for Model 7 This model also generated reasonable clusters that can be clearly identified and that are reasonably distributed. 3.1.3.8. Model 8 This model will be implemented with the following configuration: - Algorithm: SOM - Variables: Excluding ENTITY_ID, SELF_EXCLUDED and AVG_DAY_TYPE; keeping only one AMOUNT variable; keeping two FREQUENCY variables; keeping one WINNING variable; excluding all PERIOD OF DAY variables - Scaler: Normalization (Minmax) - Outliers: Outliers will be limited to the 99th Percentile The implementation of SOM will be experimented in a 10x10 feature map that will be executed for 100 epochs. Afterwards, K-Means will be applied to the results of SOM in order to obtain six clusters of data. The BMU Hits View displayed on Figure 3.13 below indicates the number of records associated to each neuron (unit) in the feature map. Cluster DAYS_PLAYED AVG_HOURS_PLAYED AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE 0 15.05 2.47 0.34 0.28 26.94 1 56.30 3.86 0.18 0.37 -9.21 2 15.28 2.02 0.16 0.20 -7.55 3 191.86 3.87 0.17 0.44 -8.24 4 46.50 3.15 0.20 18.33 -125.04 45 Figure 3. 13: BMU Hits View for Model 8 And after applying K-Means the Hits Map on Figure 3.14 indicates which neurons are associated to each cluster. Figure 3. 14: Hits Maps for Model 8 46 The hits map gives an idea of the distribution of the records between the clusters with Cluster 0 having the greater number of records and Cluster 5 being the smallest cluster. By calculating the average values of the variables in each cluster it is possible to identify values that can be considered as the centroids of each cluster. These centroids are represented in the following table. Table 3. 18: Centroids for Model 8 The centroids for this model are very similar to those of model 6 that used K-Means and it also generates reasonable clusters that are well distributed. 3.1.4. Model Selection for 2019 Data After having implemented a series of different models, one of them must be chosen as the primary model for modeling this data. One way of evaluating all these models is to check their silhouette scores. The following table shows the value for each model. Table 3. 19: Silhouette Scores of the Models One thing that is clear, by looking at these scores, is that models in which outliers were treated had a much better performance. This is the case for models 5 through 8. Cluster DAYS_PLAYED AVG_HOURS_PLAYED AVG_WIN_PERC AVG_AMOUNT_VAR AVG_BALANCE AVG_DAY_TYPE 0 29.19 2.80 0.16 0.14 -4.25 0.42 1 124.41 4.35 0.18 0.34 -9.62 0.42 2 15.34 1.94 0,16 0.14 -5.44 0.60 3 13.61 1.95 0.16 0.18 -9.26 0.24 4 18.71 2.36 0.33 0.25 30.29 0.40 5 40.70 3.05 0.19 12.28 -125.96 0.40 Model Silhoutte Score Model 1 0.11 Model 2 0.13 Model 3 0.02 Model 4 0.01 Model 5 0.24 Model 6 (4 clusters) 0.30 Model 6 (5 clusters) 0.27 Model 6 (6 clusters) 0.28 Model 7 0.38 Model 8 0.23 47 It is clear that Model 7 had the best performance, followed by Model 6. And Model 8, which implemented SOM, did not perform very well in comparison to these other models. Another form of evaluating the quality of the models is to plot their silhouette coefficients. Since, based on the silhouette average score, it is already possible to have an idea of this quality, only the coefficients for models 6 (with 6 clusters) and 7 will be plotted. These were two of the models with best silhouette average scores. Figure 3.15 displays the silhouette plot for Model 6 (with 6 clusters). Figure 3. 15: Silhouette Plot for Model 6 (with 6 clusters) The plot shows that clusters 0, 2, 3, 4 and 5 have some silhouette coefficients below 0 which indicates that some records might have been incorrectly classified. The thickness of these lines, however, indicate that this did not happen for many records. The thickness of the lines also helps in identifying that cluster 0 is the largest cluster and cluster 2 is the smallest cluster. And it is also perceptible that clusters 1, 2, 3 and 5 have most records with silhouette coefficients above the average of 0,28. 54 As a result of the analysis of each of the clusters, the profiles listed on Table 3.27 were identified. Table 3. 27: List of Profiles (2020) As it was done with the data from 2019, the profiles were defined based on the tendency to have compulsive gambling behavior. In the case of the data from 2020, clusters 2 and 3 are the ones that represent players with high probability of having addictive gambling habits. Cluster 2 represents players that play with a high frequency and cluster 3 represents players that lose large monetary values. These players with high compulsive behavior represent 12% of the users in the dataset. As it was noted with the data from 2019, there are differences in user behavior based on the entity in which they played. The table below shows the percentage of users of each entity associated to each cluster. Table 3. 28: Proportional Distribution of Clusters by Entity (2020) Cluster Cluster Name Description Compulsive Behavior Proportion of Cluster 0 Frequent Small Loser Plays twice a week. Loses small amounts of money and the amounts do not vary much during the day. Medium 23% 1 Sporadic Player Plays once a week and for few hours each day. Loses small amounts of money and the values of the bets do not vary much during the day. Low 58% 2 Frequent Player Plays with a high frequency and for many hours each day. Does not lose much money and the values of the bets do not vary much during the day. High 10% 3 High Value Player Plays twice a week. Loses a high amount of money and the betting values vary a lot during the day. High 2% 4 Winning Player Plays once a week and has a high percentage of wins. This leads to positive balances for the player. Low 7% Entity/Cluster 0 1 2 3 4 1 23,79% 61,26% 12,75% 1,86% 0,35% 2 21,00% 41,37% 9,02% 1,22% 27,39% 3 25,76% 59,21% 10,49% 2,33% 2,21% 4 22,99% 65,89% 9,97% 0,95% 0,20% 5 24,57% 58,15% 11,30% 2,85% 3,11% 6 26,86% 56,38% 11,54% 2,89% 2,33% 7 17,13% 31,71% 5,91% 0,89% 44,36% 9 13,95% 59,69% 3,57% 3,06% 19,73% 10 16,32% 77,96% 4,16% 1,48% 0,08% 11 23,72% 54,70% 11,78% 1,48% 8,32% Total 23,11% 58,45% 10,15% 1,69% 6,60% 55 The analysis makes it clear that there are similarities in the clusters that were generated by the model for the data of each year. There are also, however, some differences in a few characteristics of these clusters and in the proportion each one of them represents. These aspects will be analyzed in the Results section of this work. 3.3. CLUSTER SHIFTS BETWEEN 2019 AND 2020 An important analysis that can be made is to verify into which clusters of 2019 the data from 2020 would fit into. By doing this it is possible to verify if users have moved from one cluster to another during the lockdown period of the pandemic. And, in doing so, it is possible to quantify the number of users that have developed compulsive gambling behaviors and those that have either maintained previous behaviors or developed healthier ones. There are many techniques available to classify datapoints into previously generated clusters. For this work, a supervised learning method called KNeighborsClassifier will be utilized. In this method each datapoint that needs to be classified is compared in terms of distance (Euclidean distance in this case) to all the datapoints in the original dataset and the K nearest neighbors are selected. Afterwards, by a form of vote the new datapoint is classified based on the classification of the majority of its K nearest neighbors (sklearn.neighbors.KNeighborsClassifier -scikit-learn 1.0.1 documentation). So, in the case of classifying the data from 2020 into the 2019 clusters, KNeighborsClassifier will be implemented with a K of 3. Each datapoint (user) from the 2020 dataset will be compared to the datapoints from the 2019 dataset and the three closest neighbors will be identified. This datapoint will then be classified according to the classification of the majority of these 3 neighbors. So, for example, if two neighbors are associated to cluster 1 and one neighbor is associated to cluster 2, the 2020 datapoint will be associated to cluster 1. After doing this, it will be possible to compare each user based on its original cluster in 2019 and on the cluster it would be associated to based on its variables in 2020. And so, the following table shows the cluster shifts of the 31.615 users that were present in both 2019 and 2020 datasets. It summarizes the number of users in each of the possible cluster combinations in the years 2019 and 2020. Table 3. 29: Cluster Shifts 0 1 2 3 4 0 882 996 638 511 57 1 726 4.444 1.924 3.529 200 2 1.054 4.145 4.975 2.090 173 3 114 1.122 253 3.085 85 4 31 132 74 89 286 2019 2020 Cluster Shifts 56 This analysis only contemplates the users that were present in both the 2019 and 2020 datasets, which is a total of 31.615 users, since it would not make sense to include users that were only active in one of the years in order to identify cluster shifts. And by analyzing this table, a few insights can be reached: - 13.672 (43%) of users did not change to a different cluster in 2020. - 6.560 (21%) of users moved from clusters of low (clusters 0 and 2) or medium (cluster 1) compulsive behavior to clusters of high (clusters 3 and 4) compulsive behavior. - 1.726 (6%) of users moved from clusters of high compulsive behavior to clusters of either low or medium compulsive behavior. - 5.141 (16%) of users moved from clusters of low compulsive behavior to a cluster of medium compulsive behavior. - 4.444 (14%) of users moved from clusters of medium compulsive behavior to clusters of low compulsive behavior. A few conclusions can be reached immediately by looking at these numbers, but they will be analyzed more objectively in the Results section of this work. 57 4. RESULTS AND DISCUSSIONS This section of the work will be dedicated to the discussion of the final results and to answering the research questions that were presented in the Introduction. One of the main objectives of this work was to classify online gambling users into clusters based on their behavior. Through the application of ML techniques, it became evident that these users can be distributed based on some of their gambling characteristics. Initially, ML techniques were applied to user data from 2019 which was divided into five clusters. Theses clusters were then analyzed with the intent of identifying profiles according to the tendency of users having compulsive gambling behavior. Of the five clusters, two were associated with high compulsive behavior, either because of the frequency of play or because of the extremely negative user balance. These two clusters represent roughly 8% of the total user base in 2019. The ML model that was used with the 2019 user base, was also applied to the data from 2020 in order to evaluate what user behavior would look like during the most restrictive period of lockdown in the Covid-19 pandemic. The data was, likewise, divided into five clusters that were analyzed according to the tendency of having compulsive behavior. Approximately 12% of users were associated with high compulsive behavior, which represents an increase by 50% when compared to user behavior in 2019. Another conclusion that can be reached by analyzing and comparing clusters from 2019 and 2020 is that clusters from 2020 seem to be more extreme. This can be noticed by analyzing, specifically, the clusters associated with high compulsive behavior. In 2019 the cluster that represents users that have extreme negative balance values has a centroid in which the average balance value is -125,04. In 2020 the equivalent cluster has a centroid in which the average balance value is -138,89. This can also be noticed in the cluster that represents users that play with extreme frequency. In 2019 this cluster has a centroid in which the average number of days played is 191,86 and the average number of hours played is 3,87. In 2020 the equivalent cluster has a centroid in which the average number of days played is 262,77 and the average number of hours played is 4,33. Finally, when analyzing users that were present in both the 2019 and the 2020 datasets, it was possible to identify the percentage of users that shifted to different clusters. By doing this, and considering the 2019 clusters as the baseline, it was observed that, during the lockdown period, 43% of users did not change clusters. Of the remaining users, 37% of users shifted to clusters associated to more compulsive gambling behavior and 20% of users shifted to clusters associated to less compulsive behavior. To summarize, the results of this work, allow us to reach the conclusion that, during the most restrictive period of the lockdown, online gambling users, that are associated to compulsive behavior, became more representative and, on average, may have developed even more extreme habits. In the following section, the research questions that have guided this work will be answered, in an attempt to wrap up the most relevant objectives that were initially established. 58 4.1. ANSWERING RESEARCH QUESTIONS 1. Is it possible to identify specific user behaviors (clusters) based on the data from 2019 that can establish online gambling disorders? By implementing unsupervised ML techniques to user data from 2019 it was possible to identify clusters of users based on gambling habits. 2. Also based on the data from 2019, is it possible to identify a cluster of users that could be associated with online gambling problems? By performing the profiling of the clusters, it was possible to identify clusters of users clearly associated to more compulsive gambling behavior. One of these clusters is associated to a higher frequency of gambling and another is associated with a tendency to lose larger monetary amounts. 3. By comparing the segmentation results from 2019 and 2020 during the lockdown restrictions period, has there been a significant shift in cluster sizes? By comparing the clusters that were generated with data from 2019 and clusters that were generated with data from 2020, it is possible to verify that the percentage of users associated to clusters that indicate addictive behavior increased from 8% to 12%. This indicates that these clusters had a significantly higher representation in 2020, at least during the months of April, May, and June, which were the months in which harsher lockdown restrictions had been imposed in Portugal. 4. Did players, on average, engage in more intense gambling activities during the lockdown restriction periods? It was verified that, on average, users in 2019 played for 3 days each month and for 2.6 hours each day. In 2020 users played, on average, for 7 days each month and for 2.7 hours each day. This means that users engaged in more intense gambling activities during the months of April, May and June of 2020 when compared to the gambling intensity in 2019. 5. During the lockdown restrictions period, is it possible to determine if a certain number of players from other user clusters migrated to clusters of users with potential gambling disorders? During the lockdown period 37% of users migrated to clusters associated to more compulsive gambling behavior. 59 5. RECOMMENDATIONS FOR FUTURE WORK Based on what was developed during this work it is possible to build upon the acquired knowledge to undergo future improvements. A few recommendations will be listed below: - This type of analysis can be applied to other equivalent types of online gambling activities, such as sporting bets and other kinds of games of chance. - The analysis can be thought of in terms of individual gambling records instead of consolidated user activities. By doing this it would be possible to evaluate gambling habits based on its variation through time. This, however, would require extremely higher computational capabilities since it would involve stupendous amounts of data. - Other types of ML models can be applied and the ones that were applied can be improved with alternative configuration of the hyperparameters. - The models that were applied to the data can generate better results and greater insights if the data is complemented with categorical variables regarding the users, such as: age, gender, marital status, geographic location, and education level. With this type of information, users can be better classified, and this would help in identifying specific groups of users that are more susceptible to compulsive gambling behavior. 60 6. BIBLIOGRAPHY Aggarwal, C. C. (2017). Outlier Analysis. Springer. Alam, M. (2020). Statistical techniques for anomaly detection - Five statistical tools for rapid assessment of anomalies and outliers. Retrieved June 24, 2021, from Towards Data Science: https://towardsdatascience.com/statistical-techniques-for-anomaly-detection- 6ac89e32d17a Amelia, A. (2018). Retrieved August 30, 2021, from Towards Data Science: https://towardsdatascience.com/k-means-clustering-from-a-to-z-f6242a314e9a Bação, F., Lobo, V., & Painho, M. (2005). Self-organizing Maps as Substitutes for K-Means. In: Sunderam V.S., van Albada G.D., Sloot P.M.A., Dongarra J. (eds) Computational Science – ICCS 2005. ICCS 2005. Lecture Notes in Computer Science, vol 3516. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11428862_65 Bhandari, A. (2020). Feature Scaling for Machine Learning: Understanding the Difference Between Normalization vs. Standardization. Retrieved June 27, 2021, from Analytics Vidhya: https://www.analyticsvidhya.com/blog/2020/04/feature-scaling-machine-learning- normalization-standardization/ Birkett, A. (2019). How to Deal with Outliers in Your Data. Retrieved June 25, 2021, from CXL: https://cxl.com/blog/outliers/ Bishop, C. M. (2006). Pattern Recognition and Machine Learning. Springer. Bock, T. (n.d.). What are the Strengths and Weaknesses of Hierarchical Clustering? Retrieved August 19, 2021, from DisplayR: https://www.displayr.com/strengths-weaknesses-hierarchical- clustering/ Britannica. (n.d.). Artificial Intelligence. Retrieved June 15, 2021, from https://www.britannica.com/technology/artificial-intelligence Brownlee, J. (2016). Machine Learning Mastery With Python - Understand Your Data, Create Accurate Models and Work Projects End-To-End. Jason Brownlee. Calado, F., & Griffiths, M. D. (2016). Problem gambling worldwide: An update and systematic review of empirical research (2000–2015). Clark, L. (2014). Disordered gambling: the evolving concept of behavioral addiction. Clements, J. (2019). Introduction to Hierarchical Clustering - Uncovering Structure in State-level Demographic Data in R. Retrieved August 18, 2021, from Towards Data Science: https://towardsdatascience.com/introduction-hierarchical-clustering-d3066c6b560e Domingos, P. (2015). The Master Algorithm - How the Quest for the Ultimate Learning Machine Will Remake Our World. Basic Books. 61 European Comission. (2012). COMMUNICATION FROM THE COMMISSION TO THE EUROPEAN PARLIAMENT, THE COUNCIL, THE ECONOMIC AND SOCIAL COMMITTEE AND THE COMMITTEE OF THE REGIONS - Towards a comprehensive European framework for online gambling. Retrieved June 15, 2021, from https://eur-lex.europa.eu/legalcontent/EN/TXT/PDF/?uri=CELEX:52012DC0596&from=ET Galarnyk, M. (2018). Understanding Boxplots. Retrieved June 25, 2021, from Towards Data Science: https://towardsdatascience.com/understanding-boxplots-5e2df7bcbd51 Géron, A. (2019). Hands-on Machine Learning with Scikit-Learn, Keras, and TensorFlow - Concepts, Tools, and Techniques to Build Intelligent Systems. O’Reilly Media, Inc. Gupta, A. (2021). Elbow Method for optimal value of k in KMeans. Retrieved November 02, 2021, from Geeks for Geeks: https://www.geeksforgeeks.org/elbow-method-for-optimal-value-of- k-in-kmeans/ Håkansson, A. (2020). Impact of COVID-19 on Online Gambling – A General Population Survey During the Pandemic. Retrieved June 15, 2021, from https://www.frontiersin.org/articles/10.3389/fpsyg.2020.568543/full Han, J., Kamber, M., & Pei, J. (2012). Data Mining Concepts and Techniques. Elsevier. Henriques, R., Lobo, V., & Bação, F. (2012). Spatial Clustering Using Hierarchical SOM. In Applications of Self-Organizing Maps, Magnus Johnsson, IntechOpen. doi:10.5772/51159 Jain, A. K., Murty, M. N., & Flynn, P. J. (1999). Data Clustering: A Review. Kassambara, A. (n.d.). K-Medoids in R: Algorithm and Practical Examples. Retrieved November 02, 2021, from Data Novia: https://www.datanovia.com/en/lessons/k-medoids-in-r-algorithm- and-practical-examples/ KHAZRI, A. (2019). Self Organizing Maps (Kohonen’s maps). Retrieved September 03, 2021, from Towards Data Science: https://towardsdatascience.com/self-organizing-maps-1b7d2a84e065 Kho, J. (2019). Annotated Heatmaps of a Correlation Matrix in 5 Simple Steps. Retrieved July 01, 2021, from Towards Data Science: https://towardsdatascience.com/annotated-heatmaps-in- 5-simple-steps-cc2a0660a27d Kumar, S. (2020). Feature Engineering — deep dive into Encoding and Binning techniques. Retrieved June 29, 2021, from Towards Data Science: https://towardsdatascience.com/featureengineering-deep-dive-into-encoding-and-binning-techniques-5618d55a6b38 Kumar, S. (2020). Hierarchical Clustering: Agglomerative and Divisive — Explained - An overview of agglomeration and divisive clustering algorithms and their implementation. Retrieved August 17, 2021, from Towards Data Science: https://towardsdatascience.com/hierarchicalclustering-agglomerative-and-divisive-explained-342e6b20d710 Kumar, S. (2021). How to know which Statistical Test to use for Hypothesis Testing? - When to use which test — T-test, Chi-square Test, ANOVA. Retrieved July 01, 2021, from Towards Data 62 Science: https://towardsdatascience.com/how-to-know-which-statistical-test-to-use-for- hypothesis-testing-744c91685a5d LZP, J. (2019). Distance Measures and Linkage Methods In Hierarchical Clustering. Retrieved August 18, 2021, from Gitconnected: https://levelup.gitconnected.com/distance-measures-and- linkage-methods-in-hierarchical-clustering-8b7d488d7ebc Madsen, J. H. (2018). Outlier detection for improved clustering : empirical research for unsupervised data mining. Retrieved from http://hdl.handle.net/10362/34464 Mitchell, T. M. (1997). Machine Learning. McGraw-Hill Science/Engineering/Math. Patel, A. A. (2019). Hands-On Unsupervised Learning Using Python - How to Build Applied Machine Learning Solutions from Unlabeled Data. O’Reilly Media, Inc. Piech, C. (2013). K Means. Retrieved August 24, 2021, from Stanford: https://stanford.edu/~cpiech/cs221/handouts/kmeans.html Radečić, D. (2021). How to Make Stunning Radar Charts with Python — Implemented in Matplotlib and Plotly - Easily visualize data beyond the 2nd dimension with Radar Charts — implemented in both Matplotlib and Plotly. Retrieved October 05, 2021, from Towards Data Science: https://towardsdatascience.com/how-to-make-stunning-radar-charts-with-python- implemented-in-matplotlib-and-plotly-91e21801d8ca Russell, S. J., & Norvig, P. (2010). Artificial Intelligence - A Modern Approach. Pearson Education. Selecting the number of clusters with silhouette analysis on KMeans clustering - scikit-learn 1.0.1 documentation. (n.d.). Retrieved November 02, 2021, from https://scikitlearn.org/stable/auto_examples/cluster/plot_kmeans_silhouette_analysis.html Sharma, P. (2019). The Most Comprehensive Guide to K-Means Clustering You’ll Ever Need. Retrieved August 24, 2021, from Analytics Vidhya: https://www.analyticsvidhya.com/blog/2019/08/comprehensive-guide-k-means-clustering/ sklearn.cluster.Kmeans - scikit-learn 1.0.1 documentation. (n.d.). Retrieved November 02, 2021, from https://scikit-learn.org/stable/modules/clustering.html#k-means sklearn.neighbors.KNeighborsClassifier -scikit-learn 1.0.1 documentation. (n.d.). Retrieved from https://scikitlearn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html SRIJ. (2018). Serviço de Regulação e Inspeção de Jogos. Retrieved from https://srij.turismodeportugal.pt/pt/ Turismo de Portugal. (2019). Atividade do Jogo Online em Portugal - 4º Trimestre de 2019. Retrieved June 15, 2021, from https://www.srij.turismodeportugal.pt/fotos/editor2/estatisticas/Relatorio_4_trimestre_201 9_Jogo_Online_PT.PDF Whelan, C., Harrell, G., & Wang, J. (2015). Understanding the K-Medians Problem. 63 White, T. (2015). Hadoop: The Definitive Guide. O’Reilly Media, Inc. Widmann, M., & Heine, M. (2018). Four Techniques for Outlier Detection. Retrieved June 24, 2021, from Knime: https://www.knime.com/blog/four-techniques-for-outlier-detection Yiu, T. (2019). The Curse of Dimensionality - Why High Dimensional Data Can Be So Troublesome. Retrieved June 28, 2021, from Towards Data Science: https://towardsdatascience.com/thecurse-of-dimensionality-50dc6e49aa1e Zair, M., Rahmoune, C., & Benazzouz, D. (2018). Multi-fault diagnosis of rolling bearing using fuzzy entropy of empirical mode decomposition, principal component analysis, and SOM neural network.