A ship classification and prediction method and system based on cosine similarity optimization
By combining cosine similarity optimization and random forest model, the problem of sample imbalance in ship classification is solved, achieving high-precision ship classification and fuel consumption prediction, thus improving operational efficiency and accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- COSCO SHIPPING TECH CO LTD
- Filing Date
- 2025-07-25
- Publication Date
- 2026-07-24
AI Technical Summary
Existing ship classification methods suffer from sample imbalance, resulting in insufficient training samples for the model, decreased accuracy of the classification model, and inability to effectively utilize the similarity between ships, thus affecting the accuracy of fuel consumption prediction and operational efficiency.
The cosine similarity optimization method is used to reclassify ship categories, merging categories with insufficient sample size into the multi-sample category with the highest similarity, and then training the model with a random forest model to construct a ship classification prediction model.
It improved the accuracy and generalization ability of the ship classification model, reduced classification errors, ensured the accuracy of fuel consumption prediction and operational efficiency, and achieved an upgrade from manual classification to automatic model classification.
Smart Images

Figure CN120804915B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of maritime management and artificial intelligence technology, specifically to a ship classification and prediction method and system based on cosine similarity optimization. Background Technology
[0002] In modern ship management and fuel consumption forecasting, the classification of different ship types has a crucial impact on the accuracy of forecasting models and operational efficiency. A ship's fuel consumption is closely related to its structural dimensions, performance parameters, and operational status. Therefore, scientifically classifying individual ships can not only improve the accuracy of fuel consumption forecasting models but also provide important support for shipping companies' operational optimization, fuel cost control, and environmental protection.
[0003] Ship classification methods often rely on expert experience, grouping individual vessels into different categories (groups) based on characteristics such as size, intended use, and load capacity. These classifications are typically based on subjective judgment, such as tonnage, draft, speed, or engine type. However, with the diversification of ship types, classification relying solely on human experience faces several problems: 1) Imbalanced sample size: Some ship categories contain only a very small number or even a single type of vessel, resulting in insufficient training samples for the model. The classification model cannot effectively learn the characteristics of these categories, leading to decreased model accuracy; 2) Insufficient generalization ability: Traditional models perform poorly when dealing with imbalanced samples, and predictions for single ship categories are prone to bias. This bias not only affects fuel consumption prediction but may also lead to errors in management and operational decisions by shipping companies; 3) Inability to effectively utilize similarities: Different ships may share certain similarities, such as ships of similar size but different uses. Reclassifying these ships based on similarity would help improve the performance of the classification model. However, traditional methods struggle to fully capture these similarities.
[0004] In view of this, there is an urgent need for a ship classification and mapping method that combines cosine similarity and machine learning to solve the problem of imbalanced samples and achieve accurate ship classification and management. Summary of the Invention
[0005] To address the problems of sample imbalance, insufficient model generalization ability, and ineffective utilization of similarity in existing ship classification processes, this invention provides a ship classification and prediction method based on cosine similarity optimization. This method effectively solves the sample imbalance problem in ship management and fuel consumption prediction, while also effectively filtering out noise interference in the data, ensuring the stability and reliability of the final classification results, and significantly improving the accuracy and generalization ability of the ship classification and prediction model. This invention also relates to a ship classification and prediction system based on cosine similarity optimization.
[0006] The technical solution of the present invention is as follows:
[0007] A ship classification and prediction method based on cosine similarity optimization, characterized by the following steps:
[0008] Ship Feature Acquisition and Preliminary Classification Steps: Collect multidimensional raw feature data of ships, encompassing their physical characteristics and performance parameters reflecting their power level and operational efficiency. Preprocess the collected multidimensional raw feature data. Based on the preprocessed multidimensional raw feature data and combined with empirical rules, perform preliminary classification of ships to obtain preliminary classification results containing multiple ship categories. Then, count the number of samples for each ship category in the preliminary classification results. Ship categories with a sample number less than a preset threshold are recorded as categories to be optimized, and other ship categories are recorded as reference categories.
[0009] Ship category optimization steps: Each feature parameter in the preprocessed multidimensional original feature data is converted into a feature vector. Based on the feature vectors, the cosine similarity between each ship in the category to be optimized and all ships in the reference category is calculated using the cosine similarity method, thus generating a cosine similarity matrix. The target ship with the highest similarity to each ship in the category to be optimized is then found in the cosine similarity matrix, and the category label of each ship in the category to be optimized is updated to the ship category to which the corresponding target ship belongs. After all ships in the category to be optimized have been reclassified, the category to be optimized is deleted, thus obtaining the optimized ship classification result.
[0010] Model building and training steps: The preprocessed multidimensional original feature data and the optimized ship classification results are used as the dataset. The dataset is divided into training set and test set according to the preset ratio. The training set is input into the random forest model for training. The trained random forest model is obtained and tested and analyzed through the test set to verify the model performance. The final trained and tested ship classification prediction model is obtained.
[0011] Model category prediction steps: Use the ship classification prediction model to predict the category of the new ship to be detected, and predict the ship category to which the new ship belongs.
[0012] Preferably, in the ship feature acquisition and preliminary classification step, the preprocessing includes processing missing values and removing outliers from the original multidimensional feature data to obtain processed multidimensional feature data; and using a standardization processor to standardize the processed multidimensional feature data to obtain standardized feature data.
[0013] Preferably, in the model construction and training steps, the preset ratio is 70%-80% for the training set and 20%-30% for the test set; the random forest model is an ensemble learning model based on decision trees, consisting of 100 independent decision trees. During the training of each decision tree, a subset of samples is generated by random sampling with replacement from the training set, and a subset of features is randomly selected during each node split; at the same time, the maximum depth of each decision tree is set to 20; after all decision trees are trained, the final prediction result is determined by ensemble voting.
[0014] Preferably, in the model building and training steps, the model performance is verified through testing and analysis using a test set, specifically including:
[0015] The performance of the trained random forest model is evaluated using a test set and evaluation metrics, including detection speed, detection accuracy, and complexity. Detection accuracy includes precision, recall, and average precision. Detection speed is measured by the number of samples processed per second, and complexity is measured by the number of parameters and the number of floating-point operations.
[0016] Preferably, the accuracy calculation steps specifically include: inputting each ship data in the test set into the trained random forest model and outputting the prediction result; and based on the prediction result and the real labels manually annotated for each ship data in the test set, counting the true positives, true negatives, false positives and false negatives, and calculating the accuracy based on the true positives, true negatives, false positives and false negatives.
[0017] Preferably, in the ship feature acquisition and preliminary classification step, the physical characteristics in the multidimensional original feature data include deadweight tonnage, gross tonnage, net tonnage, length, beam, design draft, displacement, depth, main engine cylinder diameter, and number of main engine cylinders. The performance parameters reflecting the ship's power level in the multidimensional original feature data include main engine stroke type, maximum power, braking power, operating power, total main engine horsepower, and total main engine power. The performance parameters reflecting the ship's operating efficiency in the multidimensional original feature data include design speed, maximum speed, and operating speed.
[0018] A ship classification and prediction system based on cosine similarity optimization is characterized by comprising, in sequence, a ship feature acquisition and preliminary classification module, a ship category optimization module, a model building and training module, and a model category prediction module.
[0019] The ship feature acquisition and preliminary classification module collects multidimensional raw feature data of ships, covering their physical characteristics and performance parameters reflecting their power level and operating efficiency. It preprocesses the collected multidimensional raw feature data and, based on the preprocessed data and empirical rules, performs a preliminary classification of ships, resulting in a preliminary classification result containing multiple ship categories. Then, it counts the number of samples for each ship category in the preliminary classification result, designating ship categories with fewer than a preset threshold as categories to be optimized, and designating other ship categories as reference categories.
[0020] The ship category optimization module converts each feature parameter in the preprocessed multidimensional original feature data into a feature vector. Based on the feature vector, it calculates the cosine similarity between each ship in the category to be optimized and all ships in the reference category using the cosine similarity method, thereby generating a cosine similarity matrix. Then, it finds the target ship with the highest similarity to each ship in the category to be optimized in the cosine similarity matrix, updates the category label of each ship in the category to be optimized to the ship category to which the corresponding target ship belongs, and deletes the category after all ships in the category to be optimized have been reclassified, thus obtaining the optimized ship classification result.
[0021] The model building and training module takes the preprocessed multidimensional original feature data and the optimized ship classification results as the dataset, divides the dataset into training set and test set according to a preset ratio, inputs the training set into the random forest model for training, obtains the trained random forest model, and tests and analyzes it through the test set to verify the model performance, and obtains the final trained and tested ship classification prediction model.
[0022] The model category prediction module uses the ship classification prediction model to predict the category of the new ship to be detected, thus predicting the ship category to which the new ship belongs.
[0023] Preferably, in the ship feature acquisition and preliminary classification module, the preprocessing includes processing missing values and removing outliers from the multidimensional original feature data to obtain processed multidimensional feature data; and using a standardization processor to standardize the processed multidimensional feature data to obtain standardized feature data.
[0024] Preferably, in the model building and training module, the model performance is verified through test analysis using a test set, specifically including:
[0025] The performance of the trained random forest model is evaluated using a test set and evaluation metrics, including detection speed, detection accuracy, and complexity. Detection accuracy includes precision, recall, and average precision. Detection speed is measured by the number of samples processed per second, and complexity is measured by the number of parameters and the number of floating-point operations.
[0026] Preferably, in the model building and training module, when testing and analyzing the model performance using a test set to verify its performance, the accuracy calculation steps specifically include: inputting each ship data in the test set into the trained random forest model and outputting the prediction result; and based on the prediction result and the manually labeled real labels of each ship data in the test set, counting true positives, true negatives, false positives, and false negatives, and calculating the accuracy based on the true positives, true negatives, false positives, and false negatives.
[0027] The technical effects of this invention are as follows:
[0028] This invention provides a ship classification and prediction method based on cosine similarity optimization, which is used to solve the sample imbalance problem in ship management and fuel consumption prediction, and improve the accuracy and generalization ability of the classification model. The first step is ship feature acquisition and preliminary classification. This involves collecting multi-dimensional raw feature data of ships (including physical characteristics, power performance parameters, and operational efficiency performance parameters) and preprocessing it. Then, based on empirical rules, preliminary classification of ships is performed, resulting in a preliminary classification of multiple ship categories. By utilizing existing knowledge systems to quickly establish a classification framework, it helps to quickly identify common ship categories, improves initial classification efficiency, and provides a reliable starting point for subsequent optimization. At the same time, it reduces the risk of misclassification caused by relying entirely on algorithms, improving system stability. Next, the number of samples for each ship category in the preliminary classification results is counted. Ship categories with fewer than a preset threshold are marked as categories to be optimized, while other ship categories are marked as reference categories. That is, the "categories to be optimized" with insufficient sample size and the "reference categories" with sufficient sample size are selected. This allows the system to dynamically adjust the classification strategy, effectively avoiding classification errors or model overfitting problems caused by scarce samples. Preliminary classification based on empirical rules quickly achieves the initial classification of ships and clarifies the classification framework. At the same time, the "categories to be optimized" (small sample categories) are identified by selecting based on sample size, accurately locating the weak links in the classification (small samples are prone to classification bias), providing a clear target for subsequent optimization. Next is the ship category optimization step. For categories with insufficient sample size after initial classification, the cosine similarity method is introduced to reclassify the categories. By utilizing the similarity between ships, ships with similar features are grouped into the same category. This makes the optimized ship classification results more consistent with the actual distribution of ship features and can accurately reflect the inherent correlation between different ships. It ensures that even categories with a small number of samples can obtain reasonable classification results. This not only improves the comprehensiveness of the classification but also reduces model bias caused by sample sparsity. It effectively solves the sample imbalance problem in ship management and fuel consumption prediction. By using cosine similarity to reclassify single-sample or small-sample ships into similar multi-sample categories, i.e., secondary classification, it ensures a balanced number of samples in the classification labels and improves the subsequent model training effect.Next, the model construction and training steps involve using preprocessed multidimensional original feature data and optimized ship classification results to build a ship classification prediction model based on a random forest model. The model is then trained based on the optimized ship classification results, avoiding the propagation of small sample label errors into the model and improving the model's learning accuracy for ship categories. The random forest model is highly adaptable to multidimensional ship features (such as physical characteristics, power parameters, and operational efficiency parameters), effectively handling high-dimensional data, and possesses good generalization ability, anti-overfitting ability, and robustness to noise. Training the model based on the optimized ship classification results (with small sample categories corrected) and validating its performance on a test set ensures the model's reliability in distinguishing different ship categories. This ultimately forms a reusable prediction model that breaks free from reliance on "empirical rules," thereby improving the accuracy of the classification mapping model and enabling efficient prediction of new ship types in practical applications. This represents an upgrade from "manual / rule-based classification" to "automatic model classification." Furthermore, the random forest model, through comprehensive analysis of the results of numerous decision trees, effectively filters out noise interference in the data, ensuring the stability and reliability of the final classification results. Finally, the model category prediction step uses a well-trained and tested ship classification prediction model to predict the category of the new ship to be detected, thus achieving rapid and automated classification of new ships without the need for manual judgment based on experience, improving the efficiency of classification prediction (especially suitable for batch new ship detection scenarios). Based on optimized data and a mature model, the accuracy and consistency of the prediction results are higher (compared to empirical rules or unoptimized models), reducing human error.
[0029] The ship classification and prediction method based on cosine similarity optimization disclosed in this invention can also be described as a ship type classification and mapping method based on cosine similarity calculation and random forest ensemble learning. It involves preliminary classification using empirical rules and reclassification (secondary classification) of small sample categories in the preliminary classification using cosine similarity to obtain more reliable ship classification results. Based on this, a ship classification prediction model is trained using random forest ensemble learning technology, ultimately achieving accurate mapping of ship types and efficient prediction of new ship types.
[0030] This invention achieves the following overall technical effects by introducing a small-sample optimization mechanism based on cosine similarity and combining it with a random forest model: 1) Balanced sample size: Traditional ship classification relies heavily on expert experience to divide individual ships into several categories. However, some categories have very few samples (e.g., only one ship), and this imbalanced sample size negatively impacts model training and generalization, easily leading to overfitting or prediction bias for specific categories. This invention uses cosine similarity to reclassify single-sample or small-sample ships into similar multi-sample categories, ensuring a balanced sample size in the classification labels, effectively improving model training performance, and effectively solving the classification error problem in small-sample categories. 2) Improved classification accuracy: By constructing feature vectors using multi-dimensional feature parameters (such as deadweight tonnage, gross tonnage, and ship length), and utilizing the similarity between ships, ships with similar features are grouped into the same category, making the classification results more consistent with the actual distribution of ship features. Furthermore, cosine similarity is used to quantify the similarity between ships; that is, introducing cosine similarity to reclassify categories accurately reflects the inherent correlation between different ships. This approach can accurately measure the similarity between different ships while maintaining high-dimensional features, thereby improving classification accuracy. 3) Small classification error and enhanced robustness: The random forest model consists of multiple decision trees, which can handle complex nonlinear relationships and high-dimensional data. Through learning from the training set, the model can effectively capture patterns in the data and reduce classification errors. At the same time, due to the complex and changeable marine environment, the data inevitably contains various outliers and noise. Due to its ensemble learning characteristics, the random forest model performs well in the face of noisy data and can maintain high prediction accuracy even in the presence of outliers or noise. In addition, the cosine similarity method itself has a certain resistance to noise in the data. 4) Improved accuracy: Based on the initial classification, cosine similarity is used to reclassify the ship categories to ensure that even a small number of samples can obtain reasonable classification results. Combined with the random forest model for final classification, the overall classification accuracy is effectively improved. 5) Improved accuracy of fuel consumption prediction models: Accurate ship classification is crucial for fuel consumption prediction. Through reclassified category labels, the ship classification prediction model established in this invention provides accurate foundational data for fuel consumption prediction, helping shipping companies optimize operational strategies, reduce fuel costs, and achieve more environmentally friendly operations. 6) Full-process automation: From multi-dimensional raw feature data collection, preliminary classification, cosine similarity-based category optimization to the training and testing of the random forest model, the entire process is highly automated. This not only improves work efficiency but also reduces the need for manual intervention and lowers the risk of human error.In summary, this invention, through a series of innovative technical means, including the application of a small-sample optimization mechanism based on cosine similarity and a random forest model, successfully solves the key challenges in traditional ship classification. It can be widely applied in fields such as maritime traffic management, ship monitoring, and shipping data analysis, and has high promotional value and technological prospects.
[0031] Furthermore, preprocessing includes handling missing values and removing outliers from the original multidimensional feature data to obtain processed multidimensional feature data. A standardization processor is then used to standardize the processed multidimensional feature data, resulting in standardized feature data. Missing value handling ensures the integrity and consistency of the dataset, avoiding model training bias caused by missing data, improving the stability and accuracy of subsequent classification algorithms, and ensuring that all ships can be classified based on complete data. Outlier removal eliminates potential errors or extreme values, reducing the impact of noise on classification results, enhancing the model's robustness, and enabling it to better adapt to data variations within a normal range. Standardization eliminates the influence of differences in the magnitude of different features, ensuring that each feature contributes relatively evenly to model training, avoiding the dominance of high-magnitude features, and improving the model's learning performance.
[0032] Furthermore, the performance of the trained random forest model is evaluated using a test set and evaluation metrics, including detection speed, detection accuracy, and complexity. Detection accuracy includes precision, recall, and mean precision. Detection speed is measured by the number of samples processed per second, and complexity is measured by the number of parameters and the number of floating-point operations. By using performance evaluation metrics, the strengths and weaknesses of the model are identified, and the model performance is comprehensively measured to ensure its efficiency and reliability in different application scenarios.
[0033] Furthermore, each ship data point in the test set is input into the trained random forest model, which outputs prediction results. Based on the prediction results and the manually labeled real examples for each ship data point in the test set, true positives, true negatives, false positives, and false negatives are counted. The accuracy is then calculated based on these data points. By comparing the prediction results with the real labels in the test set, true positives, true negatives, false positives, and false negatives are counted, and the accuracy is precisely calculated. This allows for a more comprehensive evaluation of the model's overall performance, ensuring its reliability in practical applications and providing solid data support for model optimization.
[0034] This invention also relates to a ship classification and prediction system based on cosine similarity optimization. This system corresponds to the aforementioned ship classification and prediction method based on cosine similarity optimization. It can be understood as a system that implements the aforementioned method, comprising a ship feature acquisition and preliminary classification module, a ship category optimization module, a model building and training module, and a model category prediction module connected sequentially. These modules work collaboratively. First, they utilize multidimensional feature data and expert experience for preliminary classification, identifying subcategories with insufficient sample sizes as objects to be optimized, providing a basis for subsequent processing. Then, the cosine similarity method is used to reclassify ship categories. By calculating the similarity between each ship and all other ships, a cosine similarity matrix is generated, thereby reassigning ships in the subcategories to more suitable categories, solving the problem of imbalanced samples. Subsequently, the optimized classification results are used as part of the dataset, combined with the original feature data, and trained and tested using a random forest model, ensuring good generalization ability and noise resistance of the model on high-dimensional data. This not only improves the accuracy of ship classification but also automates the entire process from data acquisition to classification prediction, possessing good engineering practicality and scalability. It has demonstrated broad application prospects and technological potential in fields such as ship management, fuel consumption optimization, and maritime big data analysis, providing strong technical support for related industries. Attached Figure Description
[0035] Figure 1 This is a flowchart of the ship classification and prediction method based on cosine similarity optimization of the present invention. Detailed Implementation
[0036] The present invention will now be described with reference to the accompanying drawings.
[0037] This invention relates to a ship classification and prediction method based on cosine similarity optimization. By calculating the cosine similarity between ships, ships with fewer individuals are reclassified into ship categories with higher similarity, thereby solving the sample imbalance problem in ship management and fuel consumption prediction and improving the accuracy and generalization ability of the classification model. Subsequently, based on the optimized ship categories, a random forest model is used for training to construct a ship classification mapping model (i.e., a ship classification prediction model) to achieve accurate ship classification and management. The flowchart of this method is as follows. Figure 1 As shown, the steps are as follows:
[0038] I. Ship Feature Collection and Preliminary Classification Steps: Collect multidimensional raw feature data of ships, covering their physical characteristics and performance parameters reflecting their power level and operating efficiency. Preprocess the collected multidimensional raw feature data. Based on the preprocessed multidimensional raw feature data and combined with empirical rules, perform preliminary classification of ships to obtain preliminary classification results containing multiple ship categories. Then, count the number of samples for each ship category in the preliminary classification results. Ship categories with a sample number less than a preset threshold are recorded as categories to be optimized, and other ship categories other than those to be optimized are recorded as reference categories.
[0039] Specifically, the first step is to collect multidimensional raw characteristic data of the ship, which covers the ship's physical characteristics and performance parameters (reflecting the ship's power level and operating efficiency). Among these, the physical characteristics in the multidimensional raw characteristic data include deadweight tonnage, gross tonnage, net tonnage, length, beam, design draft, displacement, molded depth (referring to the vertical distance from the upper edge of the deck beam to the upper surface of the keel plate in the theoretical design lines of the ship (excluding the thickness of the hull steel plates)), main engine cylinder diameter, and number of main engine cylinders, etc. The performance parameters reflecting the ship's power level in the multidimensional raw characteristic data include main engine stroke type, maximum power, braking power, operating power, total main engine horsepower, and total main engine power (total kilowatts of main engine), etc. The performance parameters reflecting the ship's operating efficiency in the multidimensional raw characteristic data include design speed, maximum speed, and operating speed, etc.
[0040] The collected multidimensional raw feature data is then processed by handling missing values and removing outliers to obtain processed multidimensional feature data. The processed multidimensional feature data is then standardized using the StandardScaler processor to eliminate the influence of differences in feature magnitude. Based on the standardized feature data and combined with empirical rules (expert experience), ships are initially classified, resulting in preliminary classification results containing multiple ship categories. Each ship category is then labeled, and the label encoder (LabelEncoder) encodes the classification labels. The classification labels contain ship annotation information. Finally, the number of samples for each ship category in the preliminary classification results is counted. Ship categories with fewer than a preset threshold are designated as categories to be optimized, and other ship categories are designated as reference categories.
[0041] II. Ship Category Optimization Steps: The feature parameters in the preprocessed multidimensional original feature data are converted into feature vectors. Based on these feature vectors, the cosine similarity between each ship in the category to be optimized and all ships in the reference category is calculated using the cosine similarity method, thus generating a cosine similarity matrix. The target ship with the highest similarity to each ship in the category to be optimized is then identified in the cosine similarity matrix. The category label of each ship in the category to be optimized is updated to the ship category to which the corresponding target ship belongs. After all ships in the category to be optimized have been reclassified, the category to be optimized is deleted, thus obtaining the optimized ship classification result.
[0042] In the initial classification, ships are divided into several groups, but some ship groups contain only a small number of samples, or even just one sample. This imbalance negatively impacts the training performance of the model, failing to provide sufficient training data for the classification model. To improve the imbalance problem, a cosine similarity method is introduced to reclassify the groups, merging these groups with insufficient samples into the most similar multi-sample groups. Specifically, firstly, the feature parameters in the preprocessed multidimensional original feature data are converted into feature vectors (feature vectors contain multidimensional information describing ship size, load capacity, power, etc.), that is, the features of each ship sample in each ship group are represented as a vector. Then, based on the feature vectors, the cosine similarity method is used to calculate the cosine similarity between each ship in the group to be optimized and all ships in the reference group, thereby generating a cosine similarity matrix. Cosine similarity is an index that measures the similarity between two vectors, measuring their similarity by calculating the cosine of the angle between the two vectors. Its value is between -1 and 1; the closer the value is to 1, the more similar the two samples are. The cosine similarity calculation formula is shown below:
[0043]
[0044] In the above formula, A and B are the feature vectors of the two ships, respectively. i and B i This represents the value of the i-th feature in the feature vector.
[0045] The cosine similarity between each ship in the category to be optimized and all ships in the reference category is calculated using the above formula, thereby generating a cosine similarity matrix to measure the similarity between each pair of ship samples. The cosine similarity matrix is a symmetric matrix, where each element sim(i,j) represents the similarity between ship sample i and ship sample j.
[0046] Then, the target ship with the highest similarity to each ship in the category to be optimized is found in the cosine similarity matrix. That is, for each sample that needs to be reassigned, the ship type to which the other sample with the highest cosine similarity belongs is found. The category label of each ship in the category to be optimized is updated to the ship type to which the corresponding target ship belongs. After all ships in the category to be optimized have been reclassified, the category to be optimized is deleted, and the optimized ship classification result is obtained. For example, taking 664 ships as the experimental dataset, including 188 container ships A, 120 liquid bulk carriers B, 300 dry bulk carriers C, and 56 special transport ships D, then special transport ships D is recorded as the category to be optimized. Taking a ship E in special transport ships D, its similarity with A, B, and C is calculated: sim(E,A)=0.94 (container ship), sim(E,B)=0.76 (liquid bulk carrier), sim(E,C)=0.85, then the assignment result is: ship E→container ship. This process continues until all vessels in Special Transport Vessel D have been reclassified, at which point the category to be optimized is removed. This reclassification process significantly increases the number of samples in previously insufficient categories, ensuring that each vessel type contains a sufficient number of samples. This reclassification allows the classification model to fully learn the characteristics of each vessel type during subsequent training, avoiding model bias and overfitting problems caused by insufficient sample size.
[0047] III. Model Construction and Training Steps: The preprocessed multidimensional original feature data and the optimized ship classification results are used as the dataset. The dataset is divided into training set and test set according to a preset ratio. The training set is input into the random forest model for training. The trained random forest model is obtained and tested and analyzed through the test set to verify the model performance. The final trained and tested ship classification prediction model is obtained.
[0048] After reclassification, this invention utilizes a random forest model to construct a ship classification prediction model, achieving scientific classification of ship types. By introducing machine learning methods, useful information can be automatically extracted from multi-dimensional ship features, effectively improving the accuracy and generalization ability of ship classification. Specifically, the original feature data and optimized ship classification results are first used as a dataset, which is then divided into a training set and a test set according to a preset ratio. This preset ratio can be 70%-80% for the training set and 20%-30% for the test set, for example, a 70% training set and 30% test set. The training set is used for model training, and the test set is used to verify model performance, allowing the model to learn on sufficient data and be validated on unknown datasets. The training set is then input into the random forest model for training, and performance is optimized by adjusting model parameters. The trained random forest model is then tested and analyzed using the test set to obtain the final trained and tested ship classification prediction model. Preferably, the performance of the trained random forest model is evaluated using a test set and evaluation metrics, including detection speed, detection accuracy, and complexity. Detection accuracy includes precision, recall, and average precision. Detection speed is measured by the number of samples processed per second, and complexity is measured by the number of parameters and floating-point operations. Specifically, the accuracy calculation steps include: inputting each ship data point in the test set into the trained random forest model and outputting the prediction result; and based on the prediction result and the manually labeled true examples and false positives for each ship data point in the test set, identifying true positives, true negatives, false positives, and false negatives. Accuracy is then calculated based on these data points and used as the primary evaluation metric. The accuracy formula is shown below:
[0049]
[0050] In the above formula, TP, TN, FP, and TN represent true positives, true negatives, false positives, and false negatives, respectively.
[0051] The Random Forest model is an ensemble learning model based on decision trees, achieving classification by training multiple independent decision trees. Each decision tree is trained using a random subset of samples and random selection of features to reduce the risk of overfitting. During training, each decision tree learns the relationship between sample features and class labels. After all decision trees are trained, the prediction result is determined by ensemble voting. By ensemble multiple decision trees, the stability and accuracy of the model can be significantly improved. Furthermore, the Random Forest model exhibits good generalization ability when handling high-dimensional data and is robust to noise. Preferably, the model consists of 100 independent decision trees, with a maximum depth of 20 for each tree.
[0052] IV. Model Category Prediction Steps: The ship classification prediction model is used to predict the category of the new ship to be detected, thus determining the ship category to which the new ship belongs. That is, the trained and tested ship classification prediction model can be used to predict the category of new ships. By inputting the multidimensional feature data of the new ship into the ship classification prediction model, the model uses its previously learned knowledge to classify it and predict the ship category to which the ship belongs. The prediction results are compared with the true labels in Table 1.
[0053] Table 1
[0054] container ship 0.9123 Liquid bulk carriers 0.8056 dry bulk carriers 0.8222 Special transport ships 0.9412
[0055] It can be seen that the method of the present invention can significantly improve the accuracy and generalization ability of ship classification, and provide strong technical support for ship management, fuel consumption optimization and maritime big data analysis.
[0056] This invention also relates to a ship classification and prediction system based on cosine similarity optimization. This system corresponds to the aforementioned ship classification and prediction method based on cosine similarity optimization, and can be understood as a system that implements the above method. The system includes, in sequence, a ship feature acquisition and preliminary classification module, a ship category optimization module, a model building and training module, and a model category prediction module. Specifically,
[0057] The ship feature acquisition and preliminary classification module collects multidimensional raw feature data of ships, covering their physical characteristics and performance parameters reflecting their power level and operating efficiency. It preprocesses the collected multidimensional raw feature data and, based on the preprocessed data and empirical rules, performs a preliminary classification of ships, resulting in a preliminary classification result containing multiple ship categories. Then, it counts the number of samples for each ship category in the preliminary classification result, designating ship categories with fewer than a preset threshold as categories to be optimized, and designating other ship categories as reference categories.
[0058] The ship category optimization module converts each feature parameter in the preprocessed multidimensional original feature data into a feature vector. Based on the feature vector, it calculates the cosine similarity between each ship in the category to be optimized and all ships in the reference category using the cosine similarity method, thereby generating a cosine similarity matrix. Then, it finds the target ship with the highest similarity to each ship in the category to be optimized in the cosine similarity matrix, updates the category label of each ship in the category to be optimized to the ship category to which the corresponding target ship belongs, and deletes the category after all ships in the category to be optimized have been reclassified, thus obtaining the optimized ship classification result.
[0059] The model building and training module takes the preprocessed multidimensional original feature data and the optimized ship classification results as the dataset, divides the dataset into training set and test set according to a preset ratio, inputs the training set into the random forest model for training, obtains the trained random forest model, and tests and analyzes it through the test set to verify the model performance, and obtains the final trained and tested ship classification prediction model.
[0060] The model category prediction module uses the ship classification prediction model to predict the category of the new ship to be detected, thus predicting the ship category to which the new ship belongs.
[0061] Preferably, in the ship feature acquisition and preliminary classification module, the preprocessing includes processing missing values and removing outliers from the multidimensional original feature data to obtain processed multidimensional feature data; and using a standardization processor to standardize the processed multidimensional feature data to obtain standardized feature data.
[0062] Preferably, in the model building and training module, the model performance is verified by testing and analysis using a test set. Specifically, this includes: using the test set to evaluate the performance of the trained random forest model using evaluation metrics, including detection speed, detection accuracy, and complexity. The detection accuracy includes precision, recall, and average precision. The detection speed is measured by the number of samples processed per second, and the complexity is measured by the number of parameters and the number of floating-point operations.
[0063] Preferably, in the model building and training module, when testing and analyzing the model performance using a test set to verify the model performance, the accuracy calculation steps specifically include: inputting each ship data in the test set into the trained random forest model and outputting the prediction result; and based on the prediction result and the manually labeled real labels of each ship data in the test set, counting true positives, true negatives, false positives, and false negatives, and calculating the accuracy based on the true positives, true negatives, false positives, and false negatives.
[0064] This invention provides an objective and scientific method and system for ship classification and prediction based on cosine similarity optimization. By employing the cosine similarity method to reclassify ships, ships in the unoptimized category are reassigned to more suitable categories, thus solving the problem of imbalanced samples. Furthermore, the use of a random forest model for training and testing ensures the model's good generalization ability and noise resistance on high-dimensional data. This not only improves the accuracy of ship classification but also automates the entire process from data collection to classification prediction, demonstrating good engineering practicality and scalability. It shows broad application prospects and technological potential in areas such as ship management, fuel consumption optimization, and maritime big data analysis, providing strong technical support for related industries.
[0065] It should be noted that the specific embodiments described above enable those skilled in the art to more fully understand the present invention, but do not limit the present invention in any way. Therefore, although the present invention has been described in detail with reference to the accompanying drawings and embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the present invention. In short, all technical solutions and improvements that do not depart from the spirit and scope of the present invention should be covered within the protection scope of the present invention patent.
Claims
1. A ship classification and prediction method based on cosine similarity optimization, characterized in that, Includes the following steps: Ship Feature Acquisition and Preliminary Classification Steps: Collect multidimensional raw feature data of ships, encompassing their physical characteristics and performance parameters reflecting their power level and operational efficiency. Preprocess the collected multidimensional raw feature data. Based on the preprocessed multidimensional raw feature data and combined with empirical rules, perform preliminary classification of ships to obtain preliminary classification results containing multiple ship categories. Then, count the number of samples for each ship category in the preliminary classification results. Ship categories with a sample number less than a preset threshold are recorded as categories to be optimized, and other ship categories are recorded as reference categories. Ship category optimization steps: Convert each feature parameter in the preprocessed multidimensional original feature data into a feature vector, calculate the cosine similarity between each ship in the category to be optimized and all ships in the reference category based on the feature vector and the cosine similarity method, and then generate a cosine similarity matrix. Then, in the cosine similarity matrix, the target ship with the highest similarity to each ship in the category to be optimized is found, and the category label of each ship in the category to be optimized is updated to the ship category to which the corresponding target ship belongs; Once all ships in the category to be optimized have been reclassified, the category to be optimized is deleted, and the optimized ship classification result is obtained. Model building and training steps: The preprocessed multidimensional original feature data and the optimized ship classification results are used as the dataset. The dataset is divided into training set and test set according to the preset ratio. The training set is input into the random forest model for training. The trained random forest model is obtained and tested and analyzed through the test set to verify the model performance. The final trained and tested ship classification prediction model is obtained. Model category prediction steps: Use the ship classification prediction model to predict the category of the new ship to be detected, and predict the ship category to which the new ship belongs.
2. The ship classification and prediction method based on cosine similarity optimization according to claim 1, characterized in that, In the ship feature acquisition and preliminary classification steps, the preprocessing includes processing missing values and removing outliers from the original multidimensional feature data to obtain processed multidimensional feature data; and using a standardization processor to standardize the processed multidimensional feature data to obtain standardized feature data.
3. The ship classification and prediction method based on cosine similarity optimization according to claim 1, characterized in that, In the model construction and training steps, the preset ratio is 70%-80% for the training set and 20%-30% for the test set; the random forest model is an ensemble learning model based on decision trees, consisting of 100 independent decision trees. During the training of each decision tree, a subset of samples is generated by random sampling with replacement from the training set, and a subset of features is randomly selected during each node split; at the same time, the maximum depth of each decision tree is set to 20; after all decision trees are trained, the final prediction result is determined by ensemble voting.
4. The ship classification and prediction method based on cosine similarity optimization according to claim 3, characterized in that, In the model construction and training steps, the model performance is verified through testing and analysis using a test set, specifically including: The performance of the trained random forest model is evaluated using a test set and evaluation metrics, including detection speed, detection accuracy, and complexity. Detection accuracy includes precision, recall, and average precision. Detection speed is measured by the number of samples processed per second, and complexity is measured by the number of parameters and the number of floating-point operations.
5. The ship classification and prediction method based on cosine similarity optimization according to claim 4, characterized in that, The accuracy calculation steps specifically include: inputting each ship data in the test set into the trained random forest model and outputting the prediction result; and based on the prediction result and the real labels manually annotated for each ship data in the test set, counting the true positives, true negatives, false positives and false negatives, and calculating the accuracy based on the true positives, true negatives, false positives and false negatives.
6. The ship classification and prediction method based on cosine similarity optimization according to claim 1 or 2, characterized in that, In the ship feature acquisition and preliminary classification steps, the physical characteristics in the multidimensional raw feature data include deadweight tonnage, gross tonnage, net tonnage, length, beam, design draft, displacement, depth, main engine cylinder diameter, and number of main engine cylinders. The performance parameters reflecting the ship's power level in the multidimensional raw feature data include main engine stroke type, maximum power, braking power, operating power, total main engine horsepower, and total main engine power. The performance parameters reflecting the ship's operating efficiency in the multidimensional raw feature data include design speed, maximum speed, and operating speed.
7. A ship classification and prediction system based on cosine similarity optimization, characterized in that, It includes, in sequence, a ship feature acquisition and preliminary classification module, a ship category optimization module, a model building and training module, and a model category prediction module. The ship feature acquisition and preliminary classification module collects multidimensional raw feature data of ships, covering their physical characteristics and performance parameters reflecting their power level and operating efficiency. It preprocesses the collected multidimensional raw feature data and, based on the preprocessed data and empirical rules, performs a preliminary classification of ships, resulting in a preliminary classification result containing multiple ship categories. Then, it counts the number of samples for each ship category in the preliminary classification result, designating ship categories with fewer than a preset threshold as categories to be optimized, and designating other ship categories as reference categories. The ship category optimization module converts each feature parameter in the preprocessed multidimensional original feature data into a feature vector, calculates the cosine similarity between each ship in the category to be optimized and all ships in the reference category based on the feature vector and the cosine similarity method, and then generates a cosine similarity matrix. Then, in the cosine similarity matrix, the target ship with the highest similarity to each ship in the category to be optimized is found, and the category label of each ship in the category to be optimized is updated to the ship category to which the corresponding target ship belongs; Once all ships in the category to be optimized have been reclassified, the category to be optimized is deleted, and the optimized ship classification result is obtained. The model building and training module takes the preprocessed multidimensional original feature data and the optimized ship classification results as the dataset, divides the dataset into training set and test set according to a preset ratio, inputs the training set into the random forest model for training, obtains the trained random forest model, and tests and analyzes it through the test set to verify the model performance, and obtains the final trained and tested ship classification prediction model. The model category prediction module uses the ship classification prediction model to predict the category of the new ship to be detected, thus predicting the ship category to which the new ship belongs.
8. The ship classification and prediction system based on cosine similarity optimization according to claim 7, characterized in that, In the ship feature acquisition and preliminary classification module, the preprocessing includes processing missing values and removing outliers from the original multidimensional feature data to obtain processed multidimensional feature data; and using a standardization processor to standardize the processed multidimensional feature data to obtain standardized feature data.
9. The ship classification and prediction system based on cosine similarity optimization according to claim 7, characterized in that, In the model building and training module, the model performance is verified through testing and analysis using a test set, specifically including: The performance of the trained random forest model is evaluated using a test set and evaluation metrics, including detection speed, detection accuracy, and complexity. Detection accuracy includes precision, recall, and average precision. Detection speed is measured by the number of samples processed per second, and complexity is measured by the number of parameters and the number of floating-point operations.
10. The ship classification and prediction system based on cosine similarity optimization according to claim 9, characterized in that, In the model building and training module, when testing and analyzing the model performance using a test set to verify its performance, the accuracy calculation steps specifically include: inputting each ship data in the test set into the trained random forest model and outputting the prediction result; and based on the prediction result and the manually labeled real labels of each ship data in the test set, counting the true positives, true negatives, false positives, and false negatives, and calculating the accuracy based on the true positives, true negatives, false positives, and false negatives.