Next Article in Journal
Electromagnetic Radiation and Human Environment: Editorial
Previous Article in Journal
Numerical Study on Cold Plume Behavior in the RPV of a Small Mobile Reactor During Safety Injection
Previous Article in Special Issue
Improved Unsupervised Domain Generalization by Leaf-Bridge for Soybean Leaf Disease Identification
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

An IWMA-Optimized LightGBM Model for Early Ketosis Risk Screening in Dairy Cows Using DHI Data

College of Information Science and Technology, Gansu Agricultural University, Lanzhou 730070, China
*
Author to whom correspondence should be addressed.
Appl. Sci. 2026, 16(10), 5050; https://doi.org/10.3390/app16105050 (registering DOI)
Submission received: 4 April 2026 / Revised: 14 May 2026 / Accepted: 15 May 2026 / Published: 19 May 2026

Featured Application

The proposed IWMA-LightGBM model can be applied as a decision-support tool in precision dairy farming to enable early, non-invasive screening of milk fat-to-protein ratio (F/P)-based ketosis risk in dairy cows during early lactation. By leveraging routinely collected Dairy Herd Improvement (DHI) data, the model allows farmers and herd managers to identify high-risk individuals without additional labor or invasive testing. When integrated into farm management software or automated milking systems, this approach can provide real-time risk alerts, support targeted nutritional and health interventions, and optimize herd management strategies. Ultimately, its application can help reduce the risk of ketosis through early detection and intervention, improve milk production efficiency, and enhance overall farm profitability.

Abstract

Ketosis is a prevalent metabolic disorder in early-lactation dairy cows, significantly affecting animal health, milk production, and farm profitability. Developing accurate and non-invasive methods for early risk detection is therefore of critical importance. In this study, a hybrid optimization framework integrating an Improved Whale Migration Algorithm (IWMA) with a Light Gradient Boosting Machine (LightGBM) is proposed to predict ketosis risk based on the milk fat-to-protein ratio (F/P) using Dairy Herd Improvement (DHI) records. The proposed IWMA enhances optimization performance through cubic chaotic initialization, elite opposition-based learning, and a Cauchy–Gaussian hybrid mutation strategy, enabling improved global exploration and convergence stability. A dataset comprising 25,155 DHI records collected from multiple commercial dairy farms over seven months was used for model development and evaluation. Experimental results demonstrate that the IWMA–LightGBM model achieves a classification accuracy of 0.8997 and a mean squared error of 0.289, consistently outperforming six benchmark optimization methods. Feature analysis identifies Herd Within Index (WHI), Energy Corrected Milk (ECM), Days in Milk (DIM), Milk Urea Nitrogen, and Foremilk as key predictors associated with metabolic risk. Overall, the proposed approach provides a robust and effective non-invasive solution for early-stage metabolic risk screening at the herd level, offering practical value for precision dairy management. It should be noted that the model is intended for risk assessment rather than clinical diagnosis of ketosis.

1. Introduction

Ketosis is one of the most prevalent metabolic disorders affecting dairy cows during early lactation and represents a major challenge to animal health, milk production, reproductive performance, and farm profitability. With global milk consumption projected to increase continuously in the coming decades [1], the sustainability of modern dairy production systems has become increasingly dependent on effective metabolic disease management. Ketosis is closely associated with negative energy balance (NEB) during the transition period, when energy demand for lactation exceeds dietary energy intake. This metabolic imbalance can lead to substantial economic losses through reduced milk yield, impaired fertility, increased disease incidence, and elevated culling rates.
Subclinical ketosis (SCK), characterized by the absence of obvious clinical symptoms, is particularly difficult to identify during routine herd management. Previous studies have reported that SCK affects approximately 10–30% of dairy cows during early lactation and is strongly associated with secondary disorders such as mastitis and displaced abomasum [2,3]. In addition, ketosis-related NEB delays ovarian cyclicity recovery, prolongs the calving-to-conception interval, and reduces reproductive efficiency. Recent nutritional intervention studies further confirmed that alleviating metabolic stress can significantly improve reproductive performance, highlighting the close relationship between meta-bolic status and dairy cow productivity [4].
Currently, ketosis diagnosis and metabolic status assessment in dairy cows mainly rely on blood-based biomarkers, particularly β-hydroxybutyric acid (BHBA) [5] and non-esterified fatty acids (NEFAs) [6]. Blood BHBA concentration is widely regarded as the clinical gold standard for ketosis diagnosis because of its high sensitivity and specificity [7]. However, blood sampling is invasive, labor-intensive, and costly, which limits its applicability for large-scale herd-level monitoring and early warning [8]. Consequently, there is growing interest in developing non-invasive and scalable approaches for metabolic risk screening in dairy cows.
With the widespread implementation of Dairy Herd Improvement (DHI) systems, large-scale standardized production and milk composition data have become readily available. DHI records contain abundant physiological and production-related information, including milk yield, milk composition, and derived metabolic indicators, providing valuable data support for precision dairy farming. Previous studies have demonstrated that DHI-derived features and milk-based indicators can serve as effective proxies for detecting metabolic imbalance and assessing ketosis risk [3,9,10].
Among these indicators, the milk fat-to-protein ratio (F/P) has attracted considerable attention as a practical non-invasive proxy for metabolic imbalance [10,11,12]. Clinical and epidemiological studies have demonstrated strong associations between elevated F/P values and increased blood BHBA concentrations during early lactation [8,13]. Specifically, cows with elevated F/P values are more likely to experience NEB and ketosis-related metabolic disturbances [8,13]. In addition, veterinary investigations have shown that F/P can reflect progressive stages of metabolic adaptation and energy imbalance, making it suitable for herd-level metabolic risk stratification [10,11,12]. Systematic reviews further confirmed the reliability of F/P-based screening strategies for identifying cows at risk of elevated BHBA levels during early lactation [14]. Moreover, recent cohort studies suggested that intermediate F/P ranges may capture early metabolic perturbations prior to clinically detectable ketosis, highlighting the potential of F/P for early warning applications [15].
Recent advances in machine learning (ML) have enabled the development of data-driven prediction models for ketosis risk assessment using DHI data. Algorithms such as support vector machines, gradient boosting decision trees, and neural networks have shown promising performance in identifying metabolic abnormalities in dairy cows [16,17].
However, many existing studies primarily formulate ketosis prediction as a binary classification problem based on predefined BHB thresholds, while relatively few studies explore continuous metabolic risk prediction or multi-level risk stratification [18].
Second, the robustness and generalization ability of existing ML models across different farms and production environments remain insufficiently validated [19].
Third, the predictive performance of ML models is highly dependent on hyperparameter optimization, whereas conventional optimization strategies often suffer from limited search efficiency in complex and high-dimensional parameter spaces [20].
Therefore, this study focuses on metabolic risk stratification rather than direct clinical diagnosis of ketosis and aims to develop a non-invasive early warning framework using routinely collected DHI data. To address the limitations of existing approaches, we propose an integrated IWMA–LightGBM framework for early ketosis risk screening. Light Gradient Boosting Machine (LightGBM) is employed as the base learner due to its strong capability in modeling nonlinear relationships and handling large-scale tabular datasets. To further enhance model performance, an Improved Whale Migration Algorithm (IWMA) is applied for LightGBM hyperparameter optimization, improving population diversity and balancing global and local search efficiency.
The proposed framework was evaluated on a longitudinal DHI dataset collected from commercial dairy farms in Gansu Province, China. Comparative experiments were conducted against the original WMA-based model and several commonly used optimization algorithms to assess predictive performance, robustness, and generalization ability.
The main contributions of this study are summarized as follows:
(1)
Development of a novel IWMA for efficient LightGBM hyperparameter optimization, improving the balance between global exploration and local exploitation.
(2)
Proposal of an integrated IWMA–LightGBM framework for non-invasive ketosis risk screening using routinely collected DHI data, providing an effective and scalable solution for herd-level metabolic monitoring.
(3)
Establishment of an interpretable metabolic risk assessment framework through feature importance and confusion matrix analysis, identifying key metabolic indicators associated with ketosis risk and highlighting classification challenges in transitional metabolic states.

2. Materials and Methods

2.1. Overall Framework

As illustrated in Figure 1, a systematic workflow was developed for non-invasive ketosis risk screening based on routinely collected DHI data. The objective of the proposed framework is to predict ketosis risk using milk composition-derived indicators, particularly the F/P, from commercial dairy farms.
Monthly DHI records, including milk yield and milk composition traits, were collected from multiple commercial dairy farms. The raw data were subjected to preprocessing procedures, including missing value handling, data cleaning, and feature normalization. Subsequently, structured feature vectors were constructed for model input.
LightGBM model was developed to perform both F/P regression and ketosis risk classification based on predefined risk thresholds. To improve model performance, IWMA was integrated to optimize key hyperparameters of LightGBM.
The IWMA performs population-based iterative search to identify the optimal hyperparameter configuration, while the LightGBM model is trained and validated within each iteration using the corresponding parameter set. The final optimized model is selected based on validation performance.
The overall framework establishes a data-driven pipeline that integrates preprocessing, feature construction, modeling, and optimization, enabling systematic learning from routinely collected DHI data.

2.2. Dataset Description

2.2.1. Data Source

The dataset used in this study consisted of DHI records collected from multiple commercial dairy farms in Gansu Province, China. A total of 25,155 records from 3593 lactating Holstein cows were collected between January and July 2022.
The DHI data were routinely recorded under standardized herd management procedures and included milk production and milk composition indicators obtained during regular testing intervals. Data collection and management were conducted through the farm DHI recording system to ensure consistency and traceability of production records.
Prior to model development, the raw data underwent standardized preprocessing and quality-control procedures, including missing-value handling, abnormal-value screening, feature consistency checks, and duplicate-record removal. Duplicate entries corresponding to the same cow on the same test day were identified using CowID and test-day information and subsequently eliminated to improve data reliability and consistency.
Outlier detection was conducted using the interquartile range (IQR) method for most continuous variables. For biologically skewed indicators, physiologically plausible ranges were adopted to remove abnormal records. Specifically, the retained ranges were Somatic Cell Count (SCC) < 20 × 104 cells/mL, Somatic Cell Score (SCS) < 4, Precursor Cells < 20 × 104 cells/mL, and Precursor Cell Division < 5 × 104 cells/mL. Milk composition variables were restricted to 2.0–7.0% for Milk Fat, 2.5–5.0% for Milk Protein, and 4.5–5.8% for Lactose.
After data cleaning, 19,737 valid DHI records with 28 candidate features were retained for subsequent analysis. CowID was preserved for dataset partitioning but was not used as an input feature.
The candidate variables included lactation and production traits (Parity, Milk Production, Energy Corrected Milk (ECM), Peak Milk Yield, Peak Day, 305-Day Milk Yield, Total Milk Yield, Adult Equivalent, and Days in Milk (DIM)); milk composition indicators (Milk Fat, Milk Protein, Lactose, Total Solids, Total Milk Fat, and Total Milk Protein); udder health indicators (SCC, SCS, Precursor Cells, and Precursor Cell Division); metabolic indicators (Milk Urea Nitrogen); and production persistence indicators (Lactation Persistence, Herd Within Index (WHI), and Foremilk). Several economic-related variables, including Milk Yield Loss, Milk Payment Differential, Economic Loss, and Foremilk Loss, were initially included as candidate features for subsequent feature selection.
To prevent target leakage during model training, the F/P, which was used for label definition, was excluded from the input feature set.
A detailed description of all variables and calculation procedures is provided in Appendix A.

2.2.2. Label Definition

In this study, milk F/P was used as a non-invasive proxy indicator for metabolic risk stratification in dairy cows. Previous studies have reported that F/P is significantly associated with blood BHBA concentration and can reflect energy balance status in early lactation cows [8,13]. Based on these findings, F/P-derived thresholds were adopted to construct supervised learning labels.
Each DHI record was classified into one of three metabolic risk categories according to predefined criteria:
Healthy: F/P ≤ 1.1.
Subclinical metabolic risk: 1.1 < F/P ≤ 1.4.
High metabolic risk: F/P > 1.4.
These thresholds were applied consistently across the dataset to generate categorical labels for model training and evaluation. The resulting label distribution was used as the ground truth for supervised classification, as illustrated in Figure 2.
It should be noted that the constructed labels represent metabolic risk stratification based on milk composition indicators rather than clinically confirmed ketosis diagnosis. Therefore, the model outputs are intended for early warning and herd-level decision support rather than clinical diagnosis.

2.3. Data Preprocessing

To enhance model robustness and generalization, a systematic preprocessing workflow was applied, including feature selection, class balancing, and data standardization. These steps were designed to mitigate scale disparities, address class imbalance, and reduce redundancy while preserving biologically meaningful variability in the data.

2.3.1. Data Partitioning

To prevent information leakage and ensure realistic model evaluation, data partitioning was performed at the cow level. Cows were randomly assigned to training (Set A, 70%) and testing (Set B, 30%) sets based on unique CowID, ensuring that all records from the same cow were allocated exclusively to one set. Set A was further divided into a training subset (A1, 80%) and a validation subset (A2, 20%) using stratified random sampling to preserve class distribution.
Set A (training + validation): 2496 cows, 13,816 records.
Set B (independent test): 1069 cows, 5921 records.
This cow-level partitioning ensures strict independence between training and testing data, prevents information leakage, and enables fair model comparison.

2.3.2. Feature Selection

Multicollinearity among candidate features was assessed using the Variance Inflation Factor (VIF). Features with VIF >10 were considered highly collinear. Although ECM (VIF = 18.7) and Milk Production (VIF = 17.9) exhibited strong collinearity, both were retained due to distinct biological interpretations: ECM reflects energy-corrected milk yield, whereas Milk Production represents absolute milk yield.
Remaining features showed VIF ≤ 8, indicating no severe multicollinearity. High pairwise correlations (e.g., WHI and ECM, r = 0.89) did not warrant feature removal, as these variables capture complementary physiological aspects. Additionally, LightGBM’s Exclusive Feature Bundling (EFB) reduces redundancy among correlated features, further justifying their inclusion.
A tree-based importance ranking approach was then applied using gain metrics from a preliminary LightGBM classifier trained on Set A1. Features with zero gain-based importance were removed, while all non-zero features were retained to preserve potentially relevant information. Figure 3 presents the feature importance ranking prior to elimination. Notably, economic-related variables (Foremilk Loss, Economic Loss, Milk Payment Differential, Milk Yield Loss) exhibited negligible contribution and were excluded from the final model.

2.3.3. Class Balancing

A pronounced class imbalance was observed among the ketosis categories. To address this issue, three commonly used resampling methods, including random oversampling, Synthetic Minority Oversampling Technique (SMOTE), and Adaptive Synthetic Sampling (ADASYN), were comparatively evaluated on the training subset (A1). Model performance was assessed using macro F1-score, classification accuracy, and training time.
Among the evaluated methods, random oversampling achieved the best overall performance, with a macro F1-score of 0.789, classification accuracy of 0.802, and training time of 12.5 min, outperforming SMOTE (F1 = 0.765, accuracy = 0.778) and ADASYN (F1 = 0.741, accuracy = 0.753). Previous studies have reported that random oversampling may outperform synthetic sampling methods in datasets with limited inter-class feature overlap because it avoids introducing artificial noise while maintaining computational efficiency [21]. SMOTE-based approaches were originally proposed to address minority class imbalance through synthetic sample generation [22].
Therefore, random oversampling was adopted in this study to improve the model’s ability to learn minority-class patterns while preserving the original class distribution of the validation and test sets.
Before oversampling, the class distribution in the training data consisted of 7129 healthy samples (Category 0), 1924 subclinical-risk samples (Category 1), and 2000 high-risk samples (Category 2). After oversampling, all classes were expanded to 8911 samples, resulting in a balanced training dataset. The class distributions before and after balancing are shown in Figure 4.

2.3.4. Data Standardization

To normalize feature scales, min–max normalization was applied to rescale all numerical variables to [0, 1], preserving relative differences while facilitating model convergence. The transformation is defined as shown in Equation (1):
x = x x min x max x min
where x is the original feature value, x min and x max are the minimum and maximum values computed from the training set, and x is the normalized value. The same transformation parameters were applied to the validation and test sets.

2.4. Model Foundations

2.4.1. Light Gradient Boosting Machine (LightGBM)

LightGBM is an efficient implementation of Gradient Boosting Decision Trees (GBDT) proposed by Ke et al. [23]. It builds additive models by sequentially fitting decision trees to minimize a differentiable loss function. LightGBM introduces Gradient-based One-Side Sampling (GOSS), which retains instances with large gradients and down-samples instances with small gradients, and EFB, which combines mutually exclusive features into a lower-dimensional representation to reduce computational cost and memory usage.
In this study, LightGBM was implemented via its official C API and integrated into MATLAB (R2023a) through a dynamic link library (lib_lightgbm.dll). Model training and prediction were executed by the LightGBM engine. The hyperparameters selected for optimization included num_leaves, learning_rate, feature_fraction, bagging_fraction, bagging_freq, min_child_samples, lambda_l1, and lambda_l2. The search ranges of these hyperparameters were determined according to the characteristics of the ketosis DHI dataset (19,737 records with 28 predictive features) and are summarized in Table 1.
The gradient boosting framework of LightGBM inherently captures nonlinear interactions among predictors [23], which is crucial for modeling the complex metabolic relationships in dairy cow ketosis risk prediction. Ke et al. [23] demonstrated that the gradient boosting structure can automatically learn high-order feature interactions without manual feature engineering, a core advantage that distinguishes it from traditional linear models. Therefore, effective hyperparameter optimization is critical for achieving optimal model performance [24].

2.4.2. Whale Migration Algorithm (WMA)

The continuous development of intelligent optimization algorithms is theoretically grounded in the No Free Lunch theorem, which states that no single optimization method can consistently outperform all others across every class of problems [25]. In practical terms, this implies that algorithms demonstrating strong performance in one domain may exhibit limited effectiveness in others. As a result, a wide range of meta-heuristic optimization methods has been actively explored in applications such as feature selection, image segmentation, medical diagnosis, plant disease identification, engineering design, controller tuning, fault diagnosis, and ML hyperparameter optimization.
The WMA is a swarm intelligence-based optimization method inspired by the migratory behavior of humpback whales [26]. The algorithm adopts a leader–follower mechanism to balance global exploration and local exploitation. Leader individuals are responsible for exploring new regions of the search space, whereas follower individuals refine their positions by learning from leaders and high-performing neighboring solutions. This cooperative strategy enhances convergence efficiency while reducing the risk of premature stagnation.
In this study, WMA is employed to optimize the hyperparameters of the LightGBM model. Each candidate solution is encoded as an eight-dimensional vector corresponding to the selected hyperparameters. Model performance, measured through classification or regression objectives, is used as the fitness function. During the optimization process, leader whales perform global exploration using perturbation and boundary-reflection strategies, while follower whales update their positions based on the average positions of leaders and neighboring individuals. Population roles are dynamically updated at each iteration, and a convergence control factor regulates the transition from exploration to exploitation. The algorithm terminates when the maximum number of iterations is reached, yielding the optimal set of LightGBM hyperparameters.

2.5. Proposed Improved Whale Migration Algorithm (IWMA)

Despite its effectiveness in global optimization, the classical WMA still suffers from several limitations when applied to high-dimensional, non-convex, and multi-modal problems, such as LightGBM hyperparameter tuning. Specifically, WMA often exhibits (1) insufficient diversity in population initialization, (2) a tendency to become trapped in local optima during the search process, and (3) an imbalanced trade-off between global exploration and local exploitation.
To address these limitations, this study proposes an IWMA that integrates three complementary strategies: CCM, EOBL, and CGHM. These strategies form a coordinated optimization framework: CCM enhances the diversity and uniformity of the initial population, EOBL expands the search space to escape local optima, and CGHM dynamically balances exploration and exploitation during the iterative search process. Together, these improvements establish a closed-loop optimization mechanism, enabling IWMA to efficiently navigate complex hyperparameter spaces in DHI-based ketosis prediction tasks.

2.5.1. Cubic Chaotic Map (CCM)

To improve initial solution diversity, CCM is incorporated into IWMA for population initialization [27,28,29,30]. CCM leverages the ergodic and pseudo-random properties of chaotic systems to generate uniformly distributed candidate solutions. Compared with conventional random initialization, CCM mitigates premature convergence and enhances global search robustness.
Mechanism: The CCM generates chaotic variables according to nonlinear dynamics, producing initial solutions with broad coverage over the search space. The control parameter a was set to 3.8, which provides maximal ergodicity in the interval (0, 1) [30].
To illustrate the characteristics of CCM, Figure 5 presents the chaotic behavior and spatial distribution generated by the cubic chaotic map. The CCM exhibits strong ergodicity and broad coverage of the search space, which is beneficial for improving the diversity of the initial population.

2.5.2. Elite Opposition-Based Learning (EOBL)

To enhance the algorithm’s ability to escape local optima and accelerate convergence, EOBL is applied. EOBL, derived from Opposition-Based Learning (OBL), evaluates candidate solutions and their corresponding opposite solutions [31,32]. Unlike standard OBL, EOBL selectively applies opposition operations to elite individuals with high fitness values, preserving high-quality solutions while expanding the search space.
This strategy addresses WMA’s vulnerability to premature convergence, improving both exploration and convergence speed. By generating opposite solutions for elite individuals, EOBL expands the effective search region while preserving high-quality candidate solutions, thereby reducing the risk of premature convergence. The mathematical formulation of the elite opposition operation is given in Equation (2):
x i o p p o s i t e = x min + x max x i
where x i denotes the position vector of the i - t h elite individual, x min and x max represent the lower and upper bounds of the respective dimension [33]. If the opposite solution exhibits superior fitness, it replaces the original elite individual in the next generation.

2.5.3. Cauchy-Gaussian Hybrid Mutation (CGHM)

Mutation plays a crucial role in maintaining population diversity. CGHM integrates Cauchy and Gaussian distributions to balance global exploration and local refinement [34,35,36].
Cauchy mutation: Heavy-tailed distribution enables large perturbations, facilitating escape from local optima [35].
Gaussian mutation: Concentrated distribution allows fine-grained local search.
A dynamic probability mixing mechanism regulates mutation behavior across iterations: early iterations emphasize Cauchy for global search, while later iterations favor Gaussian for local exploitation.
Figure 6 illustrates the mutation distribution generated by the CGHM strategy. The hybrid mutation mechanism combines the global exploratory capability of Cauchy perturbation with the local refinement property of Gaussian mutation, enabling adaptive balance between exploration and exploitation.

2.5.4. Improved Algorithm Flow Chart

Based on the three proposed improvement strategies, the overall workflow of IWMA was constructed, as illustrated in Figure 7.

2.5.5. Methodological Advantages of IWMA

By integrating CCM-based initialization, EOBL, and the CGHM strategy, the proposed IWMA is designed to address several inherent limitations of the original WMA framework, including insufficient population diversity, premature convergence, and an imbalanced trade-off between global exploration and local exploitation. These three components operate in a complementary manner to enhance different stages of the optimization process.
Specifically, CCM-based initialization improves the uniformity and ergodicity of the initial population, thereby promoting better coverage of the search space and strengthening global exploration in the early stages. The EOBL mechanism expands the effective search region by leveraging the symmetry of elite individuals, which helps the algorithm escape local optima while maintaining high-quality candidate solutions. Meanwhile, the CGHM strategy introduces a hybrid mutation mechanism that combines the long-tailed exploratory capability of Cauchy perturbations with the fine-grained local refinement of Gaussian mutation, enabling a more balanced exploration–exploitation process.
These design choices are expected to improve convergence behavior, solution quality, and robustness, particularly in high-dimensional, non-convex, and multi-modal optimization problems.
Overall, IWMA provides an enhanced optimization framework compared to conventional WMA, offering a structured improvement in exploration diversity, convergence control, and solution stability. This design forms the methodological basis for its application in subsequent benchmark validation and in optimizing LightGBM hyperparameters for ketosis risk prediction.

2.6. IWMA–LightGBM Framework Construction

An integrated IWMA–LightGBM framework was developed for non-invasive ketosis risk prediction using DHI data. Within this framework, IWMA was employed as a hyperparameter optimization algorithm to automatically search for the optimal configuration of key LightGBM parameters for both classification and regression tasks. The optimization process was guided by predefined fitness functions corresponding to different predictive objectives.

2.6.1. Training and Validation Strategy

To comprehensively assess ketosis risk, both classification and regression tasks were implemented within a unified modeling framework. The classification model serves as a screening tool to identify cows at different metabolic risk levels, while the regression model predicts continuous F/P values to provide a more refined assessment of metabolic status.
The model was trained and evaluated based on the A1 dataset partition described in Section 2.3.1. To ensure fair comparison, all models were implemented under identical experimental settings.
An early stopping mechanism was applied during model training to prevent overfitting. Specifically, training was terminated if the validation performance did not improve for 10 consecutive iterations, with the maximum number of iterations set to 500.
For comparative evaluation, eight models were constructed, including six LightGBM models optimized using representative metaheuristic algorithms, namely Sparrow Search Algorithm (SSA) [37], Dung Beetle Optimizer (DBO) [38], Seagull Optimization Algorithm (SOA) [39], Remora Optimization Algorithm (ROA) [40], Whale Optimization Algorithm (WOA) [36], and Grey Wolf Optimizer (GWO) [41], together with the baseline WMA–LightGBM and the proposed IWMA–LightGBM framework.
All optimization algorithms were implemented using the same dataset partition, search space, stopping criteria, and evaluation procedures to ensure methodological consistency.

2.6.2. Classification Evaluation Metrics

To evaluate classification performance, five commonly used evaluation metrics were adopted, including Accuracy, Precision, Recall, F1-score, and Logarithmic Loss (Log Loss). Their mathematical definitions are presented in Equations (3)–(6):
A c c u r a c y = T P + T N T P + F P + T N + F N
P r e c i s i o n = T P T P + F P
R e c a l l = T P T P + F N
F 1 S c o r e = 1 k k = 1 K 2 × P r e c i s i o n k × R e c a l l k P r e c i s i o n k + R e c a l l k
where TP, TN, FP, and FN denote the numbers of true positives, true negatives, false positives, and false negatives, respectively, and k represents the index of the class.
L o g L o s s = 1 N i = 1 N k = 1 3 y k i · log p k i
in Equation (7), log denotes the natural logarithm (base e). The predicted class probabilities are obtained via the softmax function, as defined in Equation (8).
p k = e z k j = 1 3 e z j
where z k denotes the unnormalized model output (logit) corresponding to class k.
For classification-related metrics (Accuracy, Precision, Recall, and F1-score), higher values indicate superior predictive performance. In contrast, Log Loss reflects the uncertainty of probabilistic predictions, with lower values indicating better model calibration and reliability.
To facilitate intuitive comparison across metrics, a transformed indicator (1 − Log Loss) was additionally reported. However, this transformation was used solely for visualization purposes and does not alter the fundamental interpretation of Log Loss. Therefore, the original Log Loss values remain the primary basis for performance evaluation.
For the classification task, Accuracy was selected as the primary optimization objective and served as the fitness function for hyperparameter optimization.

2.6.3. Regression Evaluation Metrics

To comprehensively assess the predictive performance of the regression models developed for ketosis assessment in dairy cows, several classical regression evaluation metrics were employed, including Mean Squared Error (MSE), Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), and the Coefficient of Determination (R2). Together, these metrics provide a multifaceted evaluation of model accuracy and generalization capability by capturing absolute error magnitudes, penalization of large deviations, proportional relationships, and overall goodness of fit. Their mathematical formulations are given in Equations (9)–(12):
M S E = 1 n i = 1 n y ^ i y i 2
R M S E = 1 n i = 1 n y ^ i y i 2
M A E = 1 n i = 1 n y ^ i y i
R 2 = 1 i = 1 n y ^ i y i 2 i = 1 n y i y ¯ 2
where y ^ i denotes the predicted F/P value and y i is the actual F/P value of the i-th sample.
For the regression task, MSE was adopted as the fitness function due to its sensitivity to large prediction errors. Lower values of MSE, RMSE, and MAE indicate better predictive accuracy, whereas higher R2 values indicate stronger explanatory power.
The combined use of these complementary metrics enables a rigorous and quantitative evaluation of the regression models’ practical utility for early ketosis screening in dairy cows, thereby providing a robust foundation for subsequent model refinement and real-world deployment.

2.7. Experimental Design

The proposed framework was comprehensively evaluated through a series of experiments, including IWMA validation, benchmark evaluation, and baseline model comparisons. Unless otherwise specified, all experiments were conducted on the A2 dataset with a population size (PS) of 30, a maximum iteration (MI) number of 1000, and 30 independent runs to reduce stochastic variability.
Different fitness functions were adopted according to task type: Accuracy for classification and MSE for regression.

2.7.1. Design of Ablation Study

To evaluate the individual and combined contributions of the proposed improvement strategies, including CCM, EOBL, and CGHM, six algorithm variants were implemented:
Single-strategy: WMA + CCM, WMA + EOBL, WMA + CGHM;
Baseline: original WMA;
Combined-strategy: WMA + CCM + EOBL, IWMA (full version).
All variants were executed under identical experimental conditions. The mean MSE and coefficient of variation (CV) were adopted as evaluation indicators to assess optimization accuracy and robustness.

2.7.2. Design of Comparison with Conventional Optimization Methods

To benchmark the optimization capability of IWMA, three widely used hyperparameter optimization methods, including Grid Search (GS), Random Search (RS) [42], and Bayesian Optimization (BO) [43], were selected for comparison under identical experimental conditions.
All methods were implemented under identical experimental settings, including the same hyperparameter search space, objective function, dataset partition, and evaluation metrics. Each algorithm was executed independently 30 times to account for stochastic variability.

2.7.3. Design of Sensitivity Analysis

A single-factor sensitivity analysis was conducted to evaluate the robustness of key IWMA parameters, including PS, MI, and CCM parameter a. The parameter settings were defined as follows:
P S 10 ,   20 ,   30 ,   40 ,   50
M I 500 ,   800 ,   1000 ,   1200 ,   2000
a 3.5 ,   3.6 ,   3.7 ,   3.8 ,   3.9 ,   4.0
Evaluation indicators included mean MSE and the CV of MSE, with CV < 10% considered strong robustness. The optimal parameter value was defined as that corresponding to the minimum MSE, and the robust range was defined as the interval where MSE variation was less than 5% and CV remained below 10%.

2.7.4. Design of CEC2022 Benchmark Experiments

To further evaluate the optimization performance of IWMA, experiments were conducted on the CEC2022 benchmark suite. The suite consists of 20-dimensional test functions characterized by high dimensionality, strong nonlinearity, and multimodality. Key function characteristics are summarized in Appendix A.
The proposed IWMA was benchmarked against seven widely used swarm intelligence algorithms: SSA, DBO, SOA, ROA, WOA, GWO, and the original WMA.
All algorithms were executed under identical experimental conditions: PS = 30, MI = 1000, and 30 independent runs per benchmark function. The evaluation metrics included best fitness, mean fitness, and convergence iterations.

2.7.5. Design of Baseline Model Comparison

To validate the effectiveness and generalization capability of the proposed framework, five representative machine learning models were selected as baseline learners, including LightGBM, XGBoost [44], CatBoost [45], Random Forest (RF) [46], and Multilayer Perceptron (MLP) [47].
To ensure a fair and controlled comparison, all models were optimized using the same IWMA-based hyperparameter optimization framework. Specifically, IWMA was employed as a unified search strategy to tune the hyperparameters of each model un-der identical optimization conditions, including the same PS = 30, maximum iteration number (MI = 1000), search space definition, and fitness evaluation function.
Each model was trained and evaluated under two configurations:
(1)
default parameter settings without optimization;
(2)
IWMA-optimized parameter settings obtained using the same optimization budget.
All stochastic experiments were repeated 30 independent runs to reduce randomness, and the mean performance and standard deviation were reported.
Model evaluation was conducted on the A2 validation subset under a strict data partitioning strategy to prevent information leakage.
Evaluation metrics were classified into three categories:
Classification performance: Accuracy and F1-score;
Regression performance: MSE and R2;
Computational efficiency: Average training time (seconds).
All experiments were conducted under identical hardware and software environments to ensure reproducibility and comparability.

3. Results and Discussion

3.1. Validation of IWMA Optimization Performance

3.1.1. Ablation Study

As shown in Table 2, all single-strategy variants outperform the original WMA. CGHM is identified as the core independent improvement strategy (MSE = 0.337, 3.71% reduction; convergence = 850), followed by CCM (MSE reduction = 2.29%, convergence = 870). EOBL provides a limited independent contribution (MSE reduction = 1.14%, convergence = 890).
The combined-strategy variants show progressive performance improvement: WMA + CCM + EOBL achieves a 12.00% MSE reduction, and the full IWMA attains the best performance (MSE = 0.299, 14.57% reduction; convergence = 750 iterations).
These results verify the strong synergistic effect of the three strategies:
CCM optimizes the initial population;
EOBL expands the search space;
CGHM balances global exploration and local exploitation.
Overall, the progressive improvement from Variant 1 to Variant 6 confirms that the three proposed strategies contribute complementarily to the optimization process.

3.1.2. Comparison with Conventional Optimization Methods

Table 3 summarizes the quantitative comparison results.
IWMA achieved the lowest MSE (0.321 ± 0.009), outperforming GS, RS, and BO. In addition, IWMA converged within fewer iterations while maintaining comparable computational cost to BO.
These results indicate that IWMA provides a superior balance between optimization accuracy and convergence efficiency.

3.1.3. Sensitivity Analysis

As shown in Figure 8, the PS significantly affected optimization performance. The minimum MSE (0.299) was achieved at PS = 30 with a CV of 8.5%, indicating stable convergence behavior. When PS < 20, insufficient population diversity reduced global exploration capability and increased performance variability (CV > 10%). In contrast, PS > 40 increased computational cost without notable accuracy improvement. Similarly, the maximum iteration number (MI) influenced convergence stability. The model achieved stable convergence when MI ≥ 1000, whereas smaller MI values resulted in incomplete convergence and higher MSE values. For the CCM parameter a, the optimal performance was observed around a = 3.8, where the chaotic mapping exhibited favorable ergodicity and population diversity.
The analysis verified that the empirical parameters are the optimal values for the ketosis DHI dataset, and the model has strong robustness within the robust ranges. For practical deployment, parameters can be adjusted within the robust range according to computational resources (e.g., PS = 20 for low-resource devices).

3.1.4. CEC2022 Benchmark Evaluation

Box plot visualizations (Figure 9 and Figure 10) were employed to analyze the solution distributions, robustness, and consistency of the compared algorithms.
(1)
Global Optimality: IWMA consistently achieved lower medians, smaller minimum values, and narrower lower quartiles for functions F1, F2, F5, F6, and F9–F11, indicating close proximity to the global optima. In contrast, SOA and ROA exhibited wider dispersion, while DBO produced multiple outliers, reflecting unstable convergence behavior.
(2)
Stability and Robustness: For functions F3, F4, F7, F8, and F12, IWMA demonstrated compact box plots with tight interquartile ranges and few outliers, confirming high stability and low sensitivity to population initialization. By comparison, the other algorithms showed broader interquartile ranges or premature stagnation, highlighting the superior robustness of IWMA across diverse search landscapes.
(3)
Exploration–Exploitation Balance: On multimodal functions (F1, F5, and F10), IWMA maintained controlled dispersion, suggesting effective global exploration. Conversely, for unimodal functions (F4, F8, and F11), the algorithm exhibited compact distributions, reflecting efficient local exploitation and rapid convergence.
(4)
Prevention of Premature Convergence: WOA and GWO showed tendencies toward early convergence, whereas IWMA preserved population diversity during the early iterations and gradually stabilized over time. This behavior resulted in lower median values and fewer extreme solutions, demonstrating the effectiveness of IWMA’s adaptive perturbation mechanisms.
Overall, across all twelve benchmark functions, IWMA generally outperformed the comparative algorithms in terms of optimization accuracy, convergence behavior, robustness, and solution consistency, confirming its strong suitability for large-scale, nonlinear, and high-dimensional optimization problems.
The benchmark experiments conducted on the CEC2022 test suite comprehensively demonstrate the superior optimization capability, convergence stability, and robustness of the proposed IWMA when addressing high-dimensional, nonlinear, and multi-modal optimization tasks. These characteristics are particularly critical for hyperparameter optimization in advanced ML models, where the search landscape is often complex, discontinuous, and highly sensitive to parameter interactions.
Building upon these validated advantages, IWMA is further integrated with LightGBM to construct an IWMA–LightGBM predictive framework for non-invasive ketosis monitoring in dairy cows. In this framework, IWMA is employed to optimize key LightGBM hyperparameters automatically, thereby enhancing predictive accuracy, generalization capability, and training stability when applied to real-world DHI data.
Subsequent experiments focus on evaluating the performance of the proposed IWMA–LightGBM model under practical dairy farming conditions. Specifically, both classification and regression tasks are conducted to assess early ketosis detection and continuous metabolic risk prediction at the herd level. Comparative analyses against baseline models and alternative optimization strategies are further performed to verify the effectiveness and practical applicability of the proposed framework in precision dairy management.

3.2. Baseline Model Comparison

Table 4 presents the performance comparison of five baseline machine learning models under both default and IWMA-optimized configurations.
Overall, all models show performance improvements after IWMA-based optimization, indicating that the proposed optimization strategy is effective in enhancing model learning capability. However, the magnitude of improvement varies across different models.
Among all evaluated models, LightGBM achieves the best overall performance in both classification and regression tasks. Under IWMA optimization, it obtains the highest Accuracy (0.8625) and F1-score (0.8358), as well as the lowest MSE (0.3182) and highest R2 (0.4795), demonstrating superior predictive capability for ketosis risk assessment.
Compared with default settings, LightGBM exhibits the most significant performance improvement, particularly in error reduction and classification accuracy. XGBoost and CatBoost also benefit from IWMA optimization but with relatively smaller gains. RF and MLP show limited improvements compared to tree-based boosting models.
From the perspective of computational efficiency, LightGBM maintains a favorable balance between accuracy and training time (102.5 ± 5.8 s), outperforming XGBoost and MLP in efficiency, while achieving higher predictive accuracy. RF demonstrates faster training speed but lower predictive performance.
These results indicate that IWMA optimization consistently improves model performance across different algorithms, and LightGBM achieves the best overall trade-off between accuracy and efficiency under the proposed framework.

3.3. Performance Evaluation of IWMA–LightGBM

The performance of the proposed IWMA–LightGBM framework was evaluated using both classification and regression tasks for F/P-based ketosis risk in dairy cows. Eight optimization algorithms integrated with LightGBM were compared under identical experimental conditions, and results for the held-out test set are summarized in Table 5.

3.3.1. Classification Performance

As illustrated in Figure 11 and Table 5, IWMA–LightGBM consistently outperformed all comparative models across all evaluation metrics. Specifically, the model achieved the highest Accuracy (0.8997), Precision (0.8569), Recall (0.8959), and F1-score (0.8749), substantially exceeding conventional WMA–LightGBM (Accuracy = 0.8499) and other optimization-based frameworks such as SSA–LightGBM (0.6404) and DBO–LightGBM (0.6659). The improved 1−Log Loss (0.7148) further indicates lower prediction uncertainty and more reliable probability estimates.
The superior classification results reflect the effective balance between global exploration and local exploitation achieved by IWMA during hyperparameter optimization. These findings are consistent with the ablation study (Section 3.1.1), where the CGHM strategy contributed most to performance improvement, reducing MSE by 3.71%. Moreover, LightGBM’s inherent adaptability to complex, high-dimensional DHI data contributed to robust classification across metabolic risk categories [48].
Although this study relied on F/P ratios as a proxy for ketosis risk rather than direct biochemical measurements (e.g., BHBA or NEFA), the classification outcomes have meaningful implications for herd management. For instance, high-risk cows identified by the model could be prioritized for nutritional intervention or monitoring, potentially reducing the incidence of clinical ketosis and associated production losses. Conversely, healthy cows could avoid unnecessary interventions, improving overall herd management efficiency.
The ability of the model to differentiate among F/P-defined metabolic risk categories indicates that these biologically meaningful production traits collectively reflect underlying metabolic variation relevant to changes in ketosis risk, rather than confirmed clinical status.
To further examine class-specific prediction behavior, a detailed confusion matrix analysis is presented in the following subsection.

3.3.2. Confusion Matrix Analysis

Figure 12 presents the confusion matrix of the proposed IWMA–LightGBM model for multi-class ketosis risk classification.
Overall, the model demonstrates strong classification performance for clearly defined metabolic states. Category 0 (healthy cows) achieves the highest number of correct predictions (2553 samples), while Category 2 (high-risk cows) also maintains relatively stable recognition performance with 172 correctly classified samples.
In contrast, Category 1 (subclinical-risk cows) exhibits the highest misclassification rate, with a substantial proportion of samples incorrectly assigned to Category 0. This phenomenon suggests that subclinical ketosis represents an intrinsically ambiguous transitional metabolic state located near the decision boundaries between healthy and high-risk conditions [49].
From a biological perspective, the F/P interval corresponding to the subclinical group (1.1–1.4) is relatively narrow and associated with only mild physiological deviations. Consequently, the feature distributions of subclinical samples substantially overlap with adjacent categories, reducing class separability in the feature space.
From a data distribution perspective, the subclinical group contains fewer samples and exhibits higher intra-class variability compared with the healthy group, further weakening feature compactness and increasing classification uncertainty.
From a model-learning perspective, LightGBM primarily optimizes global loss reduction and therefore tends to favor classes with stronger statistical signals. As a result, samples located near decision boundaries are more likely to be assigned to neighboring categories despite the use of oversampling strategies.
In addition, the current framework mainly relies on cross-sectional DHI-derived indicators collected at single recording time points, which may not fully capture the dynamic progression characteristics of subclinical ketosis. This limitation further constrains the model’s ability to identify subtle metabolic deviations during early-stage conditions.
Future improvements may include incorporating temporal metabolic features, additional physiological biomarkers, and cost-sensitive learning strategies to further improve recognition performance for transitional metabolic states.
Overall, the confusion matrix analysis indicates that the proposed model performs reliably for distinct metabolic conditions while highlighting the intrinsic difficulty of distinguishing subclinical ketosis.

3.3.3. Regression Performance

Regression modeling of ketosis-related indicators is inherently more challenging than categorical classification because it requires capturing continuous variations in metabolic status rather than discrete disease states.
Table 5 and Figure 13 summarize the regression performance of eight optimization algorithms integrated with the LightGBM model for predicting the F/P, a proxy indicator of ketosis risk. Among all models, the IWMA–LightGBM framework consistently achieves the best performance, attaining the lowest MSE of 0.289 and the highest R2 of 0.5242, demonstrating superior predictive accuracy and explanatory power. This outstanding performance benefits from two complementary factors: (1) precise hyperparameter optimization by IWMA, as verified in the ablation experiments in Section 3.1.1, and (2) the strong adaptability of LightGBM to the complex, high-dimensional DHI dataset, validated in Section 3.2. The alignment between algorithmic improvements and feature adaptation confirms that the IWMA–LightGBM framework effectively integrates model optimization and data characteristics, enabling accurate continuous prediction of ketosis-related indicators.
In addition, IWMA–LightGBM attains the highest coefficient of determination (R2 = 0.5242), reflecting a better goodness of fit and stronger explanatory capability. As illustrated in Figure 13, the proposed model maintains a consistent advantage across all evaluation metrics, further supporting its effectiveness for regression-based prediction of the F/P, a proxy indicator of ketosis risk in dairy cows.
Beyond numerical accuracy, the improved regression performance of the IWMA–LightGBM model suggests that the selected feature set effectively captures physiologically meaningful patterns associated with metabolic changes reflected in the F/P. Metabolic imbalance during early and mid-lactation, particularly NEB and altered nutrient partitioning, is a primary driver of elevated F/P [50]. The model’s ability to achieve lower prediction errors and higher explanatory power indicates enhanced sensitivity to variations in production load, lactation dynamics, and metabolic stress, rather than purely statistical optimization. Therefore, the observed regression improvements may reflect improved alignment between model predictions and underlying dairy cow metabolic physiology as captured by the F/P proxy.

3.3.4. Feature Importance and Biological Interpretation

Figure 14 presents the permutation-based feature importance ranking of the IWMA–LightGBM regression model. Among all predictors, WHI, ECM, and DIM emerge as the dominant variables, jointly forming a physiologically coherent framework that characterizes metabolic load, production demand, and temporal adaptation during lactation. The linear relationships between these key features and the target variable F/P are further illustrated in the Pearson correlation heatmap (Figure 15), providing statistical support for the subsequent mechanistic interpretation.
A central physiological mechanism linking key features to ketosis risk is NEB, which is most prevalent during early lactation (DIM < 60 days) [51]. When energy demand for milk production (reflected by ECM) exceeds dietary intake, cows mobilize body fat reserves, leading to elevated circulating NEFA. Incomplete oxidation of NEFA in the liver produces ketone bodies (e.g., BHBA), which promotes milk fat synthesis while inhibiting protein synthesis—contributing to elevated F/P values (the proxy indicator for ketosis risk). For key features: WHI reflects individual production intensity relative to the herd, ECM quantifies energy-corrected milk yield, and DIM captures lactation stage dynamics—their synergistic effect (e.g., ‘high WHI + high ECM + low DIM’) exacerbates NEB, making cows more susceptible to ketosis. This mechanism may explain why these three features rank top in permutation importance (Figure 14) and why their nonlinear interactions are critical for model performance.
From a mechanistic perspective, ECM, DIM, and WHI can be interpreted as complementary indicators capturing different aspects of this NEB-driven metabolic process. ECM reflects energy-corrected milk yield and thus represents production-driven energy demand. Elevated ECM indicates increased glucose requirements for lactose synthesis and intensified metabolic burden; when this demand exceeds energy intake, it exacerbates NEB and promotes lipid mobilization and ketogenesis. DIM captures the temporal dynamics of lactation and serves as a proxy for the progression of metabolic adaptation. During early lactation (typically within 30–60 DIM), dry matter intake lags behind energy demand, making cows particularly susceptible to NEB and subsequent metabolic disorders. WHI represents the relative production intensity of an individual cow within the herd. Elevated WHI values indicate that a cow is producing above the herd average, implying a disproportionately high metabolic load; under early lactation conditions, this can further aggravate NEB, thereby increasing the risk of excessive lipid mobilization and ketone body accumulation.
As shown in Figure 15, ECM and WHI exhibit a strong positive correlation (r = 0.89), indicating consistent metabolic pressure between individual production level and herd-standardized performance. In contrast, DIM shows weak correlations with ECM (r = 0.29) and WHI (r = 0.11), confirming its role as an independent temporal regulator. All three variables are significantly associated with F/P: ECM and WHI are positively correlated with F/P (r = 0.47 and r = 0.42, respectively), whereas DIM shows a weak negative correlation (r = −0.24). These patterns are consistent with the physiological mechanism of early lactation, in which high production demand and insufficient energy intake jointly drive elevated F/P.
Importantly, these variables do not act independently but exhibit coordinated and potentially non-additive effects. For example, elevated ECM during early lactation (low DIM) may result in a more severe energy deficit than similar production levels observed at later stages, highlighting the temporal modulation of metabolic stress. Similarly, the effect of WHI may depend on DIM, as cows with high relative production intensity in early lactation are more vulnerable to sustained NEB. These interaction patterns reflect the biological reality that ketosis arises from the combined effects of production pressure, temporal imbalance, and systemic metabolic load, rather than from isolated factors.
A second tier of predictors, including Total Milk Fat, Milk Urea Nitrogen, and Peak Day, provides additional physiological insights. Total Milk Fat likely reflects the extent of body fat mobilization under energy-deficient conditions, as increased milk fat content is associated with enhanced lipolysis and ketone body formation. Milk Urea Nitrogen may indicate imbalances in rumen nitrogen utilization and protein-to-energy ratios, which can impair hepatic gluconeogenesis and further exacerbate energy deficits. Peak Day reflects lactation curve dynamics and may capture deviations in production timing associated with prolonged metabolic stress.
In contrast, variables such as Precursor Cells and Lactose contribute minimally to model performance, suggesting that compositional or cellular characteristics of milk play a secondary role compared with systemic metabolic and production-related factors. This finding further supports the notion that ketosis risk is primarily driven by integrated metabolic load rather than isolated compositional changes.
Although the present analysis focuses on individual feature importance, it should be noted that the gradient boosting framework inherently captures nonlinear interactions among predictors. Therefore, the importance of WHI, ECM, and DIM likely reflects both their individual effects and their joint contributions within a high-dimensional interaction space. Future studies incorporating explicit interaction modeling and visualization may further enhance mechanistic interpretability.
These findings suggest that the IWMA–LightGBM model can effectively integrate production intensity, temporal dynamics, and metabolic context for F/P-based metabolic risk prediction. This mechanism-oriented interpretation aligns with the established pathophysiology of ketosis, in which NEB-induced lipid mobilization and hepatic ketogenesis serve as central drivers of metabolic imbalance. These observations further indicate that the proposed framework may capture biologically relevant patterns associated with ketosis-related metabolic variation.

3.3.5. Clinical and Practical Implications

Although this study employed milk F/P as a proxy indicator rather than direct biochemical measurements such as BHBA, the IWMA–LightGBM framework demonstrated strong capability for identifying metabolic risk patterns associated with ketosis [14]. Compared with conventional blood-based examinations, this DHI-based approach provides a non-invasive, low-cost, and easily scalable solution for herd-level metabolic risk screening.
Early identification of high-risk cows may facilitate timely nutritional adjustment, monitoring, and targeted intervention, potentially reducing the incidence of clinical ketosis, maintaining lactation performance, and improving animal welfare. Additionally, the framework may offer economic benefits by decreasing labor, diagnostic costs, and losses associated with milk production, reproduction, and veterinary care.
Limitations include reliance on cross-sectional monthly DHI indicators and F/P-based risk labels rather than clinically confirmed ketosis diagnosis. Future studies integrating longitudinal metabolic records and direct biochemical biomarkers are expected to enhance clinical interpretability and generalization of the framework.

4. Conclusions

This study proposes a non-invasive IWMA–LightGBM framework for early ketosis risk screening in dairy cows using routinely collected DHI data. By utilizing the milk F/P ratio as a biologically relevant proxy indicator of metabolic imbalance during early lactation, the proposed framework enables herd-level metabolic risk stratification without relying on invasive blood sampling or laboratory-based biochemical testing.
Experimental results demonstrate that the framework achieves strong and consistent performance in both classification and regression tasks, effectively discriminating among healthy, subclinical-risk, and high-risk metabolic states. Compared with baseline models, the IWMA–LightGBM framework exhibits superior predictive accuracy, stability, and robustness in hyperparameter optimization, confirming the effectiveness of the proposed optimization strategy.
Importantly, the proposed framework is intended for herd-level early warning and management support rather than direct clinical diagnosis of ketosis. The results suggest that routinely collected DHI data can provide meaningful insights into metabolic risk patterns and may support timely nutritional intervention, monitoring, and precision dairy management under practical farming conditions.
Nevertheless, several limitations should be acknowledged. The current framework relies on cross-sectional DHI indicators and F/P-based risk labels rather than clinically confirmed biochemical measurements such as blood BHBA or NEFA. In addition, the model does not incorporate longitudinal metabolic trajectories, which may limit sensitivity to subtle transitional states.
Future work will focus on integrating longitudinal time-series features, clinical metabolic biomarkers, and enhanced explainability strategies to further improve generalization capability, biological interpretability, and practical deployment in real-world dairy farming systems.
Overall, the proposed IWMA–LightGBM framework provides a reliable, scalable, and cost-effective approach for non-invasive metabolic risk screening, offering potential support for precision herd management and proactive disease prevention strategies.

Author Contributions

Conceptualization, Y.Y.; methodology, Y.Y. and H.L.; software, Y.Y. and H.L.; validation, Y.D. and R.G.; formal analysis, Y.Y. and H.L.; investigation, Y.Y. resources, Y.D.; data curation, Y.Y. and Y.D.; writing—original draft preparation, Y.Y.; writing—review and editing, Y.Y., H.L. and Y.D.; visualization, Y.Y.; supervision, H.L., Y.D. and R.G.; project administration, Y.D. and H.L.; funding acquisition, Y.D. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by the Natural Science Foundation of Gansu Province grant number [25JRRA355]; Innovation Fund for Higher Education of Gansu Province grant number [2022B-107]; Basic Research Innovation Group grant number [21JR7RA858]; Gansu Agricultural University Young Mentor Fund “Research on Machine Learning Prediction Model of Cow Ketosis Driven by Intelligent Optimization Algorithm” grant number [GAU-QDFC-2025-09], 2025–2028; and Gansu Provincial Natural Science Foundation “Research on Machine Learning Prediction Model of Cow Recessive Mastitis” grant number [25JRRA355], 2025–2028.

Institutional Review Board Statement

Ethical review and approval were waived for this study because the research used only existing, anonymized Dairy Herd Improvement (DHI) data provided by a company. No live animals were directly handled, and no new data collection or experimental procedures involving animals were conducted. All analyses were performed on de-identified data, ensuring confidentiality and compliance with standard data protection practices.

Data Availability Statement

The data analyzed in this study is subject to the following licenses/restrictions: confidentiality: the data contains sensitive information that is not to be shared publicly due to privacy concerns related to the dairy farm operations and the individual cows’ performance metrics. Limited access: access to the dataset is restricted to the research team and authorized personnel only. Requests to access these datasets should be directed to dyq@gsau.edu.cn.

Conflicts of Interest

The authors declare no conflicts of interest.

Appendix A

The various indicators in the DHI report are obtained through testing, statistical analysis, and calculation based on the physiological characteristics and biological model data of the tested dairy cows. Proper and accurate analysis of DHI data is key to addressing the cows’ physiological issues as well as management problems on the dairy farm. The DHI testing indicators and their interpretation and application are as follows.
Parity: Number of completed calvings of the cow at the time of recording.
Days in Milk (DIM): The number of days since a cow has calved and started lactation.
Milk Production (kg): Daily milk production recorded at the test day.
Milk Fat (%): Percentage of fat content in milk.
Milk Protein (%): Percentage of protein content in milk.
Somatic Cell Count (SCC) (×104 cells/mL): Number of somatic cells per milliliter of milk, indicating udder health status.
Somatic Cell Score (SCS): Log-transformed SCC value used to normalize distribution and improve statistical modeling.
Milk Urea Nitrogen (MUN) (mg/dL): Concentration of urea nitrogen in milk, reflecting protein metabolism and dietary nitrogen balance.
Milk Yield Loss (kg): Difference between observed milk yield and expected production based on reference standards or lactation stage.
Milk Payment Differential: The price premium applied to the base milk price based on milk composition and quality parameters, including fat %, protein %, and somatic cell count. Values of zero indicate no premium.
Economic Loss: Calculated financial loss associated with reduced production or quality penalties.
Energy Corrected Milk (ECM) (kg): It is a standard parameter for calculating feeding efficiency. The fat and protein in energy-corrected milk are both adjusted, allowing for a comparison of milk production differences between different breeds and individual cows. Although there are differences between the values of energy-corrected milk and uncorrected milk, both are meaningful. The correction formula for energy-corrected milk is as follows: ECM = (12.82 × kilograms of milk fat) + (7.13 × kilograms of milk protein) + (0.323 × kilograms of milk).
Lactation Persistence: An indicator reflecting the rate of decline in milk yield after peak production, representing the stability of lactation performance over time.
WHI: The Herd Within Index (WHI) is calculated by dividing an individual cow’s adjusted milk yield by the herd’s average adjusted milk yield. WHI is a relative value, with a normal range of 90–110. The WHI value indicates the cow’s relative performance within the herd. The WHI was constructed as a weighted linear combination of standardized production- and health-related variables: W H I = w i Z i , where Z i denotes standardized variables and w i represents corresponding weights. The F/P ratio was not included to avoid target leakage.
Foremilk (kg): Milk obtained at the start of milking, representing the initial milk fraction.
Precursor Cells (Cells × 104 cells/mL): Number of immature (precursor) cells in milk per mL, expressed in 104 cells/mL.
Precursor Cell Division: Number of dividing precursor cells in milk per mL, expressed in 104 cells/mL.
Foremilk Loss (kg): Milk volume lost at the start of milking (foremilk), measured in kilograms.
Peak Milk Yield (kg): It refers to the milk yield on the peak lactation day.
Peak Day (day): Refers to the number of days in milk at which the highest milk yield occurs during the current lactation of a dairy cow, measured in days. For Holstein cows, the peak day typically occurs 60 to 90 days after calving.
305-Day Milk Yield (kg): Also known as the 305-day expected milk yield, this indicator represents the projected 305-day milk yield when the lactation period is less than 305 days; when the lactation period reaches or exceeds 305 days, it represents the actual 305-day milk yield. The 305-day milk yield for dairy cows refers to the total milk production from the 5th day after calving up to the 305th day.
Total Milk Yield (kg): Refers to the total milk yield of the cow from the day of calving up to the date of the current measurement. For cows that have completed lactation for a given parity, this represents the milk production for that parity.
Total Milk Fat (%): Refers to the milk fat content of the cow from the day of calving to the date of this measurement.
Total Milk Protein (%): Refers to the milk protein content of the cow from the day of calving to the date of this measurement.
Adult Equivalent (kg): A standardized milk yield measure that adjusts the observed production of a cow to the equivalent yield of a mature cow. This metric accounts for differences in lactation stage, parity, and age, allowing fair comparison of milk production across cows at different physiological stages. AE is calculated by applying adjustment factors to the observed milk yield, converting it to a value that represents what the cow would produce if it were a mature adult under standard lactation conditions.
Lactose: representing the relative level of lactose present in milk.
Total Solids: representing the combined content of milk fat, protein, lactose, and other solid components in the milk sample.
Table A1. Features description.
Table A1. Features description.
VariableMinMedianMax
Parity115
Days in Milk (DIM) 53165339
Milk Production (kg)929.249.3
Milk Fat (%)2.324.646.91
Milk Protein (%)2.743.784.82
Somatic Cell Count (SCC) (×104 cells/mL)0424
Somatic Cell Score (SCS)026
Milk Urea Nitrogen (mg/dL)4.813.322.2
Milk Yield Loss (kg)000
Milk Payment Differential000
Economic Loss000
Energy Corrected Milk (ECM) (kg)15.237.760
Lactation Persistence75.797.5119.2
WHI44.2103.9162.5
Foremilk (kg)10.129.649.3
Precursor Cells (Cells × 104 cells/mL)0422
Precursor Cell Division026
Foremilk Loss (kg)000
Peak Milk Yield (kg)17.933.449.4
Peak Day (day)685213
305-Day Milk Yield (kg)3745783212,144
Total Milk Yield (kg)322475810,105
Total Milk Fat (%)0.122.194.63
Total Milk Protein (%)0.111.773.78
Adult Equivalent (kg)4089899013,865
Lactose4.95.35.7
Total Solids1215.719.5
Table A2. CEC2022 benchmark functions information.
Table A2. CEC2022 benchmark functions information.
No.Function F min
Unimodal Functions1Shifted and full Rotated Zakharov Function300
Basic Functions2Shifted and full Rotated Rosenbrock’s Function400
3Shifted and full Rotated Expanded Schaffer’s f 6 Function600
4Shifted and full Rotated Non-Continuous Rastrigin’s Function800
5Shifted and full Rotated Levy Function900
Hybrid
Functions
6Hybrid Function 1 (N = 3)1800
7Hybrid Function 2 (N = 6)2000
8Hybrid Function 3 (N = 5)2200
Composition
Functions
9Composition Function 1 (N = 5)2300
10Composition Function 2 (N = 4)2400
11Composition Function 3 (N = 5)2600
12Composition Function 4 (N = 6)2700
The search range for all functions was set to [−100, 100]^D.

References

  1. OECD/FAO. OECD-FAO Agricultural Outlook 2022–2031; OECD Publishing: Paris, France, 2022. [Google Scholar] [CrossRef]
  2. He, K.B. Establishment and application effect of monitoring, warning and early prevention and control technology system of cow ketosis based on DHI. Anim. Breed. Feed. 2021, 20, 83–86. [Google Scholar] [CrossRef]
  3. Wang, K.; Zhao, X.X.; Zhang, Y.P.; Xue, G.H.; Liu, Y.; Bao, P.; Xu, Q.W.; Li, J.B.; Jiang, L. Research Progress on Based on Mid-infrared Spectroscopy for Monitoring Ketosis in Dairy Cows. Chin. J. Anim. Sci. 2023, 59, 87–92. [Google Scholar] [CrossRef]
  4. Giurgiu, O.V.; Berean, D.I.; Ionescu, A.; Ciupe, M.S.; Cimpean, C.R.; Radu, C.I.; Bitica, D.G.; Bogdan, S.; Bogdan, M.L. The effect of oral administration of zeolite on the energy metabolism and reproductive health of Romanian spotted breed in advanced gestation and post partum period. Vet. Anim. Sci. 2024, 23, 100333. [Google Scholar] [CrossRef]
  5. Iwersen, M.; Falkenberg, U.; Voigtsberger, R.; Forderung, D.; Heuwieser, W. Evaluation of an electronic cowside test to detect subclinical ketosis in dairy cows. J. Dairy Sci. 2009, 92, 2618–2624. [Google Scholar] [CrossRef]
  6. Mondal, M.; Suan, T.K.; Gore, P.L.; Khandelwal, L.; Sharma, R.; Karunakaran, M.; Youssef, H.S.M.; Chakraborty, S.; Akourki, A. Endocrine–metabolic regulation during the transition period in dairy cows: Mechanisms, biomarkers, and emerging diagnostics for subclinical ketosis. Front. Endocrinol. 2026, 17, 1799702. [Google Scholar] [CrossRef]
  7. Gulinski, P. Ketone bodies—Causes and effects of their increased presence in cows’ body fluids: A review. Vet. World 2021, 14, 1492–1503. [Google Scholar] [CrossRef]
  8. Duffield, T.F.; Kelton, D.F.; Leslie, K.E.; Lissemore, K.D.; Lumsden, J.H. Use of test day milk fat and milk protein to detect subclinical ketosis in dairy cattle in Ontario. Can. Vet. J. 1997, 38, 713–718. [Google Scholar]
  9. Chandler, T.L.; Pralle, R.S.; Dórea, J.R.R.; Poock, S.E.; Oetzel, G.R.; Fourdraine, R.H.; White, H.M. Predicting hyperketonemia by logistic and linear regression using test-day milk and performance variables in early-lactation Holstein and Jersey cows. J. Dairy Sci. 2018, 101, 2476–2491. [Google Scholar] [CrossRef]
  10. Guliński, P.; Socha, S. The relationship between milk fat to protein ratio and selected production traits of Polish Holstein-Friesian cows. Anim. Sci. Pap. Rep. 2021, 39, 213–223. [Google Scholar]
  11. Du, Z.L.; Luo, Z.Z.; Zhou, T.; Cao, S.Z.; Yan, Z.T. Research Progress on Early Warning Technology of Cow with Ketosis. Chin. J. Anim. Sci. 2024, 60, 31–35. [Google Scholar] [CrossRef]
  12. Krogh, M.A.; Toft, N.; Enevoldsen, C. Latent class evaluation of a milk test, a urine test, and the fat-to-protein percentage ratio in milk to diagnose ketosis in dairy cows. J. Dairy Sci. 2011, 94, 2360–2367. [Google Scholar] [CrossRef]
  13. Heuer, C.; Schukken, Y.H.; Dobbelaar, P. Postpartum body condition score and results from the first test day milk as predictors of disease, fertility, yield, and culling in commercial dairy herds. J. Dairy Sci. 1999, 82, 295–304. [Google Scholar] [CrossRef]
  14. Stancheva, E.; Penev, T. Critical Analysis of Protocols for Good Veterinary Practices in Monitoring, Prevention and Treatment of Ketosis in Dairy Cows. Vet. Sci. 2025, 12, 1019. [Google Scholar] [CrossRef]
  15. Kong, F.; Wang, S.; Zhang, Y.; Li, C.; Dai, D.; Guo, C.; Wang, Y.; Cao, Z.; Yang, H.; Bi, Y.; et al. Rumen microbiome associates with postpartum ketosis development in dairy cows: A prospective nested case-control study. Microbiome 2025, 13, 69. [Google Scholar] [CrossRef]
  16. Bauer, E.A.; Jagusiak, W. Prediction of ketosis using radial basis function neural network in dairy cattle farming. Prev. Vet. Med. 2025, 235, 106410. [Google Scholar] [CrossRef]
  17. Ushikubo, S.; Kubota, C.; Ohwada, H. The Early Detection of Subclinical Ketosis in Dairy Cows Using Machine Learning Methods. In Proceedings of the 9th International Conference on Machine Learning and Computing; ACM: New York, NY, USA, 2017; pp. 38–42. [Google Scholar]
  18. Satola, A.; Bauer, E.A. Predicting Subclinical Ketosis in Dairy Cows Using Machine Learning Techniques. Animals 2021, 11, 2131. [Google Scholar] [CrossRef]
  19. Arlauskaitė, S.; Girdauskaitė, A.; Malašauskienė, D.; Televičius, M.; Džermeikaitė, K.; Krištolaitytė, J.; Lembovičiūtė, G.; Šertvytytė, G.; Antanaitis, R. Machine Learning Approaches for Early Identification of Subclinical Ketosis and Low-Grade Ruminal Acidosis During the Transition Period in Dairy Cattle. Life 2025, 15, 1491. [Google Scholar] [CrossRef]
  20. Thornton, C.; Hutter, F.; Hoos, H.H.; Leyton-Brown, K. Auto-WEKA: Combined selection and hyperparameter optimization of classification algorithms. In Proceedings of the 19th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, Chicago, IL, USA, 11–14 August 2013; pp. 847–855. [Google Scholar]
  21. Mostafa, R.R.; Khedr, A.M.; Al Aghbari, Z.; Afyouni, I.; Kamel, I.; Ahmed, N. An adaptive hybrid mutated differential evolution feature selection method for low and high-dimensional medical datasets. Knowl.-Based Syst. 2024, 283, 111218. [Google Scholar] [CrossRef]
  22. Chawla, N.V.; Bowyer, K.W.; Hall, L.O.; Kegelmeyer, W.P. SMOTE: Synthetic Minority Over-sampling Technique. J. Artif. Intell. Res. 2002, 16, 321–357. [Google Scholar] [CrossRef]
  23. Ke, G.; Meng, Q.; Finley, T.; Wang, T.; Chen, W.; Ma, W.; Ye, Q.; Liu, T.-Y. LightGBM: A Highly Efficient Gradient Boosting Decision Tree. In Proceedings of the 31st International Conference on Neural Information Processing Systems, Long Beach, CA, USA, 4–9 December 2017. [Google Scholar]
  24. Zhou, S.; Li, H.; Fu, X.; Han, D.; He, X. Novel Multi-Classification Dynamic Detection Model for Android Malware Based on Improved Zebra Optimization Algorithm and LightGBM. Sensors 2024, 24, 5975. [Google Scholar] [CrossRef]
  25. Wolpert, D.H.; Macready, W.G. No Free Lunch Theorems for Optimization. IEEE Trans. Evol. Comput. 1997, 1, 67–82. [Google Scholar] [CrossRef]
  26. Ghasemi, M.; Deriche, M.; Trojovský, P.; Mansor, Z.; Zare, M.; Trojovská, E.; Abualigah, L.; Ezugwu, A.E.; Mohammadi, S.K. An efficient bio-inspired algorithm based on humpback whale migration for constrained engineering optimization. Results Eng. 2025, 25, 104215. [Google Scholar] [CrossRef]
  27. Zhang, J.; Diao, Y. Hierarchical Learning-Enhanced Chaotic Crayfish Optimization Algorithm: Improving Extreme Learning Machine Diagnostics in Breast Cancer. Mathematics 2024, 12, 2641. [Google Scholar] [CrossRef]
  28. Feng, J.H.; Zhang, J.; Zhu, X.S.; Lian, W.W. A novel chaos optimization algorithm. Multimed. Tools Appl. 2017, 76, 17405–17436. [Google Scholar] [CrossRef]
  29. Li, S.; Jin, N.; Dogani, A.; Yang, Y.; Zhang, M.; Gu, X. Enhancing LightGBM for Industrial Fault Warning: An Innovative Hybrid Algorithm. Processes 2024, 12, 221. [Google Scholar] [CrossRef]
  30. Wen, J.; Wang, F.; Su, Y. A Bi-Layer Collaborative Planning Framework for Multi-UAV Delivery Tasks in Multi-Depot Urban Logistics. Drones 2025, 9, 512. [Google Scholar] [CrossRef]
  31. Tizhoosh, H.R. Opposition-Based Learning: A New Scheme for Machine Intelligence. IEEE 2005, 1, 695–701. [Google Scholar]
  32. Rahnamayan, S.; Tizhoosh, H.R.; Salama, M.M.A. Opposition-Based Differential Evolution. IEEE Trans. Evol. Comput. 2008, 12, 64–79. [Google Scholar] [CrossRef]
  33. Liang, H.; Hu, W.; Gong, K.; Dai, J.; Wang, L. Solving UAV 3D Path Planning Based on the Improved Lemur Optimizer Algorithm. Biomimetics 2024, 9, 654. [Google Scholar] [CrossRef] [PubMed]
  34. Li, K.W.; Li, S.H.; Huang, Z.C.; Zhang, M.; Xu, Z.F. Grey Wolf Optimization algorithm based on Cauchy-Gaussian mutation and improved search strategy. Sci. Rep. 2022, 12, 18961. [Google Scholar] [CrossRef] [PubMed]
  35. Ye, J.H.; Shi, R.; Guo, C.Q. Research on hierarchical emergency resource scheduling for island petrochemical enterprises based on improved multi-objective grey wolf optimization algorithm. Energy 2025, 322, 135791. [Google Scholar] [CrossRef]
  36. Mirjalili, S.; Lewis, A. The Whale Optimization Algorithm. Adv. Eng. Softw. 2016, 95, 51–67. [Google Scholar] [CrossRef]
  37. Xue, J.; Shen, B. A novel swarm intelligence optimization approach: Sparrow search algorithm. Syst. Sci. Control Eng. 2020, 8, 22–34. [Google Scholar] [CrossRef]
  38. Jiankai, X.; Bo, S. Dung beetle optimizer: A new meta-heuristic algorithm for global optimization. J. Supercomput. 2022, 79, 7305–7336. [Google Scholar] [CrossRef]
  39. Dhiman, G.; Kumar, V. Seagull optimization algorithm: Theory and its applications for large-scale industrial engineering problems. Knowl.-Based Syst. 2018, 165, 169–196. [Google Scholar] [CrossRef]
  40. Jia, H.M.; Peng, X.X.; Lang, C.B. Remora optimization algorithm. Expert Syst. Appl. 2021, 185, 115665. [Google Scholar] [CrossRef]
  41. Liu, Y.; As’arry, A.; Hassan, M.K.; Hairuddin, A.A.; Mohamad, H. Review of the grey wolf optimization algorithm: Variants and applications. Neural Comput. Appl. 2024, 36, 2713–2735. [Google Scholar] [CrossRef]
  42. Bergstra, J.; Bengio, Y. Random Search for Hyper-Parameter Optimization. J. Mach. Learn. Res. 2012, 13, 281–305. [Google Scholar]
  43. Yang, L.; Shami, A. On hyperparameter optimization of machine learning algorithms: Theory and practice. Neurocomputing 2020, 415, 295–316. [Google Scholar] [CrossRef]
  44. Chen, T.; Guestrin, C. XGBoost: A Scalable Tree Boosting System. arXiv 2016, arXiv:1603.02754. [Google Scholar] [CrossRef]
  45. Thamsatitdej, P.; Kumar, D.R.; Wipulanusat, W. Compressive strength prediction of metakaolin mortar using CATBoost enhanced with genetic algorithm and particle swarm optimization. Asian J. Civ. Eng. 2026, 1–22. [Google Scholar] [CrossRef]
  46. Breiman, L. Random Forests. Mach. Learn. 2001, 45, 5–32. [Google Scholar] [CrossRef]
  47. Kaliyaperumal, G.; Renald, C.J.T.; Karthick, P.A. Detection of fatigue conditions in facial muscles using maximal overlap discrete wavelet packet decomposition and multilayer perceptron networks. Int. J. Adv. Eng. Sci. Appl. Math. 2026, 1–12. [Google Scholar] [CrossRef]
  48. Laura, O.; Karina, B.R.; Claudio, F.; Mario, G. A Literature Review of Modeling Approaches Applied to Data Collected in Automatic Milking Systems. Animals 2023, 13, 1916. [Google Scholar] [CrossRef] [PubMed]
  49. Huang, Y.; Zhang, B.; Mauck, J.; Loor, J.J.; Wei, B.; Shen, B.; Wang, Y.; Zhao, C.; Zhu, X.; Wang, J. Plasma and milk metabolomics profiles in dairy cows with subclinical and clinical ketosis. J. Dairy Sci. 2024, 107, 6340–6357. [Google Scholar] [CrossRef]
  50. Zhang, Y.; Wang, C.; Khan, M.Z.; Ju, Z.; Huang, J. Current Understanding of Bovine Ketosis: From Molecular Basis to Farm-Level Management. Animals 2025, 15, 3644. [Google Scholar] [CrossRef]
  51. Martens, H. Invited Review: Increasing Milk Yield and Negative Energy Balance: A Gordian Knot for Dairy Cows? Animals 2023, 13, 3097. [Google Scholar] [CrossRef] [PubMed]
Figure 1. Structural framework of IWMA-LightGBM model.
Figure 1. Structural framework of IWMA-LightGBM model.
Applsci 16 05050 g001
Figure 2. Classification of metabolic risk states in dairy cows based on F/P.
Figure 2. Classification of metabolic risk states in dairy cows based on F/P.
Applsci 16 05050 g002
Figure 3. Feature importance Ranking (Gain).
Figure 3. Feature importance Ranking (Gain).
Applsci 16 05050 g003
Figure 4. Balanced dataset.
Figure 4. Balanced dataset.
Applsci 16 05050 g004
Figure 5. Analysis Diagram of CCM Characteristics.
Figure 5. Analysis Diagram of CCM Characteristics.
Applsci 16 05050 g005
Figure 6. Spatial distribution characteristics of the CGHM strategy.
Figure 6. Spatial distribution characteristics of the CGHM strategy.
Applsci 16 05050 g006
Figure 7. Algorithm flow chart.
Figure 7. Algorithm flow chart.
Applsci 16 05050 g007
Figure 8. Sensitivity analysis of key IWMA parameters.
Figure 8. Sensitivity analysis of key IWMA parameters.
Applsci 16 05050 g008
Figure 9. Box plots F1–F6 of optimized IWMA and different functional algorithms.
Figure 9. Box plots F1–F6 of optimized IWMA and different functional algorithms.
Applsci 16 05050 g009
Figure 10. Box plots F7–F12 of optimized IWMA and different functional algorithms.
Figure 10. Box plots F7–F12 of optimized IWMA and different functional algorithms.
Applsci 16 05050 g010
Figure 11. Comparison of classification performance among different LightGBM-based models.
Figure 11. Comparison of classification performance among different LightGBM-based models.
Applsci 16 05050 g011
Figure 12. IWMA-LightGBM Confusion Matrix.
Figure 12. IWMA-LightGBM Confusion Matrix.
Applsci 16 05050 g012
Figure 13. Comparison of regression performance metrics for different LightGBM-based models.
Figure 13. Comparison of regression performance metrics for different LightGBM-based models.
Applsci 16 05050 g013
Figure 14. Permutation-based feature importance for ketosis regression prediction.
Figure 14. Permutation-based feature importance for ketosis regression prediction.
Applsci 16 05050 g014
Figure 15. Correlation heatmap of key variables.
Figure 15. Correlation heatmap of key variables.
Applsci 16 05050 g015
Table 1. Hyperparameters for LightGBM model optimization.
Table 1. Hyperparameters for LightGBM model optimization.
HyperparametersMeaning[lb, ub]
num_leavesMaximum number of leaves in one tree.[10, 200]
learning_rateStep size shrinkage used to prevent overfitting.[0.01, 0.3]
feature_fractionFraction of features randomly selected for each tree.[0.1, 1.0]
bagging_fractionFraction of data used for training each iteration (row sampling).[0.1, 1.0]
Bagging_freqFrequency (in iterations) at which bagging is applied.[1, 10]
min_child_samplesMinimum number of samples required to form a leaf.[5, 100]
lambda_l1L1 regularization term on weights.[0, 10]
lambda_l2L2 regularization term on weights.[0, 10]
Table 2. Ablation study results of IWMA variants on the A2 dataset.
Table 2. Ablation study results of IWMA variants on the A2 dataset.
VariantStrategyMSEConvergence IterationMSE Reduction Ratio
1WMA + CCM0.342 ± 0.018702.29%
2WMA + EOBL0.346 ± 0.018901.14%
3WMA + CGHM0.337 ± 0.018503.71%
4WMA (Baseline)0.350 ± 0.029200
5WMA + CCM + EOBL0.308 ± 0.0181012.00%
6IWMA0.299 ± 0.0175014.57%
Bold values indicate the optimal results in each row/column.
Table 3. Quantitative comparison results of IWMA and conventional optimization methods on the A2 dataset.
Table 3. Quantitative comparison results of IWMA and conventional optimization methods on the A2 dataset.
MethodMSE (Mean ± Std)Best FitnessMean FitnessConvergence IterationAverage Running Time (s)
GS0.479 ± 0.0421.4501.63980198.2 ± 9.1
BO0.367 ± 0.0181.0801.26780 ± 42105.3 ± 6.1
RS0.423 ± 0.0311.3101.48920 ± 51131.7 ± 7.4
IWMA0.321 ± 0.0090.9201.12690 ± 29109.8 ± 6.5
Bold values indicate the optimal results in each row/column.
Table 4. Performance Comparison of IWMA-Optimized Baseline Models.
Table 4. Performance Comparison of IWMA-Optimized Baseline Models.
ModelAccuracyAccuracy (Default)F1-ScoreF1 (Default)MSEMSE (Default)R2R2 (Default)Avg. Training Time (s)
LightGBM0.86250.78520.83580.76210.31820.38910.47950.4403102.5 ± 5.8
XGBoost0.85710.76430.82060.74500.33450.40150.46580.4285178.3 ± 7.6
CatBoost0.83050.75200.80520.73240.33980.41200.45920.4225159.6 ± 7.2
RF0.77890.72150.76030.70180.36210.42870.42760.393490.3 ± 5.2
MLP0.75680.70240.74210.68950.37950.44520.40530.3729206.7 ± 8.9
Bold values indicate the optimal results in each row/column.
Table 5. Overall classification and regression performance comparison of different LightGBM-based models.
Table 5. Overall classification and regression performance comparison of different LightGBM-based models.
ModelAccuracyPrecisionRecallF1-Score1-Log LossMSER2MAERMSE
SSA-LightGBM0.64040.71660.61010.62800.15920.30730.49400.40330.5544
DBO-LightGBM0.66590.72130.62510.64600.19880.31180.48660.41240.5584
SOA-LightGBM0.83380.82810.79010.80710.61790.33820.44320.44450.5815
ROA-LightGBM0.75830.76960.70450.72920.43030.31170.48670.40720.5583
WOA-LightGBM0.83530.83660.79080.81090.61270.30260.50170.39720.5501
GWO-LightGBM0.80410.81860.75360.77950.55860.30740.49390.40400.5544
WMA-LightGBM0.84990.83420.81300.82300.65220.29660.51170.40510.5446
IWMA-LightGBM0.89970.85690.89590.87490.71480.28900.52420.39490.5376
Bold values indicate the optimal results in each row/column.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Yang, Y.; Dai, Y.; Liu, H.; Guo, R. An IWMA-Optimized LightGBM Model for Early Ketosis Risk Screening in Dairy Cows Using DHI Data. Appl. Sci. 2026, 16, 5050. https://doi.org/10.3390/app16105050

AMA Style

Yang Y, Dai Y, Liu H, Guo R. An IWMA-Optimized LightGBM Model for Early Ketosis Risk Screening in Dairy Cows Using DHI Data. Applied Sciences. 2026; 16(10):5050. https://doi.org/10.3390/app16105050

Chicago/Turabian Style

Yang, Yang, Yongqiang Dai, Huan Liu, and Rui Guo. 2026. "An IWMA-Optimized LightGBM Model for Early Ketosis Risk Screening in Dairy Cows Using DHI Data" Applied Sciences 16, no. 10: 5050. https://doi.org/10.3390/app16105050

APA Style

Yang, Y., Dai, Y., Liu, H., & Guo, R. (2026). An IWMA-Optimized LightGBM Model for Early Ketosis Risk Screening in Dairy Cows Using DHI Data. Applied Sciences, 16(10), 5050. https://doi.org/10.3390/app16105050

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Article metric data becomes available approximately 24 hours after publication online.
Back to TopTop