## 3 Prototype Description
### Data Handling  
For the data handling, procedures were performed to remove inconsistent data such as no sales and unsuitable transaction types (credit sales receipts and payments). With these operations, 97 customers were removed, resulting in a total of 1748 customers in the base. Next, a normalization of the attributes was applied, since the K-means uses a distance measure, and the value range of the attributes varies according to their nature (monetary can present values in the thousands, while the other attributes are distributed in hundreds), which can negatively influence the results. Advanced data handling techniques have been exploited to improve the capability of artificial intelligence models [47]. The Min-Max method was used to normalize the attributes. The normalization by the Min-Max method performs a linear change in the data, which are transformed into a new interval [48]. Having a value \(v\) of an attribute \(A\) from interval \([min_{A},max_{A}]\), the value is transformed to the new interval \([n(min_{A}),n(max_{A})]\), which in the case of this application is between 0 and 1, considering:  
\[\frac{v-\ min_{A}}{max_{A}-min_{A}}\ (n(max_{A})-n(min_{A}))+n(min_{A}). \tag{1}\]  
By applying this method, the values (from Table 2) are converted, with a maximum value of 1 and a minimum value of 0, as presented in Table 3.  
Values close to 1 indicate that the attribute of the customer in question is high relative to all other customers, and values close to 0 indicate that the attribute is low relative to the others. An exception is the recency attribute, which due to the format in which it was acquired ends up having inverse values, having an acceptable recency if the value is close to 0 and a bad one if it is close to 1. For reasons of simplicity and consistency of measures, a simple transformation of the recency values was applied, subtracting the value from 1. After organizing the data, it is possible to present each customer in a 3D graph, with each axis representing an attribute as in Figure 1. It is possible to identify that although the data do not provide a natural cluster distribution, it does present a structure of its own, \begin{table}
\begin{tabular}{c c c c} \hline
**ID** & **Recency** & **Frequency** & **Monetary** \\ \hline
38 & 139 & 65 & 37,176 \\ \hline \end{tabular}
\end{table} 
Table 2: Structure of the obtained data. \begin{table}
\begin{tabular}{c c c c} \hline
**ID** & **Recency** & **Frequency** & **Monetary** \\ \hline
38 & 0.0074928 & 0.71910112 & 0.43890863 \\ \hline \end{tabular}
\end{table} 
Table 3: Structure of the data obtained after normalization. with many customers clustered in the left corner of the graph indicating a low frequency, distributed over several recency intervals, with few high-monetary-attribute customers. The segmentation and validation steps were performed in parallel since the algorithm used, K-means, requires the specification of the desired number of clusters. Internal and external validations were available to assist in the decision [49]. Through a statistical analysis of the 30 internal indexes researched, 10 prove to be recommendable for use. At the top of this list are the silhouette, Calinski-Harabasz, and Davies-Bouldin indexes. To generate the silhouette index for data, only two things are needed: the clusters obtained and the set of distances between all observed data, and for each \(i\), its respective Silhouette index \(s(i)\) is calculated. The average dissimilarity of the distances of \(i\) with the rest of the data in the cluster of \(i\), denoted by \(a(i)\), is evaluated [50]. Then, the minimum value between the distances of \(i\) and any other cluster is obtained (the neighboring cluster of \(i\) is then discovered, i.e., the cluster with which \(i\) would most fit if it were not in its original cluster), denoted by \(b(i)\).