Similar results have been obtained for the three buildings, and thus, without loosing generalization and for shortening the results, the performance for building A is shown in detail in the following. Moreover, the results for building A were the worst ones because the architecture of this building was more challenging for the algorithms (remember that building A was two triangles joined by their vertex).
In summary, CatBoost and Random Forest are the top-performing models, both achieving an accuracy of 97%. These models excel in handling the classification task with very few misclassifications. The SVM model follows closely with an accuracy of 94%. It is a reliable model but slightly less effective than CatBoost and Random Forest, so we can conclude that is a moderate performer. then, KNN and Decision Tree models show lower performance, with Decision Tree being the least accurate at 82%. These models struggle more with classifying certain instances, leading to higher misclassification rates.
Similar results have been obtained for buildings B and C. Those results are not included to avoid the repetition of similar figures.
In order to improve even more the performance, an optimization of the hyperparameters has been carried out.
GridSearchCV
In the field of machine learning, hyperparameter tuning is crucial for improving model performance. GridSearchCV, part of the scikit-learn library is a widely used technique for performing an exhaustive search over a specified parameter grid to identify the optimal hyperparameters for a given estimator. This process aims to maximize the model’s predictive accuracy by systematically evaluating combinations of hyperparameters.
GridSearchCV automates the process of hyperparameter optimization by conducting a brute-force search across a defined parameter space. Hyperparameters differ from learned parameters in that they are external to the model and cannot be estimated from the data during training. Examples include the learning rate in gradient descent or the number of trees in a random forest. Manually choosing these values is often infeasible, as models can contain multiple hyperparameters, each taking on numerous possible values.
The parameter grid is a dictionary that maps model parameters to lists of values to explore. For example, when tuning an SVM, the parameter grid might include various values of regularization () and kernel types.
The cross-validation technique, denoted as k-fold cross-validation, divides the dataset into k equally sized folds. For each hyperparameter combination, the model is trained on folds and validated on the remaining fold. This process is repeated k times, with a different fold serving as the validation set each time. The average performance metric across all folds determines the effectiveness of the hyperparameter set.
The loss function
L is computed as:
where
is a loss function (e.g., MSE for regression or log-loss for classification),
represents the true labels, and
represents the predicted labels for the
i-th fold.
Upon completion of the search, GridSearchCV provides the optimal hyperparameters that yield the best average performance across all folds. Additionally, it returns the estimator refit on the entire training set using these best parameters. This ensures that the model benefits from the full dataset while leveraging the best hyperparameter settings discovered during cross-validation.
Not all are advantages in this technique, as it can be imagine, one of the limitations of
GridSearchCV is its computational expense. The complexity increases exponentially with the number of hyperparameters and their values. If there are
p hyperparameters, each with
possible values, the total number of models evaluated is:
For high-dimensional or large datasets, this can become computationally prohibitive. In such cases, alternative techniques like RandomizedSearchCV, which samples a fixed number of random combinations from the grid, can be more efficient.
Although during GirdSearchCV process the dataset is recombined, it is worth noting that once the hyperparameter has been optimized, the training process is carried out as usual with the original dataset (training and validation) but with tuned hyperparameters, so that consistency is not compromised.
Thus, for the best algorithms, we have enhanced performance by using GS (GridSearchCV) to optimize the hyperparameters. This is,
GridSearchCV has been applied to CatBoost and Random Forest to tune their hyperparameters. The results of this enhancement are shown in
Figure 8. The number of samples in GridSearchCV exceeds that of the original dataset due to the cross-validation method employed. Initially, the dataset is divided into 70% for training and 30% for testing. Within
GridSearchCV, the 70% training portion is further divided into 5 subsets. The training and testing processes are then conducted five times, each time using one subset for testing while the remaining four are used for training. This approach is designed to identify the optimal hyperparameters. Once these hyperparameters are established, the model is evaluated on the remaining 30% of the dataset to assess its performance.
For example, the 70% training set is divided into five subsets: during the first iteration, the first subset is used exclusively for testing, while the others are used for training. In the second iteration, the second subset is used for testing, with the remaining subsets used for training, and so on.
As can be seen in this figure, the small problems in classifying floors 2 (1 in the image) and 3 (2 in the image) or 3 and 4 (2 and 3 in the image, respectively) using catBoost disappear after optimization with GridSeaarchCV. Similar behavior occurred with random forest and its optimized results.
On the other hand, building C has five floors instead of 4 as the other two buildings. In order to show the performance and for conciseness, only the performance obtained by the best techniques, i.e., CatBoost, and Random Forest, is shown for this building. In
Figure 9, the distribution of samples for each of the floors is plotted. As in the other cases, a regularization to obtain the same number of samples for all the floors is carried out.
In this building, the best models are still CatBoost and Random Forest, with 93% initial accuracy. However, after applying the
GridSearchCV technique, their performance boosted up to 98% and 99%, respectively, as can be observed in
Figure 10. Looking into more detail, CatBoost (Image a) obtains Accuracy: 0.93, Weighted Precision: 0.93, Weighted Recall: 0.93 and Weighted F1-Score: 0.93. This model shows good overall performance, with most classes being well classified, especially floor 4 (3 in the figure). However, there is some confusion when classifying floor 5 (4 in the image) that sometimes it is classified as floor 3 (4 in the image), suggesting the model struggles to differentiate between these two floors. After CatBoost is Optimized with GridSearchCV (Image b), the performance increases to Accuracy: 0.98, Weighted Precision: 0.98, Weighted Recall: 0.98 and Weighted F1-Score: 0.98. The optimization through
GridSearchCV significantly improved the model’s performance. There is a noticeable increase in precision, recall, and F1-Score compared to the non-optimized model. Floors 1 (0 in the figure) and 4 (3 in the figure), which previously showed some confusion, are now almost perfectly classified, with very few incorrect predictions.
On the other hand, Random Forest (Image c) obtains Accuracy: 0.93, Weighted Precision: 0.93, Weighted Recall: 0.93 and Weighted F1-Score: 0.92. The Random Forest model performs similarly to the non-optimized CatBoost, with an accuracy of 0.93. However, it shows more confusion between floors 4 (3 in the figure) and 5 (4 in the figure) compared to CatBoost, reflected in a lower F1-Score for these floors. The model seems less effective at distinguishing between certain classes, particularly floor 5 (4 in the figure). Then, after it is Optimized with GridSearchCV (Image d), Random Forest obtains the following: Accuracy: 0.99, Weighted Precision: 0.99, Weighted Recall: 0.99, and Weighted F1-Score: 0.99. As with CatBoost, optimization with GridSearchCV significantly improves the Random Forest model’s performance. The metrics are very high, with an accuracy of 99%. Nearly all classes are perfectly classified, indicating that the optimized model is highly effective. We can conclude that optimization with GridSearchCV significantly improves the performance of both models. This is evident in the increase in all key metrics (accuracy, precision, recall, F1-Score). Moreover, before optimization, both models performed similarly. However, after optimization, both achieved near-perfect performance, with the optimized Random Forest model showing a slight edge in metrics, reaching 99% in precision, recall, and F1-Score. Both models, before optimization, show difficulty distinguishing between floors 4 and 5 (3 and 4 in the figure, respectively). However, optimization nearly eliminates this confusion.
In summary, both CatBoost and Random Forest are strong models for this classification task, but hyperparameter optimization is crucial for maximizing their performance. The Random Forest model optimized with GridSearchCV provides the best performance in this case, with near-perfect classification.
These two techniques allow a very high accuracy (nearly 100%) for the classification of the floor, which, when combined with the high accuracy in the building identification, provides the best conditions for the last step, the estimation of the latitude and longitude.