A pig average daily gain prediction method and system based on machine learning
Patent Information
- Application Number
- CN202610180129.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-09
- Publication Date
- 2026-10-27
AI Technical Summary
[0005]有鉴于此,本申请实施例提供一种基于机器学习的猪平均日增重预测方法及系统,至少解决预测猪只的平均日增重预测精度低和成本高的问题
[0008]本申请实施例提供的技术方案带来的有益效果至少包括:
Smart Images

Figure CN122986715A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of animal husbandry, and relates to, but is not limited to, a method and system for predicting the average daily weight gain of pigs based on machine learning. Background Technology
[0002] Average Daily Gain (ADG) is a core trait that directly reflects the growth efficiency and economic benefits of pig farming. Accurate prediction of ADG is of great significance for optimizing feeding management, precise feed input, and slaughter decisions. However, in actual commercial pig production systems, achieving low-cost, high-precision, and easily scalable ADG prediction still faces significant challenges.
[0003] Among related technologies, methods based on traditional breeding assessment and genomic selection, which construct models using genotype data and family records, can estimate breeding values relatively accurately. Growth prediction methods based on conventional statistical models use tools such as linear regression to fit limited indicators such as birth weight, weaning weight, and age to infer the growth performance of pigs.
[0004] However, genomic selection methods rely on expensive genotype data and complete pedigree records. Acquiring genotype data is costly and technically challenging, making it difficult to deploy frequently and in real-time on ordinary commercial pig farms. Conventional statistical models have limited ability to characterize the complex nonlinear relationships in pig growth, resulting in insufficient prediction accuracy and generalization ability. Furthermore, they are often built based on small sample data, making them difficult to adapt to diverse pig farming scenarios. Summary of the Invention
[0005] In view of this, embodiments of this application provide a method and system for predicting the average daily weight gain of pigs based on machine learning, which at least solves the problems of low accuracy and high cost in predicting the average daily weight gain of pigs.
[0006] The technical solution of this application embodiment is implemented as follows: In a first aspect, embodiments of this application provide a machine learning-based method for predicting the average daily weight gain of pigs, including: Obtain daily production data of the pigs to be predicted; From the daily production data, important feature data that matches a predefined important feature subset is extracted; the predefined important feature subset is obtained by calculating the feature importance of candidate historical feature sets and ranking them based on a pre-trained LightGBM regression model, and then filtering them using a sequential forward feature selection method based on the ranking results. Based on the aforementioned key feature data, the average daily weight gain prediction value of the pigs to be predicted is obtained through a pre-trained CatBoost prediction model. The pre-trained CatBoost prediction model is trained based on an asymmetric loss function. In the asymmetric loss function, the first penalty weight corresponding to the overestimation error is greater than the second penalty weight corresponding to the underestimation error. Based on the predicted average daily weight gain, determine and output the predicted average daily weight gain to be output.
[0007] Secondly, embodiments of this application provide a machine learning-based system for predicting average daily weight gain in pigs, comprising: a data acquisition module, a feature processing module, a prediction module, and an output module; The data acquisition module is used to acquire the daily production data of the pigs to be predicted; The feature processing module is used to extract important feature data that matches a predefined important feature subset from the daily production data; the predefined important feature subset is obtained by calculating the feature importance of candidate historical feature sets and ranking them based on a pre-trained LightGBM regression model, and then filtering them using a sequential forward feature selection method based on the ranking results. The prediction module is used to obtain the average daily weight gain prediction value of the pig to be predicted based on the important feature data and through a pre-trained CatBoost prediction model; the pre-trained CatBoost prediction model is trained based on an asymmetric loss function; in the asymmetric loss function, the first penalty weight corresponding to the overestimation error is greater than the second penalty weight corresponding to the underestimation error; The output module is used to determine and output the average daily weight gain prediction value based on the average daily weight gain prediction value.
[0008] The beneficial effects of the technical solutions provided in this application include at least the following: The machine learning-based method for predicting average daily weight gain in pigs provided in this application reduces the cost and technical difficulty of data acquisition by obtaining daily production data, thus improving the feasibility of large-scale application in ordinary commercial pig farms. The method pre-calculates and ranks the feature importance of candidate historical feature sets using a LightGBM regression model, and then selects an important feature subset based on the ranking results using a sequential forward feature selection method. This avoids interference from irrelevant or noisy features, improving the signal quality of the model's input. By selecting the optimal feature combination, the model's ability to capture the inherent patterns in the data is enhanced, laying a solid foundation for subsequent high-precision prediction and helping to improve generalization ability under different pig farm environments. When predicting the average daily weight gain of pigs to be predicted, only important feature data matching the important feature subset needs to be extracted from daily production data to obtain the important feature data affecting the predicted average daily weight gain of pigs to be predicted. The pre-trained CatBoost prediction model obtains the predicted average daily weight gain of pigs to be predicted by analyzing the nonlinear relationship of the important feature data. During training, the pre-trained CatBoost prediction model is guided to learn a conservative prediction tendency. This reduces the economic decision-making risk of premature slaughtering of pigs before reaching target weight due to overestimation of predicted values, making the prediction results not only more accurate but also safer and more aligned with the risk control needs of production management. Therefore, this application reduces the cost of obtaining daily production data and improves the prediction accuracy of the average daily weight gain of the pigs to be predicted. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort, wherein: Figure 1 A flowchart illustrating a machine learning-based method for predicting average daily weight gain in pigs, provided in an embodiment of this application; Figure 2 This is a schematic diagram of the structure of a machine learning-based pig average daily weight gain prediction system provided in an embodiment of this application. Detailed Implementation
[0010] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. The following embodiments are used to illustrate this application, but are not intended to limit the scope of this application. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0011] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0012] It should be noted that the terms "first, second, and third" used in the embodiments of this application are merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, and third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0013] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which the embodiments of this application pertain. It should also be understood that terms such as those defined in general dictionaries should be understood to have a meaning consistent with their meaning in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0014] This application provides a machine learning-based method for predicting the average daily weight gain of pigs. Figure 1 A flowchart illustrating a machine learning-based method for predicting average daily weight gain in pigs, as provided in this application embodiment, is shown below. Figure 1 As shown, the method includes at least the following steps: Step S110: Obtain the daily production data of the pigs to be predicted; Daily production data refers to data recorded automatically or semi-automatically during the daily operation of a pig farm. Daily production data reflects the growth process of pigs and the management environment, and is a direct and practical source of data for predicting the average daily gain (ADG) of pigs.
[0015] Routine production data is a byproduct of the pig farm's existing management system. No additional testing equipment or specialized experiments are required, significantly reducing the cost of data acquisition. Pig farm staff can directly record or export daily data, obtaining it without requiring complex technical labor.
[0016] By acquiring daily production data, the cost and technical difficulty of data acquisition are reduced, and the feasibility of large-scale application in ordinary commercial pig farms is improved.
[0017] Therefore, the acquisition cycle of daily production data is short and the acquisition cost is low, which can meet the daily high-frequency prediction needs of ADG.
[0018] Step S120: Extract important feature data that matches a predefined important feature subset from the daily production data; the predefined important feature subset is obtained by calculating the feature importance of candidate historical feature sets and ranking them based on a pre-trained LightGBM regression model, and by filtering them using a sequential forward feature selection method based on the ranking results. The subset of key features enables farmers to understand the features that play an important role in the forecasting process, improving the accuracy of forecasts and facilitating their application and decision-making in actual production management.
[0019] Routine production data may contain redundant features, affecting the prediction accuracy of pre-trained Categorical Boosting (CatBoost) prediction models. Therefore, it is necessary to use a pre-trained Lightweight Gradient Boosting Machine (LightGBM) regression model to filter features in routine production data using Sequential Forward Selection (SFS) to reduce interference from irrelevant or noisy features, allowing the CatBoost prediction model to focus more on important features. This accelerates the training speed of the CatBoost prediction model, effectively prevents overfitting, and enhances its generalization ability.
[0020] Step S130: Based on the important feature data, the average daily weight gain prediction value of the pig to be predicted is obtained through a pre-trained CatBoost prediction model; the pre-trained CatBoost prediction model is trained based on an asymmetric loss function; in the asymmetric loss function, the first penalty weight corresponding to the overestimation error is greater than the second penalty weight corresponding to the underestimation error; In pig production, the economic risks of overestimating the predicted average daily weight gain of pigs far outweigh those of underestimating it. Scheduling pigs for slaughter based on overestimated average daily weight gain can lead to pigs failing to reach their target weight, resulting in direct economic losses.
[0021] Therefore, when predicting the average daily weight gain of the pigs to be predicted, a higher penalty weight is applied to the overestimation error through an asymmetric loss function. This makes the model tend to predict the average daily weight gain slightly lower, while also avoiding a conservative tendency to overestimate. This reduces decision-making errors and economic losses caused by overly optimistic predictions of the average daily weight gain.
[0022] The CatBoost prediction model outputs a conservative average daily weight gain forecast, resulting in more robust and reliable predictions. This allows pig farm operators to adopt the average daily weight gain forecast from the CatBoost model as a basis for pig feeding management and slaughter planning, promoting the implementation and application of the technical solution in actual pig production.
[0023] Therefore, the predicted average daily weight gain of the pigs obtained through the technical solution of this application has high accuracy and high reliability, and can directly support economic decision-making in the pig production process.
[0024] Step S140: Based on the predicted average daily weight gain, determine and output the predicted average daily weight gain value to be output.
[0025] After the CatBoost prediction model obtains the average daily weight gain forecast, it can directly output the average daily weight gain forecast. Alternatively, it can adjust the average daily weight gain forecast accordingly and then output the adjusted average daily weight gain forecast. For example, the average daily weight gain forecast can be lowered, and then the lowered average daily weight gain forecast can be output.
[0026] The machine learning-based method for predicting average daily weight gain in pigs provided in this application reduces the cost and technical difficulty of data acquisition by obtaining daily production data, thus improving the feasibility of large-scale application in ordinary commercial pig farms. The method pre-calculates and ranks the feature importance of candidate historical feature sets using a LightGBM regression model, and then selects an important feature subset based on the ranking results using a sequential forward feature selection method. This avoids interference from irrelevant or noisy features, improving the signal quality of the model's input. By selecting the optimal feature combination, the model's ability to capture the inherent patterns in the data is enhanced, laying a solid foundation for subsequent high-precision prediction and helping to improve generalization ability under different pig farm environments. When predicting the average daily weight gain of pigs to be predicted, only important feature data matching the important feature subset needs to be extracted from daily production data to obtain the important feature data affecting the predicted average daily weight gain of pigs to be predicted. The pre-trained CatBoost prediction model obtains the predicted average daily weight gain of pigs to be predicted by analyzing the nonlinear relationship of the important feature data. During training, the pre-trained CatBoost prediction model is guided to learn a conservative prediction tendency. This reduces the economic decision-making risk of premature slaughtering of pigs before reaching target weight due to overestimation of predicted values, making the prediction results not only more accurate but also safer and more aligned with the risk control needs of production management. Therefore, this application reduces the cost of obtaining daily production data and improves the prediction accuracy of the average daily weight gain of the pigs to be predicted.
[0027] Optionally, the daily production data includes the age at which the pig reaches the preset weight, the season of birth, the number of piglets born, the birth weight, the parity of the sow, the sex, the number of left teats, and the number of right teats; obtaining the daily production data of the pig to be predicted includes: during the growth process of the pig to be predicted, recording the age at which the pig reaches the preset weight, the season of birth, the number of piglets born, the birth weight, the parity of the sow, the sex, the number of left teats, and the number of right teats.
[0028] The birth season includes spring, summer, autumn, and winter. The target weight at the age of reaching the target weight can be 30 kg. Sow parity can be classified as category 1, 2, 3, 4, 5, 6, and 7. Sex includes male and female, with males designated as 1 and females as 0.
[0029] Optionally, the method further includes: acquiring historical production data of multiple historical pigs and corresponding actual average daily weight gain; constructing an initial LightGBM regression model; using the multiple historical production data as input data and the corresponding actual average daily weight gain as labels to train the initial LightGBM regression model, thereby obtaining the pre-trained LightGBM regression model.
[0030] In some embodiments, initial historical production data of multiple historical pigs are obtained, and the initial historical production data are preprocessed to obtain preprocessed historical production data (hereinafter referred to as historical production data).
[0031] The initial historical production data includes multiple initial historical features and a label, which is the actual average daily weight gain of the pigs.
[0032] The preprocessing process includes: performing a completeness check on the initial historical production data, removing data samples with missing values in the initial historical features or labels; performing a reasonableness check on the data after missing value processing, correcting or removing obvious errors and outliers based on the physiological range or statistical distribution of pigs; and finally obtaining the complete dataset, which is the historical production data.
[0033] Historical production data is divided into two non-overlapping parts using random sampling: a training set and a test set. The training set, comprising 70% of the total historical production data, is used for feature selection, model training, and hyperparameter optimization. The test set, comprising 30% of the total historical production data, is reserved for final performance evaluation and is not used in the training and hyperparameter tuning process.
[0034] Optionally, the method further includes: calculating the number of splits of each historical feature in the candidate historical feature set as a split node in the decision tree of the pre-trained LightGBM regression model based on the pre-trained LightGBM regression model; determining the feature importance of the candidate historical features in the candidate historical feature set in descending order of the number of splits; sorting the candidate historical features based on the feature importance to generate a feature importance ranking; and determining the predefined important feature subset based on the feature importance ranking using a sequential forward feature selection method.
[0035] The LightGBM regression model is used to calculate the feature importance of candidate feature sets in daily production data and obtain the feature importance ranking. Based on the feature importance ranking, the candidate feature sets are filtered by the sequential forward feature selection method to obtain important feature subsets.
[0036] Optionally, determining the predefined important feature subset based on the feature importance ranking using a sequential forward feature selection method includes: initializing the original feature subset as an empty set; based on the feature importance ranking, using the sequential forward feature selection method, sequentially adding each of the candidate historical features in the candidate historical feature set to the original feature subset in descending order of feature importance, generating multiple candidate historical feature subsets containing different numbers of the candidate historical features; based on each candidate historical feature subset, using the historical production data and the corresponding actual average daily weight gain, training the initial LightGBM regression model K times using K-fold cross-validation to obtain the average determination coefficient of each candidate historical feature subset; comparing the average determination coefficients corresponding to each candidate historical feature subset; and determining the candidate historical feature subset with the largest average determination coefficient as the predefined important feature subset.
[0037] A LightGBM regression model was constructed on the training set, using historical features as input to fit the target variable, average daily weight gain. There were eight historical features: age at 30kg weight, season of birth, birth weight, sow parity, sex, number of piglets born, number of left teats, and number of right teats. The output was the actual ADG value for each individual sample.
[0038] The LightGBM regression model used in this embodiment is version 4.6.0. The LightGBM regression model parameters are set as follows: boosting_type = gbdt, learning_rate = 0.1, n_estimators = 100, num_leaves = 31, min_child_samples = 20, max_depth = -1, and random_state = 42 to ensure reproducibility of the training process. This embodiment is a regression task, and the objective function of LightGBM is a regression objective, which is determined by the default regressor configuration when not explicitly specified.
[0039] In some embodiments, feature importance can also be calculated using an information gain-based approach, that is, by cumulatively calculating the decrease in the objective function caused by splitting using the feature, and generating a feature importance ranking list accordingly.
[0040] In some embodiments, if required for dimensionally sensitive models, candidate historical features may be standardized or normalized.
[0041] In sequential forward feature selection, for example, for 8 candidate historical features, candidate subsets are generated sequentially, with the number of candidate historical features increasing from 1 to 8. For example, when there are 8 features, there are 8 candidate historical feature subsets. The first candidate historical feature subset includes 1 feature, the second candidate historical feature subset includes 2 features, the third candidate historical feature subset includes 3 features, and so on.
[0042] Whether it contains one or eight candidate feature subsets, the performance of each candidate feature subset is evaluated using five-fold cross-validation.
[0043] For each candidate feature subset, K-fold cross-validation is performed on the training set to evaluate its performance. The K-fold cross-validation includes: randomly dividing the training set into K non-overlapping validation subsets; sequentially using each validation subset as the validation set, and combining the remaining K-1 subsets as the training subset; using the training subset, training a LightGBM regression model based on the features contained in the current candidate feature subset; using the trained model to predict on the validation set and calculating the determination coefficient on the validation set; calculating the average determination coefficient of the candidate feature subset based on the determination coefficients obtained from K validations; and selecting the subset with the largest average determination coefficient from all evaluated candidate feature subsets as the predefined important feature subset.
[0044] Based on feature importance ranking, the eight candidate historical features are arranged in descending order of importance as a sequence [f1, f2, ..., f8], and an empty original feature subset is initialized. Historical features are added to the original feature subset sequentially according to the ranking order: in the i-th iteration, the feature ranked i-th is added to the set already containing the first i-1 features, forming a candidate historical feature subset containing the first i features.
[0045] For each feature subset generated in each round, five-fold cross-validation is performed on the training set to evaluate its performance. The specific process includes: first, randomly dividing the training set samples into 5 non-overlapping subsets, setting random shuffling and a fixed random seed to ensure reproducibility; where random_state is 42, each subset is used as the validation set, and the remaining 4 subsets are used as the training set to train the LightGBM regression model and make predictions, obtaining the decision coefficients for each fold; finally, the five-fold decision coefficients (R²) are recorded. 2 The value of ).
[0046] To comprehensively evaluate the performance of feature subsets, the five-fold R-squared value is calculated. 2 The average value is used as the mean coefficient of determination for this subset. Simultaneously, to quantify the uncertainty of the assessment, the mean coefficient of determination (Mean R) is calculated. 295% confidence interval for ) : First calculate the 50% R 2 The standard error of the value is used to obtain the upper and lower bounds of the confidence interval.
[0047] A stopping criterion is set to determine the significance of the contribution of added features. A performance increment is defined, and iteration stops when the performance increment is less than a preset threshold twice consecutively. The preset threshold ε is set to 0.001. After stopping, Mean R is selected from all evaluated feature subsets. 2 The largest subset is taken as the final feature set.
[0048] This step outputs the complete results of each iteration, including the feature subset composition and the five-fold R-squared value. 2 Value, Mean R 2 The results, along with their 95% confidence intervals, are saved as feature selection result files to determine the final feature set and support subsequent model training and interpretability analysis.
[0049] This application employs feature screening to select six key features from eight candidate historical features. The eight candidate historical features are: age at reaching the preset weight, season of birth, number of piglets born, birth weight, parity of the sow, sex, number of left teats, and number of right teats. The six key feature subsets obtained are: age at reaching the preset weight, season of birth, number of piglets born, birth weight, parity of the sow, and sex.
[0050] It should be noted that the six key features obtained in this embodiment were screened for Yorkshire pigs, but the feature selection method provided by this invention is applicable to ADG prediction values of different pig breeds.
[0051] Optionally, the method further includes: acquiring historical important feature data and corresponding actual average daily weight gain; constructing an initial CatBoost prediction model; using the historical important feature data as input labels, the corresponding actual average daily weight gain as supervision labels, and the asymmetric loss function as the objective function, applying monotonic constraints to the features in the historical important feature data based on a monotonicity constraint mechanism, training the initial CatBoost prediction model, and obtaining the pre-trained CatBoost prediction model.
[0052] Optionally, the asymmetric loss function is as shown in formula (1): ; Where y is the actual value of the average daily weight gain; The predicted value of the initial CatBoost prediction model; This indicates the overestimation error; This indicates the underestimation error; w_over is the first penalty weight, and w_under is the second penalty weight.
[0053] when At that time, the CatBoost initial prediction model produced an overestimation error in its predictions. Indicates overestimation error; when At that time, the CatBoost initial prediction model produced an underestimation error in its predictions. This indicates an underestimation of the error.
[0054] The asymmetric loss function imposes a greater penalty on overestimation errors where the predicted value is higher than the actual average daily weight gain than on underestimation errors where the predicted value is lower than the actual average daily weight gain.
[0055] The ratio of the first penalty weight w_over to the second penalty weight w_under is determined based on the proportion of economic losses caused by overestimating the predicted average daily weight gain versus underestimating the predicted average daily weight gain. This ensures that the model prioritizes avoiding overestimation risks during training, thereby reducing economic losses in production decisions.
[0056] Optionally, the historical important feature data includes the age at which the preset weight is reached, birth weight, and number of litters; the imposition of monotonic constraints on the features in the historical important feature data based on the monotonicity constraint mechanism includes: imposing a monotonically decreasing constraint on the age at which the preset weight is reached; imposing a monotonically increasing constraint on the birth weight; and imposing a monotonically decreasing constraint on the number of litters.
[0057] A monotonically decreasing constraint is applied to the age at which the preset weight is reached to ensure that an increase in birth weight does not lead to an increase in the predicted average daily weight gain; a monotonically increasing constraint is applied to birth weight to ensure that an increase in birth weight does not lead to a decrease in the predicted average daily weight gain; and a monotonically decreasing constraint is applied to the number of litters to ensure that an increase in birth weight does not lead to an increase in the predicted average daily weight gain.
[0058] In pig growth, birth weight is a key indicator reflecting fetal development. Generally, a larger birth weight indicates that the individual received more adequate nutrition during the embryonic stage, laying a good foundation for physical constitution. This innate advantage often translates into higher growth potential in the subsequent fattening stage. Therefore, within a reasonable physiological range, there is a clear positive correlation between birth weight and average daily weight gain (ADG); that is, the higher the birth weight, the greater the expected ADG. To ensure that the machine learning model accurately captures this fundamental physiological law, a monotonically increasing constraint is applied to the birth weight feature during training. This constraint forces the learning and maintenance of a positive correlation between birth weight and predicted ADG, effectively preventing the model from erroneously deriving a negative correlation that defies common sense from training data noise, thus ensuring the physiological rationality and reliability of the prediction results.
[0059] Litter size reflects the size of the litter and significantly impacts individual growth. When there are many piglets in a litter, individuals face more intense competition for maternal milk during lactation. This early nutritional pressure can inhibit the growth and development of some individuals, thus affecting their subsequent growth rate. Therefore, litter size typically has a negative impact on individual growth rate (ADG). To ensure the prediction model conforms to this biological mechanism, a monotonically decreasing constraint is applied to the litter size feature during training. This constraint guides the model to learn the relationship between a decrease in predicted ADG and a stable trend as litter size increases, avoiding the unreasonable inference that increased litter size leads to accelerated individual growth, and ensuring that the model output aligns with the actual biological logic of competition.
[0060] Reaching 30kg body weight at a young age is a core indicator for assessing early growth rate in pigs, directly reflecting their growth and development status. When pigs reach 30kg at a relatively young age, it indicates excellent growth performance and a high expected growth rate (ADG). However, exceeding a certain physiological threshold signifies growth retardation. This retardation can be caused by multiple factors, including health, management, and genetics, and has a sustained negative impact on subsequent weight gain. To accurately capture the effect of growth retardation, a retardation index is calculated to quantify the number of days exceeding the threshold. A monotonically decreasing constraint is imposed on this index, requiring the model to establish a negative correlation between the degree of retardation and ADG; that is, the more severe the retardation, the lower the predicted growth rate. This constraint ensures that the model can accurately identify the poor performance of individuals with growth retardation, providing targeted early warning information for production management.
[0061] Optionally, determining and outputting the average daily weight gain prediction value based on the average daily weight gain prediction value includes: adjusting the average daily weight gain prediction value downward based on a preset calibration offset value to obtain the average daily weight gain prediction value to be output; and outputting the average daily weight gain prediction value to be output.
[0062] In some embodiments, the interpretability analysis of the CatBoost prediction model is performed using the Shapley Additive exPlanations (SHAP) method. The specific process includes: based on the trained and parameter-fixed CatBoost prediction model, calculating the SHAP value for each sample on the six selected features using the SHAP method; obtaining the feature importance ranking by calculating the average absolute SHAP value of each feature, and outputting a SHAP summary plot to visualize the continuous influence trend of feature values from low to high on the prediction results, thereby revealing the overall contribution of each feature to the predicted average daily weight gain from a global perspective.
[0063] A SHAP waterfall plot was generated for the pigs under test, decomposing the predicted average daily weight gain into the positive and negative contributions of each feature relative to the output. For example, the analysis showed that when the age at 30 kg was higher than approximately 73.11 days, the SHAP value was positive, significantly improving the predicted ADG value. Meanwhile, combinations of features such as spring or winter birth, higher parity, male offspring, and higher birth weight were also identified as key factors contributing positively to ADG. This individual-level factor decomposition allows farmers to intuitively understand the model's specific predictive logic for individual pigs.
[0064] Furthermore, this embodiment also supports identifying feature combinations that significantly impact ADG prediction, such as "age and season at which 30 kg is reached," by calculating SHAP interaction values between features, and visualizing these combinations using interaction heatmaps and dependency graphs. This complete interpretability analysis framework not only solves the transparency problem of machine learning models but also provides direct data support and decision-making basis for breeding strategy formulation and feeding management optimization. In actual pig farm implementation, it significantly outperforms traditional, uninterpretable machine learning models.
[0065] For example, when the sow reaches a weight of 30kg and is more than 73.11 days old, the SHAP value is positive, which significantly improves the ADG predictive value; combinations such as spring or winter birth season, 5th or 6th parity of the sow, and male sex also contribute positively to the ADG predictive value.
[0066] In some embodiments, pig farm managers can mark pigs with low ADG predicted values as key targets for attention based on ADG predicted values and SHAP interpretations, and adjust the diet level or feeding environment appropriately; pigs with high ADG predicted values can be regarded as potential fattening dominant individuals, and the slaughtering rhythm or subsequent selection can be optimized; the batch prediction and interpretation results can be exported for comparison with actual weight gain data to evaluate the effectiveness of management measures.
[0067] The following describes a machine learning-based method for predicting average daily weight gain in pigs, using a specific embodiment. This specific embodiment is merely for illustrating the invention and does not constitute an undue limitation thereof.
[0068] Historical production data of 12,079 purebred Yorkshire pigs collected from a commercial pig farm between February 2020 and April 2024 were selected to construct a dataset with a sample size of 12,079. The historical production data includes at least fields characterizing early growth and management information of individual pigs.
[0069] Historical production data is preprocessed, and the preprocessing steps include: handling missing values, handling outliers, handling data consistency, encoding categorical variables, and preventing data leakage.
[0070] Missing value handling includes: removing samples with missing key fields, or filling them with values using methods such as mean, median, mode, or model imputation. Outlier handling includes: identifying and removing or correcting abnormal records based on physiologically reasonable ranges, box plots, Z-scores, or business rules. Data consistency handling includes: standardizing units of measurement and field meanings to ensure consistent field definitions across the entire dataset. Categorical variable encoding includes: numerically encoding categorical features such as season and gender. Data leakage prevention includes: after dividing the training and test sets, transforming the test set using statistics from the training set to avoid information leakage.
[0071] The data is divided into training and test sets based on individual pigs. The training set contains data from 8455 pigs, and the test set contains data from 3624 pigs. Before feature selection, the candidate features for each pig constitute an 8-dimensional feature set. The features of all samples are stacked to form a feature matrix with 8 columns. The output labels are the actual average daily weight gain calculated based on weight increment and growth days, forming corresponding label vectors. Next, through feature importance evaluation and sequential forward feature selection, 6 important features are selected from the 8 candidate features to form the final feature matrix used for model training, with 6 columns. When training the CatBoost prediction model, continuous features can be optionally standardized or normalized.
[0072] To verify the superiority of the selected CatBoost prediction model, its prediction performance was compared with 14 other regression models trained on the same dataset, with the same features, and with the same data partitioning. The comparison models included: Multilayer Perceptron (MLP), Random Forest (RF), Gradient Boosting Machine (GBM), Support Vector Regression (SVR), Extreme Randomized Trees (ET), K-Nearest Neighbors Regression (KNN), Adaptive Boosting (AdaBoost), Decision Tree (DT), Bayesian Regression (BR), Ridge Regression (Ridge), Elastic Net Regression (ElasticNet), Lasso Regression (Lasso), Linear Regression (LR), and RANSAC (Random Sample Consensus Regression). To ensure fairness in the comparison, all models adopted a unified training process, using the same training and test sets. Hyperparameter search was performed on each model, and the average performance of cross-validation was used as the selection criterion. The training objective was to minimize the prediction error, and the evaluation metrics included RMSE, MAE, MAPE, and R-squared. 2 Optional settings include random seeding and early stopping strategies to improve stability.
[0073] Table 1 provides the optimal parameter values and corresponding performance metrics for the above 14 regression models and the CatBoost prediction model of this application.
[0074] Table 1 Performance metrics of 14 regression models and CatBoost prediction model As shown in Table 1, under the same input features and evaluation system, the CatBoost prediction model significantly outperforms other comparative models in overall prediction performance. The specific performance metrics of the CatBoost prediction model are: Root Mean Square Error (RMSE) of 46.8246, Mean Absolute Error (MAE) of 36.3759, Mean Absolute Percentage Error (MAPE) of 4.09%, and Coefficient of Determination (R²). 2 The value is 0.7223.
[0075] The above comparison results confirm that the CatBoost prediction model, as the core prediction model, has a stronger ability to model categorical features and nonlinear relationships, is more robust to missing values and inconsistent feature scales, is easy to combine with methods such as SHAP to output feature contribution, and makes the prediction results interpretable. In addition, it has fast inference speed and low deployment cost, making it more suitable for on-site applications in pig farms.
[0076] In some embodiments, considering the biological characteristics of group effects among piglets in the same litter and the fact that samples are not completely independent during the growth of pigs, a litter-level feature construction and verification strategy is introduced to improve the physiological rationality and generalization ability of the prediction model by explicitly modeling litter correlation.
[0077] Accordingly, daily production data includes individual daily production data and litter-level daily production data; obtaining daily production data for pigs to be predicted includes: measuring individual daily production data and litter-level daily production data during the growth process of the pigs to be predicted; wherein, individual daily production data includes: age at which the preset weight is reached, birth season, number of piglets born, birth weight, parity of the sow, sex, number of left teats and number of right teats; litter-level daily production data includes: average birth weight per litter, coefficient of variation or standard deviation of birth weight, average age at which the litter reaches the preset weight, and number of piglets per litter. Using the litter number as a group identifier, the litter-level characteristics of each litter are calculated, including: average birth weight per litter; coefficient of variation or standard deviation of birth weight; average age at 30 kg body weight per litter; and litter size, etc.
[0078] Both litter-level features and individual features are used as model inputs, enabling the model to identify population biological trends such as overall litter size (fat / thin), early maturity / late maturity, etc., thereby enhancing the ability to capture population background information.
[0079] Building upon litter-level statistical characteristics, further features reflecting the differences in an individual's relative position within the litter are constructed, such as the difference between an individual's birth weight and the litter's average birth weight, or the difference between the age at which an individual reaches 30 kg and the litter's average age. By introducing relative features and utilizing absolute individual indicators, the potential impact of relative advantages or disadvantages within the litter due to resource competition or genetic differences on adult growth factor (ADG) can be captured.
[0080] To strictly avoid information leakage within a nest and to accurately assess the model's generalization ability on new populations, a nest-based cross-validation strategy is adopted during the model training and evaluation phases. Data is divided by nest number to ensure that all individuals from the same nest appear only in either the training or validation set, and are never split into different sets. When performing K-fold cross-validation or training / test partitioning, sampling is performed using nests as the basic unit, thereby guaranteeing the independence of model evaluation.
[0081] By introducing litter-level statistical features, individual relative features, and validation methods based on litter grouping, the explicit modeling capability for litter correlations was significantly enhanced. While improving prediction accuracy, the model's stability and practicality across different pig populations were ensured, providing a more reliable quantitative basis for breeding group management and precision feeding decisions.
[0082] In some embodiments, the pig average daily weight gain prediction method proposed in this application achieves high-precision prediction without relying on genomic data through technological innovation, providing a practical growth performance assessment tool for large-scale pig farms.
[0083] High-precision prediction is achieved using low-cost phenotypic data, significantly lowering the application threshold. Accurate prediction of average daily weight gain (ADG) in Yorkshire pigs can be made using only readily available daily production data from pig farm records. The model exhibits high coefficients of determination and low error indices in both independent test sets and external validation herds. Compared to traditional methods requiring genotypic data or complex genetic assessments, this application significantly reduces data acquisition costs and technical barriers, making it more suitable for commercial pig farms. Feature selection ensures prediction accuracy and robustness. This application employs a strategy combining LightGBM feature importance ranking with sequential forward feature selection to systematically select six core features for ADG prediction from the initial feature set. The CatBoost prediction model maintains stable prediction performance under different genetic backgrounds and management conditions, demonstrating excellent generalization ability. Integration of SHAP interpretability technology enhances model transparency and decision support value. This application integrates the SHAP method into the prediction process, providing both global feature importance ranking and factor decomposition of individual prediction results, clearly demonstrating the direction and degree of contribution of each feature to the predicted value. This interpretable design allows breeders to intuitively understand the biological logic behind the predictions, such as the impact of factors like age at 30kg weight and season on ADG predictions, thus providing a direct basis for precision feeding and selective breeding. It empowers early growth potential identification and optimizes the efficiency of livestock resource allocation. Based on the prediction and interpretation results of this application, producers can accurately identify high-potential and low-potential individuals in the early stages of pig growth, thereby adjusting feeding strategies accordingly. This refined management helps achieve optimal resource allocation, improves overall production efficiency, and reduces feeding costs, creating significant economic benefits for pig farms.
[0084] Figure 2 A schematic diagram of a machine learning-based pig average daily weight gain prediction system provided in this application embodiment is shown below. Figure 2 As shown, this application proposes a machine learning-based system for predicting the average daily weight gain of pigs. The system 200 includes: a data acquisition module 210, a feature processing module 220, a prediction module 230, and an output module 240. The data acquisition module 210 is used to acquire the daily production data of the pigs to be predicted; The feature processing module 220 is used to extract important feature data that matches a predefined important feature subset from the daily production data; the predefined important feature subset is obtained by calculating the feature importance of candidate historical feature sets and ranking them based on a pre-trained LightGBM regression model, and then filtering them using a sequential forward feature selection method based on the ranking results. The prediction module 230 is used to obtain the average daily weight gain prediction value of the pig to be predicted based on the important feature data and through a pre-trained CatBoost prediction model; the pre-trained CatBoost prediction model is trained based on an asymmetric loss function; in the asymmetric loss function, the first penalty weight corresponding to the overestimation error is greater than the second penalty weight corresponding to the underestimation error; The output module 240 is used to determine and output the average daily weight gain prediction value based on the average daily weight gain prediction value.
[0085] In some embodiments, the system 200 may be deployed on a server or in the cloud to provide interactive prediction services to pig farm users.
[0086] In some embodiments, system 200 further includes an explanation module and a display module.
[0087] The interpretation module is used to call the SHAP interpretation engine integrated in this invention to automatically calculate the SHAP value of each feature for each prediction result and generate visual interpretation results such as waterfall plots, force-directed plots or summary plots to quantitatively display the positive and negative contribution of each feature to the ADG prediction value of the pig to be predicted, thereby improving the transparency and interpretability of the prediction results.
[0088] The display module is used to build an interactive graphical interface based on a web framework, which presents ADG predicted values, SHAP interpretation charts, and global feature importance ranking in real time. It also supports users to export prediction results and visualization images with one click, which can be easily incorporated into production management files to provide data support for feeding decisions and breeding plans.
[0089] In some embodiments, this application encapsulates a machine learning-based pig average daily weight gain prediction system into an online tool system. Users can input the daily production data of the pigs to be predicted to obtain the predicted average daily weight gain and attribution analysis in real time, and the results can be exported, thereby transforming scientific research results into a plug-and-play decision support system for front-line production sites.
[0090] This application enables efficient transformation from model to production through an integrated web application. It constructs a complete web application system that integrates data input, feature processing, CatBoost prediction, SHAP interpretation, and result display onto a unified platform. Pig farm personnel, without requiring professional programming backgrounds, can obtain prediction results and visual interpretations in real time by inputting phenotypic information through the interface, and can export detailed reports for production recording and analysis. This design solves the problem that most research models remain at the offline script stage, achieving a seamless process from algorithm innovation to field application.
[0091] It should be noted that the description of the above system embodiments is similar to the description of the above method embodiments, and has similar beneficial effects. For technical details not disclosed in the system embodiments of this application, please refer to the description of the method embodiments of this application for understanding.
[0092] It should be noted that, in the embodiments of this application, if the above-mentioned machine learning-based method for predicting the average daily weight gain of pigs is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, or the part that contributes to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a magnetic disk, or an optical disk. Thus, the embodiments of this application are not limited to any specific hardware and software combination.
[0093] Correspondingly, embodiments of this application provide a computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the steps in any of the machine learning-based methods for predicting average daily weight gain in pigs described in the above embodiments. Correspondingly, embodiments of this application also provide a computer program product, which, when executed by a processor of an electronic device, is used to implement the steps in any of the machine learning-based methods for predicting average daily weight gain in pigs described in the above embodiments.
[0094] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely descriptive and do not represent the superiority or inferiority of the embodiments.
[0095] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0096] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.
[0097] The units described above as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; they may be located in one place or distributed across multiple network units; some or all of the units may be selected to achieve the purpose of the embodiments of this application according to actual needs. In addition, each functional unit in the embodiments of this application may be fully integrated into one processing unit, or each unit may be a separate unit, or two or more units may be integrated into one unit; the integrated unit may be implemented in hardware or in the form of hardware plus software functional units.
[0098] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined to obtain new method embodiments without conflict. The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined to obtain new method embodiments or device embodiments without conflict.
[0099] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for predicting the average daily weight gain of pigs based on machine learning, characterized in that, The method includes: Obtain daily production data of the pigs to be predicted; From the daily production data, important feature data that matches a predefined important feature subset is extracted; the predefined important feature subset is obtained by calculating the feature importance of candidate historical feature sets and ranking them based on a pre-trained LightGBM regression model, and then filtering them using a sequential forward feature selection method based on the ranking results. Based on the aforementioned key feature data, the average daily weight gain prediction value of the pigs to be predicted is obtained through a pre-trained CatBoost prediction model. The pre-trained CatBoost prediction model is trained based on an asymmetric loss function. In the asymmetric loss function, the first penalty weight corresponding to the overestimation error is greater than the second penalty weight corresponding to the underestimation error. Based on the predicted average daily weight gain, determine and output the predicted average daily weight gain to be output.
2. The method according to claim 1, characterized in that, The daily production data includes the age at which the pig reaches the preset weight, the season of birth, the number of piglets born, the birth weight, the parity of the sow, the sex, the number of left teats, and the number of right teats; obtaining the daily production data of the pigs to be predicted includes: During the growth process of the pig to be predicted, the following information is recorded: the age at which the pig reaches the preset weight, the season of birth, the number of piglets born, the birth weight, the parity of the sow, the sex, the number of left teats, and the number of right teats.
3. The method according to claim 1, characterized in that, The method further includes: Obtain historical production data and corresponding average daily weight gain for multiple historical pigs; Construct the initial LightGBM regression model; Using multiple historical production data as input data and the corresponding average daily weight gain as labels, the initial LightGBM regression model is trained to obtain the pre-trained LightGBM regression model.
4. The method according to claim 3, characterized in that, The method further includes: Based on the pre-trained LightGBM regression model, calculate the number of splits of each historical feature in the candidate historical feature set as a split node in the decision tree of the pre-trained LightGBM regression model. The feature importance of candidate historical features in the candidate historical feature set is determined in descending order of the number of splits. Based on the feature importance, the candidate historical features are sorted to generate a feature importance ranking; Based on the ranking of feature importance, the predefined subset of important features is determined by the sequential forward feature selection method.
5. The method according to claim 4, characterized in that, The step of determining the predefined important feature subset based on the feature importance ranking and using a sequential forward feature selection method includes: Initialize the original feature subset to an empty set; Based on the feature importance ranking, the sequential forward feature selection method is used to add each of the candidate historical features in the candidate historical feature set to the original feature subset in descending order of feature importance, thereby generating multiple candidate historical feature subsets containing different numbers of the candidate historical features. Based on each of the candidate historical feature subsets, the initial LightGBM regression model is trained K times using the historical production data and the corresponding average daily weight gain, and the average determination coefficient of each candidate historical feature subset is obtained. Compare the average determination coefficients corresponding to each candidate historical feature subset; determine the candidate historical feature subset with the largest average determination coefficient as the predefined important feature subset.
6. The method according to claim 1, characterized in that, The method further includes: Obtain historical key feature data and corresponding average daily weight gain; Construct the initial CatBoost prediction model; Using the historical important feature data as input labels, the corresponding average daily weight gain as supervision labels, and the asymmetric loss function as the objective function, the initial CatBoost prediction model is trained by applying monotonic constraints to the features in the historical important feature data based on the monotonicity constraint mechanism, thus obtaining the pre-trained CatBoost prediction model.
7. The method according to claim 6, characterized in that, The formula for the asymmetric loss function is: ; Where y is the actual value of the average daily weight gain; The predicted value of the initial CatBoost prediction model; This indicates the overestimation error; This indicates the underestimation error; w_over is the first penalty weight, and w_under is the second penalty weight.
8. The method according to claim 6, characterized in that, The historical key characteristic data includes the age at which the preset weight is reached, birth weight, and number of litters; the application of monotonic constraints to the features in the historical key characteristic data based on the monotonicity constraint mechanism includes: A monotonically decreasing constraint is applied to the age at which the preset weight is reached. A monotonically increasing constraint is applied to the initial weight; A monotonically decreasing constraint is applied to the number of offspring.
9. The method according to claim 1, characterized in that, The step of determining and outputting the average daily weight gain prediction value based on the predicted average daily weight gain value includes: The average daily weight gain prediction value is adjusted downward based on the preset calibration offset value to obtain the average daily weight gain prediction value to be output. Output the predicted average daily weight gain value to be output.
10. A machine learning-based system for predicting the average daily weight gain of pigs, characterized in that, The system includes: a data acquisition module, a feature processing module, a prediction module, and an output module; The data acquisition module is used to acquire the daily production data of the pigs to be predicted; The feature processing module is used to extract important feature data that matches a predefined important feature subset from the daily production data; the predefined important feature subset is obtained by calculating the feature importance of candidate historical feature sets and ranking them based on a pre-trained LightGBM regression model, and then filtering them using a sequential forward feature selection method based on the ranking results. The prediction module is used to obtain the average daily weight gain prediction value of the pig to be predicted based on the important feature data and through a pre-trained CatBoost prediction model; the pre-trained CatBoost prediction model is trained based on an asymmetric loss function; in the asymmetric loss function, the first penalty weight corresponding to the overestimation error is greater than the second penalty weight corresponding to the underestimation error; The output module is used to determine and output the average daily weight gain prediction value based on the average daily weight gain prediction value.
