# A Traffic-Based Method to Predict and Map Urban Air Quality
## 2 Materials and Methods
### Modeling
#### 2.4.2 Data Preparation and Assessment  
In order to prepare the dataset, the raw data (5-s step) measured at street level using Microdust Pro were smoothed by performing a running average on two minutes to mitigate the noise created by artefactual events (e.g., sudden passage of a bus). The concentration of PM\({}_{2.5}\) was divided into two classes, low and high, depending on the median of the values of each day of measurements. The median value of PM\({}_{2.5}\) did not vary significantly from one day to another (mean = 40.7 \(\mathrm{\SIUnitSymbolMicro m}^{-3}\); standard deviation = 7.8 \(\mathrm{\SIUnitSymbolMicro m}^{-3}\)) and can be, consequently, considered as a standard concentration. Furthermore, this value is between the national standard (50 \(\mathrm{\SIUnitSymbolMicro m}^{-3}\)) and WHO health recommendations (25 \(\mathrm{\SIUnitSymbolMicro m}^{-3}\)) for 24-h PM\({}_{2.5}\) concentrations.  
Choosing the median as a threshold allowed us to get balanced classes (same number of instances in each class). If the classes are unbalanced, the machine learning algorithms tend to classify on the majority class (i.e., the class with the highest number of instances), which provides a misleadingly high accuracy by raising the baseline (i.e., the benchmark if the classification is simply based on the majority class). On the contrary, by using the median, we assure that the classification baseline is 50% (random choice between the two possible classes). Thus, the objective is to produce a model that gives an accuracy of classification significantly better than 50%, with the simplest tree as possible (no more than three nodes).  
The models were tested through a 10-fold cross-validation. This method is the best alternative when the dataset is relatively small. Cross-validation is a procedure that partitions the data into non-overlapping samples (or folds). Usually, \(k=10\) folds is chosen, which means that the data are randomly partitioned into 10 equal parts, where each fold has 10% of the instances. A model is then fit k times. Each time, one of the folds serves as the testing set and the remaining \(k\)-1 folds are used as the training set. Consequently, each fold is used once as the training set to make a prediction for every record in the dataset. The overall performance of the model is then obtained by combining the model's predictions on each of the k testing sets [34]. Equation (3) describes the formula used to calculate the accuracy of the prediction.  
\[accuracy=\frac{TP+TN}{TP+TN+FP+FN} \tag{3}\]  
where _TP_ stands for true positives (PM\({}_{2.5}\) concentrations > median) and _TN_ stands for true negatives (PM\({}_{2.5}\) concentrations < median). These variables are the correctly classified instances. The wrongly classified observations _FP_ and _FN_ are false positives and false negatives, respectively.  
Instead of predicting a spectrum of concentrations through a regression technique, this study is interested in a binary discrimination between high levels of contamination, which present a risk for public health, versus acceptable levels. This choice is supported by the recommendations of the WHO, which defines a standard threshold, and related work proposing a machine learning approach to classify air pollution [26; 35; 36; 37; 38].