## 2 Data and Methodology
### Adaptation of Calibrated Wind Speed Series to ROSEO-BIWT's Peculiarities
#### 2.4.2 Prediction of Wind Direction via Random Forest  
Since the direction from which the building receives the wind greatly affects the concentrating or obstructing effect of the building's geometry, a method to predict the past wind direction is necessary in order to use historical data for wind resource estimation. The random forest (RF) algorithm was chosen for this task because of its ability to use different types of inputs and evaluate its relevance, so it can be fed with the historical reanalysis data already on hand without any previous variable selection. Apart from that, being an ensemble learning method means that it is more robust and less likely to overfitting than single decision trees. Predicting a variable, such as the on-site wind direction, is tricky because it is a numerical cyclical variable. For instance, the values 360\({}^{\circ}\) and 0\({}^{\circ}\) refer to the same direction. However, the low resolution of the anemometer's wind direction data, which only differentiates between 16 directions, means that it behaves more like an ordinal cyclical variable. Apart from that, there is no way that we are aware of to make a random forest predict a cyclical variable, be it numerical or ordinal. For that reason, the on-site wind direction variable is treated as categorical, even if it means some loss of information. The reanalysis data used in the calibrations is used as input. Since the comparison of the grid points' wind speed showed that they are very similar, only the wind speed of the closest point was used, while the 9 variables of wind direction were used. The month of each data point was also added as a predictor, since the seasonal calibration's performance already showed that there are changes on the relationship between the modeled and the measured wind throughout the year. The month to which each data point corresponds is encoded as a categorical variable for the same reasons exposed for the on-site wind direction: few cases and cyclical nature. That gives a total of 11 input variables to predict a categorical variable with 16 classes. The number of variables randomly sampled as candidates at each split was set to 3, following the advice given by [PERSON] et al. (2018), which states that this number should be set to the root square of the number of predictors. The number of trees for the RF was set to 500. The tuning and posterior use of the algorithm was made in a similar fashion to that of the calibrations: first, the tuning and validation were made using the training and testing data sets, respectively, and, once the correct parameters were found, an RF was generated without using cross-validation (that is, using both sets), and then it was used to predict the on-site wind direction for the period ranging from 2010 to 2019. The tuning involved dealing with the unbalanced nature of the on-site wind direction, which the count of measured wind directions displayed in Figure 8 shows. Without any tuning, the algorithm tended to overestimate the frequency at which wind comes from the south-west. Such a bias would mean that the power that a turbine located on the south side of the roof would be overestimated, creating unrealistic expectations of the installation's viability. The problem was solved with a combination of cost sensitive learning and pruning. On the one hand, the algorithm was forced not to have any bias towards the majority classes by assigning all classes (that is, each one of the 16 possible wind directions) the same weight. This is an adaptation of the approach that [PERSON] et al. (2019) call \"Weighted Random Forest\", in which the less represented classes are assigned a higher weight or misclassification cost. Giving all the classes the same weight eliminated the need to calculate the weight of each class, which would be specially difficult given that we are dealing with 16 of them, and proved to be good enough for our purposes.