1. Introduction
The Mexican hairy pig originates from pigs that arrived in Mexico from Europe in 1492, and there are three subpopulations: Mexican Hairy, Cuino, and Mule’s Foot [
1]. The largest Mexican hairy pig population is currently found in Veracruz, Puebla, Tabasco, and the Yucatan Peninsula [
2]. In this region, the hairy pig is of great importance as it is part of the culture and gastronomy of the communities; hairy pig producers are creating associations specialized in the breeding of this biotype and there is a need for information that will allow them to be managed appropriately [
3].
In pig production, live weight is an important indicator in determining the optimal time for slaughtering pigs, minimizing costs and labor during the fattening phase [
4]. While directly measuring live weight using scales is considered one of the most accurate methods, it may not always be feasible, especially in field conditions. The lack of suitable weighing equipment in many small-scale or traditional businesses, or the economic and logistical challenges of establishing weighing systems, can limit the direct measurement of live weight. Furthermore, the need to transport or restrain animals during the weighing process can, in some cases, increase the risk of stress and injury for both animals and producers. Also, to implement the robotic technologies or visual processing methods into livestock sector, biometric studies should be conducted before [
5]. Indirect methods, such as 3D imaging, offer alternatives, but more practical approaches to estimating live weight are still needed [
6,
7,
8]. Even in the indirect methods used for animal welfare, biometric measurements should be taken by the breeders or researchers first to build up the model.
On the other hand, biometric measurements have also been used as indirect methods for predicting live weight; some of the most used morphometric measurements include chest circumference, height at withers, hip width/height, and body length. The measurements are obtained manually and used to create new estimation models for different species such as cattle [
9,
10,
11], pigs [
12,
13,
14,
15], sheep [
16,
17,
18], goats [
19], camels [
20], and yak [
21]. In this study, biometric measurements were obtained manually directly from the animal using measuring instruments. Although image processing and computer vision-based methods are also widely used in the literature for obtaining biometric features, the manual measurement method was preferred in this study to offer a more applicable and practical approach in field conditions. This approach increases applicability, especially in production systems where technological infrastructure is limited.
To achieve this aim, the researchers employed various parametric statistical approaches that require strict data structure assumptions. Generally, these types of datasets cannot provide the assumptions needed [
22]. To overcome these problems, several machine learning algorithms were proposed. Currently, there are a few studies that have applied machine learning techniques in animal science. Caraviello et al. [
23] and Shahinfar et al. [
24] analyzed production variables in dairy cattle using different machine learning techniques, including decision trees and support vector machines. Lee et al. [
25] developed a deep learning-based algorithm for anomaly detection in cattle. The productivity of sows was investigated using a machine learning scheme in Lee and Choe [
26]. Few studies have been conducted on estimating live weight from body measurements for different species. In this context, we aimed to predict live weight from body measurements for Yucatecan Criollo pigs using the XGBoost and LightGBM algorithms, which are the most commonly suggested algorithms in this aspect for various species.
3. Results
Table 1 presents the results of the study on estimating the live weight of Yucatecan Criollo pigs based on their biometric measurements. The table details mean, standard error, median, minimum, maximum values, and coefficients of variation (CV%) for female and male pigs. In addition, since the variables did not meet the normality assumption, comparisons between sexes were performed using the non-parametric Mann–Whitney U test; the obtained significance levels (
p-values) and corresponding effect sizes are presented in
Table 1.
According to the results presented in
Table 1, differences were observed between sexes in some biometric features. According to the Mann–Whitney U test results, statistically significant differences were observed in BW, HeL, ML, CanG, and BD (
p < 0.05). In all of these variables, the mean values of male pigs were found to be higher than those of female pigs. Effect size analysis revealed a moderate effect (
r = 0.342) for the BW variable, while the effect size remained small in other significant variables. These results suggest that statistically significant differences may not always reflect a high level of practical or biological impact. In other biometric variables (BL, HaL, RL, RH, WH, CheG, AG, LD, and RW), no statistically significant difference was found between sexes (
p > 0.05). In addition, according to
Table 1, BW for female pigs ranged from 25 kg to 110 kg, with an average of 54.8 kg and a coefficient of 28.23%. The lowest coefficient of variation was observed in BL with 7.63%, while the highest coefficient of variation was recorded in AG with 15.29%. This shows that the biometric characteristics of the female pigs were relatively consistent. For the male pigs, BW was observed in a wide range from 34 kg to 130 kg with an average of 71.98 kg and the coefficient of variation showed a higher variability of 31.41% over 48 samples. The lowest coefficient of variation was recorded in BL with 8.84% and the highest was recorded in BD with 19.56%. The higher coefficients of variation observed in the characteristics of the male pigs suggest that the biometric characteristics show more variability in this group. In general, this table shows the biometric characteristics of Yucatecan Criollo pigs that differ according to sex and how these characteristics are distributed in the general population. It is concluded that sex has a significant effect on the biometric characteristics of pigs and that this effect should be taken into account when developing live weight estimation models. These results may allow for a more detailed examination of the sex factor in future studies and the integration of this information into pig farming practices.
Figure 2 presents the relationships between biometric features of Yucatecan Criollo pigs using pair plot analysis, separated by sex. This analysis visualizes the relationships between variables and the distributions of these features for male (M) and female (F) pigs. In addition, in
Figure 2, the values presented as “Corr” represent the relationships between variables calculated without regard to sex. In the color coding used in the graph, blue represents male and red represents female pigs, allowing for a clearer assessment of the direction and strength of the relationships between sexes. Relationships between features are interpreted according to the density and distribution of points in the scatter plots, with strong relationships characterized by a linear pattern and weak relationships by a more dispersed structure. The histogram and density plots on the diagonal reveal the sex-dependent distribution of each variable, providing information on the symmetry and variability of the distribution. Furthermore, to ensure statistical reliability,
p-values were corrected using the False Discovery Rate (FDR) method, and the strength of the relationships between variables was evaluated according to effect size. The correlation structure obtained within this scope is visually presented for the entire dataset and subgroups by sex.
According to the correlation analysis results presented in
Figure 2, the relationships between live weight (BW) and biometric features show significant differences both in the entire dataset and in subgroups based on sex. Almost all
p-values obtained after FDR correction are statistically significant (mostly p_adj < 0.001), indicating that the obtained relationships are reliable despite multiple comparisons. When the entire dataset is evaluated, strong positive correlations were determined between BW and variables such as BD (r = 0.700), WH (r = 0.692), CheG (r = 0.687), and RL (r = 0.668). In contrast, the correlations of some variables such as HeL, ML, and BL with BW remained at a moderate level. In the evaluations based on sex, these relationships were found to be significantly different. For females, the correlations with BW generally range from moderate to strong, with RW (r = 0.690), CheG (r = 0.645), AG (r = 0.648), and WH (r = 0.637) variables being particularly prominent. However, it is noteworthy that the HeL variable’s correlation with BW remains weak (r = 0.256). For males, the correlation coefficients are observed to increase significantly, reaching very strong levels for many variables. In particular, CanG (r = 0.842), WH (r = 0.829), CheG (r = 0.773), RH (r = 0.764), and RL (r = 0.742) variables show very strong correlations with BW. When the entire dataset is considered, the relationships between live weight (BW) and biometric features are not only statistically significant but also strong in terms of effect size, and these relationships differ by sex. These results suggest that accounting for sex when selecting variables for live weight estimation may be important.
Table 2 presents the optimized hyperparameter value ranges for two popular machine learning models used in this study, XGBoost and LightGBM. This table shows the optimal value ranges of eta, max_depth, and min_child_weight parameters for XGBoost, and learning_rate, num_leaves, and min_data_in_leaf parameters for LightGBM, determined as a result of various experiments. In addition, the limit of the number of iterations for both models is also specified. The purpose of the table is to show the results obtained in the hyperparameter optimization process in detail and to reveal the effects of these parameters on model performance. These optimized parameters were selected to ensure that the models learn better on the data and increase the overall prediction success.
For both models, hyperparameter optimization was performed to provide the best model performance. For the XGBoost model, optimization was performed on values ranging from 0.05 to 0.3 for learning rate (eta), 2 to 10 for maximum depth, and 1 to 6 for minimum child weight. For the LightGBM model, learning rate (learning_rate) was set between 0.01 and 0.1, num_leaves between 20 and 60, and minimum data per leaf (min_data_in_leaf) between 20 and 60. These optimization processes were performed to increase the prediction success of the models, and the obtained parameter ranges play an important role in increasing the sensitivity and generalizability of the model.
Table 3 presents the optimum hyperparameter values for two popular machine learning models, XGBoost and LightGBM, and the goodness-of-fit criteria for each model. For XGBoost, the optimal hyperparameters are determined as learning rate (eta) 0.2, maximum depth (max_depth) 3, and minimum child weight (min_child_weight) 1. For LightGBM, the learning rate (learning_rate) 0.08, number of leaves (num_leaves) 20, and minimum number of data per leaf (min_data_in_leaf) 20.
According to
Table 3, the performance of both models on the training and test datasets was evaluated with R-squared (R
2), Mean Squared Error (RMSE), and Mean Absolute Error (MAE) metrics. The R
2 value of the XGBoost model was calculated as 0.997 in the training set and 0.905 in the test set. RMSE was determined as 1.064 in training and 5.704 in the test; MAE was determined as 0.738 in training and 3.636 in the test. The obtained performance values indicate that the model achieved a good level of fit to the training dataset and exhibited a relatively lower, yet acceptable and reliable predictive performance on the test dataset. For the LightGBM model, the R
2 value was determined as 0.915 in the training set and 0.824 in the test set. These values show that the LightGBM model also learned the data well and can make reasonable generalizations. RMSE was measured as 5.781 in training and 7.772 in testing; MAE was measured as 4.201 in training and 5.505 in testing. Although these results show that the LightGBM model has slightly lower performance than the XGBoost model, it still reveals that it is an effective model that can be preferred depending on different data structures and features. As a result, both models achieved significant performance with their respective hyperparameter configurations, and the XGBoost model in particular attracted attention for its high R
2 values. These results can serve as an important reference when selecting models and adjusting hyperparameters on similar datasets.
Figure 3 presents visuals comparing the performances of XGBoost and LightGBM models on training sets with R
2, RMSE, and MAE metrics.
The XGBoost model generally showed improvement in R
2 values with the increase in learning rate, reaching a maximum level of 0.99. This shows that the model explains the dataset to a high extent and provides a good fit. This situation reveals that the XGBoost model can make predictions with less error, especially at eta values and depths. On the other hand, the R
2 values for the LightGBM model were high when the learning rate was around 0.08, but it was observed that these values became more stable as the learning rate increased. According to these results, it is shown that the LightGBM model can also provide efficient results at certain parameter settings. The performances of both models emphasize how critical the hyperparameters used and the configuration of the model are. Model selection and hyperparameter adjustments should be made carefully, considering the nature of the dataset and the specific requirements. Determining the ideal model settings can be possible by understanding the structure and characteristics of the data well and applying this information correctly. In this context, the optimization processes of both models should be considered an important step to increase the model’s overall success and make more accurate predictions. The visuals in
Figure 4 show the hyperparameter optimization results of the XGBoost and LightGBM models on the test dataset. The results obtained using three different performance metrics (R
2, RMSE, and MAE) for both models are presented comparatively.
As a general comment for the visuals in
Figure 4, the performance analysis of both models on the test set clearly shows the impact of hyperparameters on model performance. The XGBoost and LightGBM models yield the best results, especially at certain combinations of learning rate and maximum depth. These figures highlight the importance of model selection and hyperparameter tuning and show the usefulness of such analyses in the model development process. In conclusion, both models can be effective in certain settings and optimization processes play a critical role in maximizing the potential of these models.
Figure 5 shows the variable importance values calculated based on the sensitivity analysis results; these values belong to the XGBoost model used in body weight prediction.
According to
Figure 5, it was statistically determined that the most important variables for body weight prediction were CanG, CheG, HaL, BD, and RW.
Figure 6 shows the variable importance values calculated based on the sensitivity analysis results; these values belong to the LightGBM model used in body weight prediction. This figure identifies the features that play key roles in the model’s predictive ability and quantitatively presents the relative effects of the features on the model.
According to
Figure 6, the most striking finding is that CheG has the highest importance with 0.3166, indicating that this feature has a central role in the model’s predictions. Secondly, WH stands out with a value of 0.240, indicating that it has a significant effect on the model outputs. On the other hand, HaL and RL are observed to have a significant but lower effect with 0.127 and 0.117, respectively. The other features shown in the graph contribute less to the model’s performance with much lower importance levels. This analysis allows for a better understanding of the model and, if necessary, strategic decisions regarding feature selection, while also suggesting the removal of low importance features in order to simplify the model and increase its efficiency.
When
Figure 7 and
Figure 8 are considered, it is seen that the XGBoost and LightGBM models reveal significant differences in terms of the importance levels they attribute to the variables and the direction of the effects of these variables on the prediction. In the SHAP graph of the XGBoost model (
Figure 7), it is noteworthy that the variables CheG, HaL, and CanG have wider SHAP value ranges and have a strong effect on the prediction. High values (yellow tones) in these variables are generally associated with positive SHAP values, thus contributing to an increase in live weight prediction. In contrast, variables such as BL, HeL, and RH have a narrower distribution and their contribution to the model remains relatively limited.
In the SHAP graph of the LightGBM model (
Figure 8), a different distribution of variable effects is observed. In this model, the variables WH, HaL, and CanG stand out and reach higher SHAP values. Unlike the XGBoost model, the LightGBM model shows that some variables (e.g., BD, RW, and RL) have a wider range of influence in both positive and negative directions, indicating that the model captures intervariate interactions differently. Furthermore, the SHAP distributions of variables in the LightGBM model exhibit a more widespread and heterogeneous structure, which may be due to the model’s leaf-wise growth strategy and its focus on more specific data regions.
When both models are examined, it is seen that the HaL and CanG variables make significant contributions in both models, thus being among the key determinants in live weight estimation. However, it is understood that the XGBoost model yields more weight to certain variables, while the LightGBM model distributes variable effects in a more balanced and spread manner. These differences stem from the tree-building strategies (level-wise vs. leaf-wise) and learning dynamics of the two algorithms, highlighting the importance of considering data structure and intervariate relationships in model selection.
In addition, the differences in the obtained variable importance values between the XGBoost and LightGBM models examined in the current study are due to the structural differences in the data approach and learning mechanisms of these two models. XGBoost uses the gradient-boosted decision tree methodology, which tries to maximize the information gain while minimizing the error rate in each iteration. In this process, the model can provide more weight to certain features of the dataset, especially when expanding the tree branches, which causes the importance levels of some variables to increase. On the other hand, LightGBM is designed to increase efficiency and speed in large datasets as a lighter gradient-boosting model. LightGBM’s leaf-oriented growth strategy allows the model to grow more efficiently with lower losses and leads to the formation of different weights on different features. These structural and algorithmic differences have caused different feature importance levels to emerge in the examined dataset. This analysis shows that such structural differences should be taken into account in the model selection process and during the tuning of hyperparameters. In particular, understanding how models affect the learning dynamics on data and the optimization of feature selection will contribute to the development of more accurate and effective prediction models.
The findings clearly show how the structural and algorithmic differences of both models affect the importance ascribed to the features in the dataset. This analysis highlights the importance of considering the learning dynamics of the models in model selection and hyperparameter tuning, thus contributing to the development of more effective and accurate prediction models. In future studies, investigating how such structural differences perform under larger datasets and various scenarios will play a critical role in expanding the application areas of machine learning models and developing model optimization strategies. This study also provides valuable information that removing low-importance features from the model both reduces the complexity of the model and increases computational efficiency.
4. Discussion
The results obtained in our study show the differences in variable importance between XGBoost and LightGBM models in detail. These differences reveal how both advanced machine learning models’ hyperparameter settings and structural features affect variable importance. In addition, the findings provide valuable insights for strategic decision-making in data science and machine learning applications. The effects of these differences on model performance and the underlying reasons are discussed by providing suggestions for effective management of model selection and hyperparameter optimization processes. This analysis provides a better understanding of the models, which will contribute to more accurate and effective predictions, especially on large datasets.
The approach proposed in this study offers a practical and feasible solution for estimating live weight using biometric measurements. This method stands out as an alternative tool, especially in situations where weighing in the field is difficult, time-consuming, or poses risks to animal welfare. The developed machine learning models can provide fast and reliable predictions, support producers’ decision-making processes, and contribute to increased efficiency in herd management. Furthermore, its low cost and ease of implementation increase its potential for widespread use in various production systems. Live weight estimation studies conducted with machine learning models depend largely on the biometric characteristics of the animal species or breed to which the study is applied, as well as the success of the algorithms used. Since the genetic structure, growth pattern, body composition, and responses to environmental factors of each breed may differ, it may not be expected that the same model will show similar levels of success in different breeds or species. Therefore, the results obtained should be evaluated only in the context of the dataset and animal material used in the study. In order to use similar estimation approaches in different species or breeds, the model must be retrained, feature selection must be adapted according to the morphological and physiological structure of the relevant animal group and hyperparameters must be optimized according to the new data structure. This situation reveals that similar modeling studies should be structured specifically for each animal population and model generalizations should be made carefully.
Although advanced machine learning algorithms such as XGBoost and LightGBM have been used in the solution of various estimation and classification type problems in agriculture and animal husbandry in recent years, their areas of use are still limited, especially in specific applications such as live weight estimation. The number of studies in the literature on the application of these algorithms on animal husbandry data is quite low, and existing studies are generally limited to limited sample sizes, narrow-scope datasets, or analyses specific to certain breeds. This situation prevents the generalizability of these algorithms to be tested on different species and breeds and their wider applicability in the livestock sector. However, these algorithms offer significant advantages such as acceptable accuracy estimation capacity, resistance to over-learning, and the ability to optimize model performance through hyperparameter settings. Therefore, studies based on larger-scale and diversified datasets are needed for these methods to be more widely applied in animal breeding, especially in the estimation of economically important parameters such as live weight estimation.
In the study by Sungirai et al. [
14], the relationship between linear body measurements and live weight in Landrace and Large White breed pigs was investigated and it was revealed that the model created with the linear regression method exhibited different levels of accuracy depending on the rearing conditions of the animals. While a high correlation was obtained especially in commercial farm conditions, it was reported that the accuracy level of the similar model decreased significantly under different management conditions. These findings show that live weight estimation models are sensitive not only to the variables used but also to the rearing environment and care conditions of the animals. In the present study, live weight of Yucatecan Criollo pigs was estimated with advanced machine learning algorithms such as XGBoost and LightGBM and high levels of accuracy were obtained. However, the findings of the study by Sungirai et al. [
14] emphasize that such models may not be directly applicable to different breeds or different rearing systems and that model generalizability may be limited. This situation indicates that the models developed for live weight estimation are valid only within the framework of specific breeds and rearing conditions and should be adapted for different populations. Therefore, the acceptable-performance prediction models obtained in the present study should only be considered valid for pigs raised under similar environmental and management conditions.
In the study of Herrera-Camacho et al. [
47], the XGBoost and LightGBM algorithms were used to body weight prediction in Holstein X Zebu crossbred heifers. According to the results of this study, it yielded the most reliable results, especially in terms of R
2, RMSE, and MAE. In this respect, the results reported by Herrera-Camacho et al. [
47] support the performance of XGBoost and LightGBM in the current study conducted for live weight estimation. When the obtained R
2 and error measures (RMSE and MAE) are compared with the existing study, it can be said that similar results were obtained. However, it is considered that the differences observed in hyperparameter combinations may be due to variations in breeding conditions, environmental factors, and data structure among species, breeds, and farms.
In the study of Shehadeh et al. [
48], modified decision tree (MDT) was determined as the model with the acceptable accuracy rate among the machine learning algorithms used for the purpose of estimating the residual value of heavy construction equipment; however, LightGBM and XGBoost algorithms also achieved successful results with high R
2 values. While LightGBM stood out with higher accuracy than XGBoost in this study, the opposite was observed in the current study, and XGBoost showed a higher performance compared to LightGBM (R
2 = 0.824) with R
2 = 0.905 in the test data. This difference shows that the performance of the algorithms may vary depending on the structure of the dataset used, sample characteristics, and variable relationships. In addition, although it was stated in the study of Shehadeh et al. [
48] that the MDT model yielded the best results, the lack of detailed information about the dataset limits the comparability of the results. Therefore, although similar algorithms were used in both studies, data structure and problem-specific factors may have created a difference in the model ranking. This situation reveals that the generalizability of the algorithms should be evaluated carefully.
In the study of Alabdullah et al. [
49], LightGBM and XGBoost algorithms were used to predict the fast chloride permeation resistance of metakaolin, and both models were evaluated with the same performance metrics on training and test data. In that study, the LightGBM algorithm showed a more successful prediction performance compared to XGBoost. However, this situation was reversed in the current study; the XGBoost model showed a better overall performance with higher R
2 and lower error values compared to LightGBM. These conflicting findings show that the performance of both algorithms may vary depending on many factors such as the structure of the dataset, sample characteristics, and relationships with the target variable. The fact that detailed information about the dataset was not provided in the study of Alabdullah et al. [
49] limits the generalizability of comparisons between algorithms. In this context, although similar algorithms were used in both studies, it is understood that the model performance ranking may differ depending on the problem-specific data structure.
In the study conducted on rabbits by Önder et al. [
50], over 95% accuracy was achieved in body weight estimation with XGBoost and LightGBM algorithms, and especially BL (body length) stood out as the most explanatory variable. In the current study, with a wider set of biometric variables belonging to Yucatecan Criollo pigs, the XGBoost model showed higher performance compared to LightGBM with R
2 = 0.905 in the test data. Although it is seen that these algorithms are powerful tools for body weight estimation in both studies, differences in model performances may be due to the species used, variable structure and hyperparameter settings. This situation reveals that model applications should be evaluated specifically on a species and breed basis.
As the above-mentioned studies show, the use of advanced machine learning algorithms such as XGBoost and LightGBM in the field of animal husbandry, especially for live weight estimation, is extremely limited in the literature. The importance of the present study lies in the fact that it comparatively evaluates these two algorithms and makes a new contribution by successfully applying them to a unique animal material such as Yucatecan Criollo pigs. Although the acceptable-performance results obtained show that these algorithms can be used effectively in animal production data, considering the limited application examples in the literature, it is understood that such models should be evaluated separately for different breeds, species, and management systems. Therefore, the findings of the study should only be accepted as valid for animals raised under similar conditions; more empirical studies covering different environmental conditions and species-based are needed to reach wider application areas.
5. Conclusions
In this study, the performance of XGBoost and LightGBM models in predicting live weight in Yucatecan Criollo pigs using biometric measurements was comparatively evaluated, particularly in terms of hyperparameter optimization and variable importance levels. The results show that both models successfully captured the relationships between biometric features and live weight. However, the XGBoost model was found to exhibit superior prediction performance with higher R2 values and lower RMSE and MAE values. The LightGBM model, on the other hand, produced acceptable results under certain hyperparameter combinations, demonstrating that it can offer an alternative approach depending on the data structure and modeling objective. Variable importance analysis revealed that the two models assigned different levels of importance to the input variables. The XGBoost model, based on a level-wise tree growth strategy, yielded more weight to certain variables such as CanG, CheG, HaL, and BD, while the LightGBM model, in line with a leaf-wise growth strategy, highlighted variables such as CheG and WH and spread variable importance across a wider set of variables. These findings demonstrate that model selection and hyperparameter optimization should be performed considering the dataset structure and the learning mechanisms of the algorithms.
SHAP analysis, applied in addition to traditional variable significance measures, revealed the effects of variables on the model output in a more detailed and interpretable way. The SHAP results confirm that the variables HaL and CanG play a critical role in live weight estimation in both models. However, the ways in which the models captured variable effects differed. While variable effects were observed to be more pronounced and directional in the XGBoost model, variable effects exhibited a more widespread and heterogeneous distribution in the LightGBM model. This indicates that the LightGBM model can capture interactions between variables at a more local level, while the XGBoost model focuses on more dominant global patterns. From an application perspective, the approach proposed in this study offers a reliable and applicable alternative for estimating live weight based on biometric measurements. Especially in situations where weighing in the field is difficult, costly, or risky in terms of animal welfare, such models can support producers’ decision-making processes and increase operational efficiency by providing rapid and non-invasive estimates.
In conclusion, it is important to note that the findings of this study are based on a specific dataset of Yucatecan Criollo pigs. Therefore, caution should be exercised when generalizing these results to other breeds, populations, or production systems. Furthermore, the uneven sex distribution in the dataset and the model’s limitation to only biometric measurements are among the limitations that should be considered when interpreting the results. In addition, while both models exhibit acceptable performance, model success and interpretability differ depending on the data structure and the relationships between variables. Future studies are recommended to apply these approaches to larger, more diverse datasets, evaluate variable reduction strategies, and conduct research to improve the models’ generalization capabilities.