# Machine Learning for Evaluating Hospital Mobility: An Italian Case Study
## 3 Materials and Methods
### Cluster Analysis  
The workflow used for cluster analysis in Orange software is illustrated in the orange box of Figure 2. To calculate intraregional active mobility in kilometers, we initially determined the interpolated distance between the capital city of the _ASL/USL_ where the patient resides and the city where the service-providing hospital is located (_Dist kmHospi_). We then aggregated the total active hospitalizations by _ASL/USL_ (_HospiASL/USL_) and by territorial area (_HospiArea_) for each hospital. The intraregional active mobility in kilometers was calculated using the following formula:  
\[Active\ mobility=(HospiASL/USL+HospiArea)*Dist\ km_{Hospi} \tag{1}\]  
This calculation considers patient movement to a different territory from their residence as motivated by a perceived higher quality of service. To transform active kilometric mobility, originally a continuous variable, into a categorical variable reflecting a mobility gradient (low, medium, high) based on the distance patients travel to the hospital, we employed the K-means clustering algorithm. This approach allowed us to investigate the impact of various variables more accurately on hospital choice, enhancing our understanding of the perceived quality of care. The K-means algorithm is crucial in data analysis for its ability to divide a dataset into K distinct clusters, minimizing the sum of squared distances between the data points and the cluster centroids. This process is effectively synthesized by the following formula:  
\[J=\sum_{i=1}^{k}\sum_{x\in C_{i}}\lVert x-\mu_{i}\rVert^{2} \tag{2}\]  
where \(k\) is the number of clusters, \(C_{i}\) is the set of points in cluster \(i\), \(x\) is a point in \(C_{i}\), and \(\mu_{i}\) is the centroid of \(i\), reflecting how the algorithm minimizes the internal variances of the clusters to effectively group the data based on their intrinsic characteristics. Its applicability ranges from exploratory data analysis to market segmentation, highlighting its importance in various fields such as biology, marketing, and network optimization [26]. The simplicity and efficiency of K-means in processing large datasets make it essential for identifying hidden patterns and guiding data-based decisions. Its ability to adapt to complex optimization problems and improve network coverage highlights its versatility, making it a valuable tool for optimizing resources and strategies [27]. The implementation of the K-means clustering algorithm in Orange software, using the K-means widget and the Silhouette widget, aimed to categorize active kilometric mobility into three distinct levels: low, medium, and high. This methodological choice was supported by a preliminary analysis, which revealed a silhouette coefficient of 0.724, indicating a significant separation and internal cohesion among the identified clusters. The average kilometric mobility values for the three clusters are illustrated in the box plots in Figure 3. We outlined three main groups: cluster C1, with 81 hospitals and an average mobility distance of 15,191.7 km, indicative of \"low\" mobility; cluster C2, comprising 17 hospitals with an average distance of 400,618 km, associated with \"high\" mobility; and cluster C3, aggregating 29 hospitals with an average distance of 122,101 km, corresponding to \"medium\" mobility. The term \"medium mobility\" refers to the average kilometers traveled in 2021 by patients residing in the hypothetical macroregion (Apulia-Emilia-Romagna) to the chosen facility. This segmentation provides a solid empirical foundation for delving into healthcare access dynamics, highlighting the importance of the distance patients travel in choosing a hospital, and offers key insights for optimizing healthcare services based on population mobility needs. Table 3 provides fundamental descriptive statistics, including mean, median, minimum, and maximum values for eight key numeric features of the dataset.