# A ResNet1D-AttLSTM-Based Approach for Ship Trajectory Classification
## 2 Methods
### Data Preprocessing  
Data quality plays a crucial role in classification algorithms based on neural network models, and the process of collecting ship trajectory data can introduce noisy data. Therefore, it is necessary to perform data preprocessing. Taking the AIS dataset as an example, the data preprocessing workflow is illustrated in Figure 1.  
Figure 1: Data preprocessing workflow. Noise removal is necessary because AIS data can contain false or erroneous information due to intentional tampering by third parties, operational errors, or system malfunctions during its generation. Missing value data, outlier data, and duplicate data are common types of noise found in AIS datasets, with specifics as follows:  
* **Missing value data** refers to records where critical attributes such as longitude, latitude, speed over ground, course over ground, and time are absent. * **Outlier data** includes records where the values for important attributes like longitude, latitude, speed over ground, course over ground, and time fall outside reasonable ranges. * **Duplicate data** consists of identical records that appear multiple times within the dataset. For these three types of noisy data, we adopt a deletion approach for handling them. Field selection aims to reduce the dimensionality of the dataset to lower computational complexity. In the AIS dataset, this paper selects seven key fields: maritime mobile service identity (MMSI), vesseltype, time, course over ground (COG), speed over ground (SOG), latitude and longitude. Other fields are removed. These selected fields effectively reflect the dynamic behavior and location information of vessels while minimizing redundant data. Additionally, category filtering refers to the process of removing data from all categories except those relevant to the study. Specifically, this involves retaining records from five specific types of vessels--towing vessels, fishing vessels, sailing vessels, passenger ships, and tankers--based on their distinct characteristics and the availability of sufficient data, while excluding data from other categories in the AIS dataset. This step is necessary because the original AIS dataset contains numerous ship categories, which could introduce unnecessary complexity and dilute the focus of the analysis. In the AIS dataset, certain types of vessels are overrepresented, resulting in a significantly larger volume of trajectory point data for these categories, while other types have relatively fewer data points. To address this imbalance and facilitate subsequent preprocessing steps, after completing the noise removal process, we performed random undersampling on the majority classes. This involved randomly removing a portion of the trajectory data for the overrepresented vessel types to achieve a more balanced distribution across all categories. As trajectory classification algorithms process objects composed of a series of ordered trajectory points forming trajectory segments, and the AIS dataset is a collection of numerous independent trajectory points, it is necessary to organize these isolated points into trajectory segments according to certain principles. In other words, we need to extract ship trajectory sequences. The method used for extracting ship trajectory sequences directly impacts the design of the classification algorithm; different extraction methods can generate trajectory sequences with varying important feature patterns, thus requiring the design of corresponding classification algorithms and the establishment of appropriate model hyperparameters. For instance, the significant features of trajectories differ across various time scales. If we define long-term trajectories as navigation records over three months and short-term trajectories as those within one hour, then, in long-term trajectories, characteristics such as anchoring habits, route selection, and destination preferences are more discriminative for ship types. In contrast, these features hold less importance in short-term trajectories.