## 2 Materials and Methods
### Definition of a Post-Processing Algorithm
If the precedent condition does not subsist, the distance is computed between the probability value of the record and the median value (across all records with that same combination of predicted and occurred scenarios) for all the other four classes (excluding the one of the main label), and the second label is chosen as the one whose assignment probability has the largest distance from the median; e.g., if a record has a predicted label = \(x\), but \(px_{xx,i}<\overline{px_{xx}}\), then all the distances \(dk_{i}=pk_{xy,i}-\overline{pk_{xy}}\) are computed for \(k=1\)... 5 and \(k\
eq x\), and the selected second label is \(k\) for which \(dk_{i}\) is max. With this procedure, a second label is assigned representing the second-likely scenario as expected by the algorithm. However, not all combinations of double-labeling are accepted: if the first label is '1' (no diffusion at all), the second label can only be '1' or '2' (no diffusion but oscillations can be expected); if the first label is '2', the second label can only be '1', '2', or '5' (active spreading with increasing curve); if the first label is either '3', '4', or '5' (active diffusion with decreasing, stable, or increasing curve), the second label can only be among '3','4', or '5', thus distinguishing between 'no diffusion' scenarios ('1' and '2') and 'active spread' scenarios ('3', '4', and '5'). Validation of the results was performed retrospectively on the entire dataset of 19,550 records. Predictions were classified into 4 different hierarchical quality levels:  
* Prediction of level A: the scenario indicated by the first label actually occurred
* Prediction of level B: the scenario indicated by the second label actually occurred
* Prediction of level C: neither the scenario indicated by the first or the second label occurred, but the scenario occurred is directly adjacent (scenario '2' occurring with a double label '11', '1' with '22', '3', or '4' with '25', one in '3', '4', or '5' with labels > 3)
* Prediction of level D: a completely different scenario from the two labels occurredThe share of these prediction classes was computed for the entire dataset, and separately for the 'no diffusion' scenarios actually occurred (true label = '1' or '2') and for the 'active spread' scenarios actually occurred (true label = '3', '4', or '5'). The final model is composed of the following functional blocks:  
Data computation: time-series of daily calls to EMS and of ambulances dispatched, with etiology for respiratory and infective issues, on territorial areas (dynamic weighted districts centered on each municipality), normalized on the resident population of the area; each record thus corresponds to 7 days of time-series in one territorial area. Derived attributes computation: additional attributes extracted from the signal are computed for each record, including statistical indicators, linear and exponential regression parameters. Training set preparation: records are labelled retrospectively on the basis of the data relevant to the following 7 days, including data from 1 January 2020 to the most recent (the training set was re-computed every 2-to-4 weeks according to the epidemiologic phases); the training set is balanced, thus has the same amount of labels for each class (1 to 5). Data pre-processing: data order is shuffled; outliers are identified through z-index (due to data non-normality) with a threshold set to 5, and records with outliers are removed; all attributes are rescaled in the 0-1 range on the entire training set. External set preparation: the same process of data computation, attributes computation and pre-processing (scaling with the parameters computed on the training set) is applied for new data to be classified (the last 2-to-4 weeks, depending on the periods, excluded from the training set). Algorithm training: the random forest algorithm is trained with the previously defined dataset; on the last available training set, the grid search parameters tuning resulted in a set of 150 classification trees with 40 layers of nodes.