## 3 Hierarchical Trajectory Clustering Algorithm
### Data Preprocessing
#### 3.1.1 Data Cleaning  
Data cleaning ensures accuracy and reliability in data analysis; this involves systematically identifying and correcting errors or inconsistencies within a dataset. The main objectives of data cleaning include removing irrelevant, duplicate, or incorrectly entered data and mitigating missing values through deletion or replacement. We set the applicable  
Figure 2: Data preprocessing process.  
sea area for the ship navigation data and used the ship's speed to remove noise and outliers. To measure the similarity of ship trajectories, which was the next step, ship identification numbers classified ship navigation data, and the direction of data progression was organized. Missing values refer to data that has not been assigned or could not be measured. The presence of missing values indicates sample incompleteness, which can lead to data bias, negative bias in analysis results, and poor prediction performance [37]. Missing values can be addressed through either removal or imputation techniques, depending on the nature of the data and the analysis requirements. However, the analysis results may be distorted depending on the processing method; therefore, careful processing is necessary. It involves replacing missing values with values estimated based on the available data to maintain the integrity of the dataset for analysis. Among the various techniques, unassigned values are filled in by linear interpolation, which is computationally simple and can be processed quickly, making it applicable to real-time systems and providing stable results [38]. The number of ships that sailed in the surveyed area varies depending on the ship's speed. Thus, imbalanced data are a situation in which the amount of data belonging to a specific class is significantly larger or smaller than that in other classes; this is recognized as an important issue in data analysis and the learning process of machine learning models. Processing imbalanced data are important for maximizing the model's prediction performance and securing fair prediction power for all classes [39]. A standard for the number of data points for each ship identification number is required to equalize the number of data points. In this study, considering the computer performance and data processing speed, the data points for each ship identification number were unified to 50 at the researcher's discretion.  
The data cleansing process applied in this study is summarized as follows: First, noise and outliers in the ship speed data were identified and removed. In the designated area of interest, the section between Mokpo Port and Seongnamdo, part of the traffic separation scheme, has no specific speed limit; however, when passing through Mokpo waters, a speed limit of 20 knots or less is enforced. To remove anchored or moored ships and those engaged in fishing activities within the target sea area, vessels with speeds under 6 knots were excluded. Data with ship speeds over 30 knots, deemed erroneous, were also removed. In the next step, irregular or erroneous data were also removed, such as those with excessively large gaps between AIS data points that could lead to errors in constant-speed model estimation. Finally, the dataset was first separated using different MMSIs, and a ship route dataset for each MMSI was established. Since the directionality of ships entering and leaving the port differs, the data were organized starting with north-eastward data to prevent errors in subsequent data processing steps. To address the noise caused by non-standard patterns in the irregular time intervals of latitude and longitude data representing the ship's position, linear interpolation was used to refine the dataset.