# Time Series Clustering of Online Gambling Activities for Addicted Users' Detection
## 3 Experimental Phase
### Data  
Data used in the experimental phase came from ten different online gambling operators, each of which provides two monthly data sets containing sports and black jack bets' data, respectively. The data sets must follow specific rules regarding the type and format of the data to be stored. For each bet played, the following variables are available:  
* player_id: unique identifier of the player in the operator system. * player_logon: username of the player in the operator system. * cod_ficha: unique identifier for a bet. * cod_ficha_jog: gambling external code attributed by the online gambling operator. * cod_aptr_jog: betting code used by the online gambling operator. * timestamp_ini: start time of betting event. * timestamp_ini: end time of betting event. * timestamp: timestamp of the betting operation placed by a user. * a_saldo_ini: balance before the betting start. * a_valor: value of the bet. * a_saldo_fim: balance after betting close. * a_bonus_ini: player bonus before betting start. * a_bonus: bet bonus. * a_bonus_fim: player bonus after betting close. * g_ganho: amount won from the bet. The data preparation phase aims at obtaining two different data sets, one for each type of game involved, that contain the time series of users' bets. For this purpose, this phase consists of three steps: aggregation, concatenation, and time series creation. The last two phases are identical for both the considered games, while the aggregation phase differs between sports betting and black jack. Before looking at each of these three phases in detail, it is necessary to clarify the following: a time series of bets for a single user cannot be given by the sequence of the g_ganho of his/her placed bets, as these values represent the amounts won from the bets, but not those lost. Thus, they are not suitable for fully representing the players' behavior. To overcome this issue, the values composing the time series are obtained as the difference between the eventual g_ganho and the a_valor. In this way, each point of a given time series represents the final balance of a single bet, which can be positive, zero, or negative. More formally, we have:\(N\): number of gamblers. \(n_{i}\): number of bets placed by the player \(i\in\{0,\dots,N\}\). \(T_{i}=\{t_{0},\dots,t_{n_{i}}\}\) instants of bets for player \(i\). \(x_{t_{i}}=\texttt{g\_ganho}(t_{i})-\texttt{a\_valor}(t_{i})\) balance of the bet placed in \(t_{i}\in T_{i}\). By doing this, we obtain a set of time series \(X=\{x_{0},\dots,x_{N}\}\), where \(x_{i}=(x_{t_{0}},\dots,x_{t_{n_{i}}})\)\(\forall i\in\{0,\dots,N\}\). The aggregation phase aims at reducing the size of the initial data set by extracting relevant information used to create the time series data set. Given a raw data set, this procedure returns a table of nine columns in which a single row represents a bet, for which the following information is stored:  
* player_id
* player_logon
* cod_ficha
* cod_aptr_jog
* timestamp: the instant of the bet. * a_valor: value of the bet, including bonuses. * g_ganho: balance of the bet. g_ganho now represents the the final balance of a single bet, obtained as described before. Moreover, a_valor is stored to know the amount of money placed on a specific bet. This phase is different for black jack and sports bets. In the former case, each bet corresponds exactly to a single row, given the nature of this game in which a player knows immediately the outcome of a single hand. Concerning sports bets, a single bet can generate different rows in the raw data set because; even if the bet is already placed by a player, the odds can change. Thus, an intermediate step in which the value and the final balance of the bet is taken from the most recent line of the same bet (not considering the others) is needed. The concatenation phase has the goal of taking the aggregated data sets by type of game and joining them to obtain a single data set containing all the bets related to the considered game.