# Application of Artificial Intelligence in Support of NAFLD Diagnosis
## 2 Materials and Methods
### Methodology
#### 2.1.2 Model Training  
The task of the second module is to deal with AI models. This module is to make sure that the models are of the highest possible quality and that they are tuned to the latest data.  
It also allows for processing patient data and making diagnoses. Its main idea is to use data incrementation to fine-tune the models.  
To ensure the quality of the machine learning models, the next step employs two fundamental data preparation techniques: stratified data splitting into training and testing sets and data standardization. This approach avoids the problem of unrepresentativeness, which could lead to erroneous conclusions about model performance. Data standardization prevents the dominance of features with larger values and speeds up the convergence of optimization algorithms. These techniques are crucial in a diagnosis support system because they ensure that models learn from well-calibrated data, resulting in better performance and prediction accuracy.  
Next, the models are flagged to be trained on increment data. Then, both sets of models are trained on their corresponding training sets. Training of machine learning models is performed through an iterative optimization process to find the model parameters that best describe the relationships in the training data. The model goes through training. Depending on the model type, different algorithms try to reduce the value of the cost function while learning different relationships between the data. It is considered trained once the algorithm is fed all the data from the training set. Once training is complete, the model is evaluated on a test set not used in the training process. This evaluation provides an independent measure of the model's performance and its ability to generalize on new, previously unseen data.  
The next step of this process is to compare the quality of old and newly trained models as shown in Figure 2. The F1 measure is used as a reference here because it harmonizes precision and sensitivity, providing a balanced assessment of model performance, especially for unbalanced classes. Once all the models have been created and their diagnostic quality has been adjusted to the new information, one large ensemble model is created, which will be used for diagnosis in this system. It combines the predictions of all baseline models that have reached an F1 measure value higher than the threshold (currently 85%) for better overall performance. In a majority vote, each model casts one vote for the predicted class, and the class with the most votes becomes the final team forecast, as it was shown in Figure 3. An ensemble model is preferable because it combines the predictions of different base models, each of which emphasizes different attributes of the data, resulting in more accurate and stable results. Baseline models differ in their errors and generalizability, so combining them in an ensemble model can capture complex relationships in the data, minimize the risk of overfitting, and compensate for weaknesses in individual models.  
As a result, the ensemble can better generalize on new data, providing higher performance and more reliable predictions than any single base model. The large model created in this way is stored on the hard drive, and from then on, it will be used in the system for predictive diagnosis. The new ensemble model is overwritten even if its global accuracy derived from the metrics is worse than before. Taking into account that it is created from many other models whose individual quality is better or equal to earlier versions, the poorer quality of the ensemble model may, therefore, be due to an unfortunate distribution of votes, and instead, the model gains resistance to overfitting. In testing the quality of the models, it was observed that each baseline model pays the most attention to different attributes from the data.  
Figure 3: Ensemble model voting example. 0 means that model diagnosed patient as healthy and 1 that model diagnosed patient as sick.  
Figure 2: Algorithm of models’ overwriting.