# Applying Machine Learning to Preselective Weighing of Moving Vehicles
## 4 Vehicle Weight Estimation Model Using Machine Learning Algorithm
### Preparation of Useful Learning Data  
Useful learning data (training data) for developing a model to estimate vehicle weights using a machine learning algorithm was obtained from the WIM station locations in Grodziec and Oswwiec on the DK4 national road. Data were collected between November 2022 and November 2023. The data are organized into 24 database files for both locations, each containing more than 100,000 records. The total size of the dataset for the Grodziec location is 684 MB, while for the Oswiec location, the data occupies 813 MB of disk space. This results in millions of data records, providing more than sufficient input for training most machine learning models. Each vehicle measurement is represented as a row in the database. The data features (columns), along with descriptions and example values, are presented in Table 1. Certain features need to be modified, scrambled, or removed to train the machine learning model for weight estimation, specifically the following:  
* Features containing information that was estimated by the ML model (weight) or features explicitly linked to it are marked in red;
* Features that do not provide useful information regarding vehicle weight estimation are marked in orange. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Feature** & **Description** & **Benchmark Value** \\ \hline Location & WIM sensor location & EN-DK45 OSOWIEC-KLU \\ Year & Year of registration & 2022 \\ Month & Month of registration & 1 \\ Day & Day of registration & 1 \\ Hour & Time of registration & 1 \\ Minute & Minute registration & 24 \\ Sec. & Registration second & 37 \\ Milisecond & Millisecond registration & 748 \\ Lane & The lane in which the vehicle was traveling & 11 \\ Speed & Vehicle speed & 88 \\ Length & Overall length of the vehicle & 97 \\ Weight & Gross vehicle weight & 38 \\ AVC & Automatic Vehicle Classification & 11 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Examples of acquired data for training the model using a machine learning algorithm [own development]. Features for which one-hot encoding was applied are highlighted in green. One-hot encoding enabled the machine learning model to interpret categorical values as input correctly. This encoding allows machine learning models to effectively analyze and train on data by treating categories as distinct classes. Some features, such as hours and minutes, exhibit a cyclic nature. Cyclic encoding (highlighted in blue) captured these features' periodic characteristics. Lastly, features that were not modified before being fed into the ML model are shown in purple. Thus, the features that were utilized by the model, either directly or after applying some preprocessing steps, are highlighted in blue, purple, and green. Table 1 shows the set of features (features) used to train the XGBoost machine learning (ML) model for vehicle weight estimation. The different rows have been marked with different colors depending on their role in the model. The green color is the features encoded by the one-hot encoding method. These are categories (e.g., post-vehicle class, country of registration) that cannot be directly used as numbers in the ML model. One-hot encoding was used, i.e., converting categorical values into binary variables (e.g., country of registration \"PL\" \(\to 1\); other countries \(\to 0\)). The blue color refers to features that are cyclic in nature, such as the time or month of the ride registration. The purple color includes data such as vehicle length, number of axles, distance between axles, and vehicle speed. These data directly affect the prediction of vehicle weight and are used in the model in its original form. Histograms on Figures 3-6 depicting the distributions of sample feature values for a subset of the Grodzic location data are provided below. The histograms presented below show the distributions of values of selected features from the dataset for the Grodzic location.