{'fraction_non_alphanumeric': 0.02770220133564185, 'fraction_numerical': 0.013641812058829125, 'mean_word_length': 4.8943590893798365, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
An Extensive Study on Cross-Dataset Bias and Evaluation Metrics Interpretation for Machine Learning applied to Gastrointestinal Tract Abnormality Classification

Precise and efficient automated identification of Gastrointestinal (GI) tract diseases can help doctors treat more patients and improve the rate of disease detection and identification. Currently, automatic analysis of diseases in the GI tract is a hot topic in both computer science and medical-related journals. Nevertheless, the evaluation of such an automatic analysis is often incomplete or simply wrong. Algorithms are often only tested on small and biased datasets, and cross-dataset evaluations are rarely performed. A clear understanding of evaluation metrics and machine learning models with cross datasets is crucial to bring research in the field to a new quality level. Towards this goal, we present comprehensive evaluations of five distinct machine learning models using Global Features and Deep Neural Networks that can classify 16 different key types of GI tract conditions, including pathological findings, anatomical landmarks, polyp removal conditions, and normal findings from images captured by common GI tract examination instruments. In our evaluation, we introduce performance hexagons using six performance metrics such as recall, precision, specificity, accuracy, F1-score, and Matthews Correlation Coefficient to demonstrate how to determine the real capabilities of models rather than evaluating them shallowly. Furthermore, we perform cross-dataset evaluations using different datasets for training and testing. With these cross-dataset evaluations, we demonstrate the challenge of actually building a generalizable model that could be used across different hospitals. Our experiments clearly show that more sophisticated performance metrics and evaluation methods need to be applied to get reliable models rather than depending on evaluations of the splits of the same dataset, i.e., the performance metrics should always be interpreted together rather than relying on a single metric.

Gastroscopy and colonoscopy are the most successful medical procedures for GI endoscopy examinations. Among both, colonoscopy has been proven to be an effective preventative method by improving declination in the occurrence of CRC by 30% [41]. During a colonoscopic procedure, endoscopists insert a colonoscope carefully through the anus to examine the rectum and colon. A tiny wide-angle video camera mounted at the end of the colonoscope captures a live video signal of the internal mucosa of the patient's colon. The endoscopist uses the video signal for real-time diagnosis of the patient, where one of the primary goals is to identify and remove abnormalities such as polyps [78].
The current EU guidelines [75] recommend GI tract screening for all people above 50 years. Such regular screenings can be of great significance for early detection and prevention of cancer inside the GI tract, but they are challenging due to many factors. Moreover, a colonoscopy examination is entirely an operator-dependent screening procedure [64].
The detection rate of GI tract lesions mostly relies on the clinical experience of the gastroenterologist. The shortage of experienced gastroenterologists, and the clinicians' tiredness and lack of concentration during the colonoscopic examination, can lead to missing polyps that otherwise would be detected [69]. The estimated miss rate for the subject undergoing a colonoscopy examination is 25% [39].
Although considerable work has been done to develop and improve systems for automatic polyp detection, the performance of existing solutions are still behind that of an expert endoscopist [7,16,44,76,77]. Most of the published papers in the field use non-public datasets or develop models from too small training, validation, and test sets [7,76,77].
The performance metrics used to measure the performance of methods are also not sufficient (for example, see the first part of Table 1). Thus, it is difficult for researchers to compare and reproduce some of the present related works. Moreover, the state of the art research in this field does not present the generalizability of their solutions using cross-dataset evaluations. As a result, it makes a distrust for applying these machine learning (ML) solutions in practice.
An automatic and efficient Computer-Aided Diagnosis (CAD) system in a clinic could assist medical experts during the endoscopic and colonoscopy procedure to improve the detection rate by finding unrecognized lesions and act as a second observer by providing better insights to the gastroenterologist concerning the presence and types of lesions. With this inspiration, we conducted five experiments to classify 16 classes of GI tract conditions for the Medico Multimedia Task at MediaEval 2018 [54]. One example for each of the 16 classes is depicted in Figure 1.
In this work, we focus on identifying the limitations of generalizing ML models across different datasets and how to interpret the evaluation metrics in that context. For this, we are using Global Feature (GF)-based and deep learning (DL)based methods that performed well at the 2018 Medico Task [54] where one specific dataset was used. In addition, we here explore the different performance metrics of both methods (GF and DL) to identifying the limitations of each. We show that combined complex Deep Neural Network (DNN) models outperform other methods. Finally, we explore how multiclass models perform on polyp and non-polyps detection with and without retraining the model for the two specific classes. The effects of retraining for classifying the sub-categories of the same dataset and using them in other datasets are analyzed in detail to identify the cross-dataset generalization capabilities of our models. We emphasize that a large number of performance measures do not show the real performance of ML models. We also highlight the necessity of having cross-dataset evaluations to determine the real capabilities of ML models before using them in clinical settings. challenge [50,52].
In order to study cross-dataset bias and metrics interpretation, our contributions are as follows: (1) We present five ML classification models to classify multi-class findings (anatomical landmark, pathological findings, polyp removal conditions, and normal findings) of the GI tract. Using a limited imbalanced dataset, we experiment with approaches ranging from GF approaches to simple DNN and complex DNN approaches with transfer learning. Moreover, we present a detailed evaluation using six performance metrics to show the real classification performance of ML models. In addition, we analyze and present detailed evaluation results of using multi-class classification ML models for classifying binary classes (subclasses of the multi-class categories) with and without retraining to evaluate the generalizability of our models. We emphasize the difficulties of using well-performing ML methods in cross-datasets as a result of the reluctance of ML models to cross-dataset generalization. We present this negative impact with the aid of another evaluation using Receiver Operating Characteristic (ROC) and Precision-Recall Curve (PRC) curves of the best model. We also demonstrate when a ROC curve is good to use and when it is better to use a PRC curve.
(2) With the above point, we emphasis the requirement of detailed cross-dataset evaluations to identify generalizability of ML models before using them as universal models in live applications. Because good performance measures with a single dataset do not necessarily imply good real-world performance, we argue that researchers should present cross-dataset evaluations for building generalizable model rather than presenting performance values for the test datasets, which is separated from the same training data source.
Moreover, with respect to the 2018 Medico Task [54], our best DNN method achieved the highest recall, specificity and accuracy for multi-class classification of the GI tract findings. We achieved an Matthews Correlation Coefficient (MCC) (0.0029 less) and an Rk correlation coefficient 3 (0.0001 less) nearly equal to the winning team. With this achievement, we demonstrate all the steps from designing to training and testing for reaching such performance using this model and its expandability using different pre-trained networks.
In the next section, we present related work and the performance of relevant existing solutions. Section 3 discusses the methodology used for our GF-based approaches and the theoretical foundation for our work. The DNN-based approaches are similarly described in Section 4. Our experimental results are presented and analyzed in Section 5, 3 The Rk correlation coefficient and the MCC were the most important considered metrics for winning the 2018 Medico Task.
Manuscript submitted to ACM

RELATED WORK
Many methods and algorithms have been proposed for GI tract disease detection/classification using videos and images from colonoscopy and gastroscopy as input. The problem of polyp detection has by far received the most attention by researchers. Images and videos of polyps and other abnormalities inside the GI tract are usually collected using a specific purpose camera and imaging system, like ScopeGuide from Olympus. The information gathered from these types of devices may be of great significance for later examination and must be handled with great care. Polyps generally have different characteristics to the normal surrounding healthy tissue and are often easy for clinicians to detect. There are several good datasets available for training and testing on polyps (the details about the available polyp dataset can be found in [16,30]), and binary classification methods are relatively straight forward to implement.
The other active research efforts include developing an automatic and real-time detection system for GI bleeding, ulcerative lesion, blood-based abnormality, tumor, angiectasia, and for multi-class data of GI tract that comprise of anatomical landmarks (e.g., z-line, pylorus, and cecum), pathological findings (e.g., esophagitis and ulcerative colitis), and normality and regular findings (e.g., normal colon mucosa and stool). Suitable datasets for research in these areas are less developed and lack adequate content. Similarly, presented performance measures in these areas are not adequate because of not presenting enough performance metrics or not presenting cross-dataset evaluations.
Manuscript submitted to ACM Table 1 gives an overview of important works related to GI disease detection/classification and the 2018 Medico Task [54] using CAD, from automatic polyp detection to multi-class disease detection and classification system. The dataset used for the experiments in the first half part of the Table 1 is different. Therefore, the results can not be directly compared; however, the results on the lower half part can be compared as the algorithms are tested on the same dataset.
Most of the research in the medical field only focuses on designing an automated disease detection system for detecting or classifying specific disease or abnormality, like polyp detection or ulcer detection. Because patients may suffer from more than one type of disease at the time, a working multi-class disease detection system will help treatment.
The performance of existing multi-abnormality detection systems is, however, not satisfactory and cannot assist doctors in CAD in real-time while undergoing colonoscopies. Furthermore, these research works have not evaluated all performance metrics at once to analyze the real behavior of their classification models. On the other hand, none of the above methods have performed cross-dataset evaluations to prove the capabilities to use the ML models in real CAD systems.
For handcrafted (HC) feature based methods, image descriptors like global or local image features (e.g., color, texture, and edges) are extracted, and later on, various ML classifiers (for example logistic model tree [72], random forest classifier [43], or Support Vector Machine (SVM) [77]) are employed to perform analysis using these features. HC descriptors (manually designed features) are useful for the gastroenterologist while identifying specific abnormality regions inside the GI tract. For instance, as blood has a particular range of chromaticity, we can specify a specific chromaticity range where features of bleeding abnormality seem to be concentrated [31]. Riegler et al. [59] achieved an F1 score of 0.909 with a GF-based approach and an F1 score of 0.875 with a DL based approach with a multi-class GI tract dataset. With ASU-Mayo polyp dataset, the GF-based approach achieves an F1 score of 0.961 while the DL based approach could make 0.936. They further suggested that the combination of both approaches may lead to improved performance. Also, the previous work by Riegler et al. [57], reveals that, while only detecting whether a frame contains an irregularity or not, GFs can beat local features, i.e., at least reach as same results while concerning detection/classification and performs better than local features with regard to processing speed. In all of these works, researchers presented performance metrics using a test dataset selected from the same dataset used for the training data. Therefore, these results do not reflect the actual practical performance of the proposed methods.
A few past studies used the information such as color and texture of polyp to sketch HC descriptors [2,3,13,28,29,32,69]. The other category of methods for automated polyp detection used shape, intensity, edge, and spatio-temporal information. For instance, Hwang et al. [27] appropriated elliptical shape features to detect the occurrence of polyps in the colonoscopy videos. Bernal et al. [7] proposed a polyp detection technique by utilizing polyp region descriptor, which is dependent on the depth of the valley image and introduced a region growing method to detect polyps in colonoscopy images. Bernal et al. [8] additionally used valley information and enhanced their approach by improving the polyp localization results to almost 30%. Bernal et al. [6] also performed additional evaluations using valley information and demonstrated better performance, especially for smaller polyps and decreased polyp miss-rate. Park et al. [47] utilized the spatio-temporal features for automatic polyp detection. The recently completed related work that uses the cross-sectional profile to detect protruding polyps automatically is the polyp-detection system Polyp Alert [78], which can provide near real-time feedback during colonoscopies. However, the system is limited to polyp detection and is slow for live examinations. Tajbakhsh et al. [69] proposed a method for automatic polyp detection from colonoscopy videos, which uses context information to remove non-polyp and shape information to localize polyp reliably. Riegler et al. [59]  Here, we obtained an MCC of 94.21%, a F1 score of 94.58%, and an accuracy of 99.32%. This was one of the best results in the MediEval 2018 Medico Task Challenge. We discuss the model introduced by Thambawita et al. [72] in detail in this paper and reproduce similar results. Based on those models, we provide and discuss the requirement of detailed evaluations using multiple performance metrics and cross-dataset evaluations.
Manuscript submitted to ACM Recent related works show promising results in terms of evaluation metrics, i.e., both sensitivity and specificity despite various challenges (for example, difficulties arise due to a dataset obtained from different modalities). The limitation with most of the recent approaches is that they target only specific problems, like bleeding detection or polyp detection. Current systems are either (i) too narrow for a flexible, multi-disease detection/classification system; (ii) tested only on a limited datasets, too small to show whether the systems would work well in hospitals, (iii) providing low processing performance for a real-time system or ignore the system performance entirely; (iv) overfitting of the specific dataset can also be a problem and lead to unreliable results; or (v) tested using datasets that are not publicly available, making it difficult to compare the approaches with others.
In some cases, GFs-based approaches produce better results. have discussed selection bias, capture bias, category or label bias, and negative bias as the main factors for the dataset bias. This directs our research to do additional experiments to identify the significant factors of the cross-domain data generalization in the medical domain, which is more critical than the general image classification.
The classification of GI diseases is more complicated than a simple real-world object classification task where one detects faces or recognize characters. Typical GI tract datasets are heavily imbalanced, e.g., the dataset of the 2018 Medico Task consists of 16 classes of anatomical landmarks, pathological findings, polyp removal cases, and normal and regular findings where the polyp class has a maximum of 613 images, and the instrument class has a minimum of only 4 images. Additionally, medical datasets are captured using different endoscopic instruments, and some of the images can be noisy, be blurry, be over-or under-exposed, be interleaved, have superfluous information within the image, contain borders, and be affected by specular reflections caused by instrument light source. Some of the images may have bleeding, while other images can be partially covered by stool or mucus. Moreover, the organs from mouth to anus can have multiple lesions showing different diseases, abnormalities, and internal injuries. Thus, the above situation leads to the necessity of distinguishing between various classes of GI tract findings. In this scenario, not only high precision, and recall, but also high accuracy and MCC becomes essential for developing an automated generalizable multi-class classification system. This implies the real requirement of measuring and analyzing all performance metrics at once. Furthermore, to prove the generalizability of models, cross-dataset evaluations are required.
Manuscript submitted to ACM

GLOBAL FEATURE BASED APPROACHES
Global Features (GFs) or descriptors are features computed over the whole image or covering a regular sub-section of an image. GFs represents the overall properties of an image and are often used in image retrieval, image compression, image classification, object detection, and image collection search and distance computing [55]. Examples of GFs are shape matrix, Histogram Oriented Gradients (HOGs), Co-HOG and invariant moments (Hu, Zernike). The LIRE [42] framework can be used to extract HC GFs like texture, color distribution, and the histogram of brightness.  Figure 2 shows the architecture of the proposed GF-based methods (1 and 2). These methods use six selected GFs and the best ML classifiers for the provided dataset.
Feature engineering is among the most crucial and challenging part for approaching any ML and computer vision problem. Based on the findings of Pogorelov et al. [55] and Riegler et al. [60], we choose to used JCD, Tamura, CL, EH, ACC, and PHOG. The combinations of these features represent the overall properties of the images. We can even add more GFs, but it may increase the noise to the image features, which again would hurt the classification performance.
Moreover, we have formulated the problem of GI tract anomaly classification as a multi-class (sixteen-class) classification of different findings including anomalies, landmarks and clinical markings. With the provided dataset, we have computed the GFs of each image. A multi-class classification problem is a general and well-studied ML problem, and there are a variety of methods available to solve this issue with higher performance. Therefore, we have sent the extracted GFs to many available ML classifiers. The whole experiment was completed with the development dataset. The 2018 Medico Task [54] shows best classification rates with Simple Logistic (SL) [38] and Logistic Model Tree (LMT) [38] classifiers.

Method 1: The SimpleLogistic classifier
In method 1, we combine the SimpleLogistic (SL) classifier from the Weka software [22] to build a linear logistic regression model with the LogitBoost [21] utility for determining attributes. The SL classifier can deal with both binary class classification, multi-class classification, missing class, and nominal class. It can handle different types of attributes such as binary attributes, nominal attributes, date attributes, missing values, unary attributes, and empty nominal attributes [38]. In a linear logistic regression classifier, a simple (linear) model fits the data, and the method of model fitting is pretty stable, leading to low variances.
LogitBoost is utilized for determination of the most appropriate attributes in the data at the time of executing logistic regression, which is done by performing a simple regression in every iteration before it converges to a solution of maximum likelihood. Therefore, LogitBoost, with a simple regression function that acts as a base learner, is utilized for Manuscript submitted to ACM fitting the logistic models. The optimum number of iterations associated with the LogistBoost algorithm to function is cross-validated, which leads to the automatic selection of the attribute [66]. The SL classifier has a built-in attribute selection (if the default parameter is not changed): it stops computing Simple Linear Regression models (i.e., performing LogitBoost iterations) when the cross-validated classification error no longer decreases. With the extracted features using LIRE, the SL classifier has not only the highest classification accuracy, but also it takes lowest classification time (i.e., lowest computational complexity) when compared with other ML classification algorithms.

Method 2: The Logistic model tree
In method 2, we use the LMT classifier from the Weka software. The LMT is a classification model related to a supervised training algorithm, which is a combination of Logistic Regression (LR) and decision tree learning techniques [38,63].
Thus, the LMT is considered an analogue model for solving classification problems. In the logistic variant, information gain is utilized for splitting, the LogitBoost algorithm generates an LR model at each node in the tree, and the CART algorithm [63] is utilized for pruning the tree.
The LMT uses a cross-validation (CV) technique to find several LogitBoost iterations to prevent overfitting of the training data. The LogistBoost algorithm accomplishes additive logistic regression which is achieved by least-squares fits for every class M, [19] which is shown in Equation 1: Here, β i denotes the coefficient of the ith component of the vector x, and n denotes number of features. The LMT model uses the Linear logistic regression method to calculate the posterior probabilities of the leaf nodes [38] which is shown in Equation 2: Here, D denotes the number of classes, and L M (X) stands for the least-square fits. The least-square fits L M (X) are transformed in such a way that D M =1 exp(L M (X ) is equal to zero.
Then, we chose ResNet-152 as the base model of the first DL approach and this base model experiment has been done under the method 3 (the model is illustrated in Figure 3). This selection has been made based on preliminary experiments.
In the preliminary experiments, the ResNet-152 showed better performance than Densenet-161. This Densenet-161 was in the second place in the performance ranking when we compared stand-alone pre-trained DL models.
In DL methods 4 and 5 (as illustrated in figures 4 and 5), we have used both pre-trained ResNet-152 and Densenet-161 using the ImageNet dataset. In the following sections, we discuss data pre-processing mechanisms and training mechanisms used for all three DL methods. In the later sections, we discuss these methods one by one with its fine-tuning mechanisms with more comprehensive explanations.
For the transfer learning methods, we use the data preprocessing tool of Pytorch library to 1) resize input images, 2) For training all DNNs, the transfer-learning mechanism was used. Then, we used the cross-entropy loss [15] with weighted classes as given in Equation 4 to calculate the loss values of the DNNs: In this equation, the weight parameter value is calculated inversely proportional to the image count in the corresponding class. In other words, class weight values are high when the classes have less number of images. However, the inbuilt cross-entropy function given in the Pytorch is used instead of implementing it from scratch. While doing preliminary experiments, we observed that there was not any effect from weighted cross-entropy loss. Then, we used the normal cross-entropy loss (Equation 5) function for calculating the loss of the DNNs: As the optimizer of all the DNNs, the stochastic gradient descent [11] method with a momentum [67] was applied. We selected this optimizer because of its stable learning mechanism in contrast with the highly unstable learning pattern of other methods [35,61,81] while they show fast convergence.
During the training procedure, we changed the learning rate manually based on the progress of learning curves rather than using the inbuilt learning rate schedulers of Pytorch. Initially, we began with a high learning rate. Then, the learning rate is reduced by the factor of 10 if the training process did not show good progress in the learning curves.
Finally, model weights of the best epoch based on the best validation accuracy were saved to use in the inference stage.

Method 3: DNN approach based on ResNet-152
Method 3 is the base method that uses only ResNet-152. A block diagram of this is illustrated in Figure 3. In this method, networks when we do transfer learning. Then, we train the last and the new layers using the new domain data. Finally, the entire network is trained after unfreezing all parameters of the network (a method known as fine-tuning).
We performed preliminary experiments to identify the influence of the above described freezing-unfreezing technique compared to using simple fine-tuning. Both techniques showed the same performance at the end of the training process, and we could not gain any performance benefit from the freezing-unfreezing method while using the simple fine-tuning method was faster. Therefore, we decided to use the simple fine-tuning method for all experiments.
In this method 3, we started the training process with a learning rate of 0.001. Then, the learning rate was decreased by a factor of 10 if we could not see any performance improvement for the validation dataset. We repeated this change of learning rate until the model came to a good stable position. In this experiment, the stochastic gradient descent method was used as the optimization method with a momentum of 0.9.
These networks were retrained separately into the Medico dataset using the same procedure used in method 3. Before this retraining, the networks were modified to classify the 16 classes. Then, we calculated an average probability of the two probability vectors (V Resnet _152 and V Densenet _161 ) output by the two separate networks: ResNet-152 and Densenet-161. By calculating the average of these two probability vectors we accepted cumulative probability decision rather than the individual decision. Using the average from these two networks, we expected to have a good decision with high confidence. For example, if the two networks return high probability values for the same class, the class probability value (confidence of classifying to that class) is high. On the other hand, when one network has a high probability, and the other network has a low probability for a specific class, then the final probability value is around 0.5. This value infers that confidence about the particular class is not good enough for the final decision.
In this model, the probability of the final answer depends on the average values rather than the highest probability value returned from one of the two models. Here, the problem is that the prediction suggested from the highest probability value of one model may be the correct class compared to the selected category from the average. Finally, we trained the model using a learning rate of 0.001. Also, we decreased the learning rate by factor 10, when the model did not show convergence. A momentum of 0.9 with Stochastic Gradient Descent (SGD) was used as same as method 3.   In the pre-training step (1), we train each DNN net i ∈ N ET S as much as possible using the transfer learning mechanism until it gives the best predictions as described in method 3 (using different loss functions; loss 1 to loss N ).
The DNNs have their unique prediction capabilities within the given classification problem. Then, we analyze the

RESULTS
In this section, we discuss the experimental setup, datasets, and results obtained from our experiments. Using these presented results, we emphasize that high scores for performance metrics do not always show the actual performance of ML methods. To show this, we present well-performing ML models, which achieved good results for their performance values. Using cross-dataset testing, we present a detailed analysis of evaluation metrics to emphasize that they are not always representative to identify the real performance of models.
For all experiments, we used the same hardware platform with an Intel Core i7 8 th generation processor with 16 GB DDR4 RAM, and 8 GB NVIDIA Geforce 1080 GPU. On the other hand, we practiced two different software frameworks for implementing our methods. To implement the GF-based methods 1 and 2, we have used the WEKA framework [22].
We have used the Pytorch framework for the DNN-based methods 3, 4, and 5.
Manuscript submitted to ACM CVC-12k [4,5]. The training and testing datasets of the 2018 Medico Task have been derived from the Kvasir Dataset [52] and Nerthus Dataset [51]. It consists of 16 classes as shown in Table 2 Table 3, we present a summary of the uses of the 2018 Medico dataset and other datasets for polyps and non-polyps classifications.
The Medico development dataset was used to train our ML models in the first stage. However, this dataset consists of a highly imbalanced number of images, as summarized in Table 2. Within this, the out-of-patient class had only 4 images to train our models. Therefore, only in the first stage, we used an additional 30 images that were selected randomly from the Internet to fill this class in the training dataset. These were images of flowers, vehicles, and other general stuff in our everyday life and did not have any relationship with this class. The advantage of this technique is discussed in the discussion of Section 6.
When we discuss the ML models' generalizability in the second part of the paper, we used the CVC datasets to retrain and test our models.   separate folders. However, the content and number of images in CVC-12k were not otherwise changed. Therefore, we refer to it by its common name.
In the second part of our research, we have used the CVC-356-plus and CVC-612-plus datasets for retraining our models to classify polyps and non-polyps. Only in this part of the research, we replaced 1,929 non-polyp images of the CVC-356-plus dataset with newly extracted 1,171 images from a clean and healthy colon video collected from the same hospital. We have done this modification to avoid the overlap between the non-polyp images of the CVC-356-plus training dataset and CVC-12k testing dataset.
For the dataset preparation stage, we focused on the number of polyps and non-polyps images in each dataset to analyze the correlation between the data distribution and the model performance. A bar graph of this data distribution is illustrated in Figure 7. We chose to include different proportions for the number of polyps and non-polyps to keep a diversity of data percentages in each test case. In the CVC-356-plus dataset, the polyps percentage is low compared to the non-polyp percentage. In the CVC-612-plus dataset, percentages of polyps and non-polyps are around 50%. In contrast to this, the CVC-12k dataset has a higher polyps percentage than the non-polyps percentage. Due to this, we can study the effects of data imbalance in the training and testing datasets on the performance and interpretability of the metrics.

Analyzing results
We discuss our results in two main sections: 1) the 16 class classification task based on the 2018 Medico Task and 2) the polyps and non-polyps classification task to analyze generalizability of ML models.

16-class classification.
In this 16-class classification task, the training dataset of the 2018 Medico Task was split into a 70% training dataset and a 30% validation dataset. Then, the test data given by the organizers was used to test the performance of five methods for classifying 16 classes of the GI tract findings.
We evaluated our five models based on the results collected by the organizers. This evaluated results of the main five models are tabulated in Table 4. With an MCC score of 0.9421, method 5 showed the best performance for classifying According to this plot, it is clear that the areas of the hexagons covered by the GF methods are smaller than the areas covered by DNN methods. With these results, it implies that three DL methods outperform two GF methods.
The CM of method 5 collected from the organizers of the 2018 Medico Task is tabulated in Table 5 for the in-depth investigation. According to the CM, we can identify two main bottlenecks to improve the performance of method 5. The Manuscript submitted to ACM

Actual class
first one is misclassification between esophagitis and normal-z-line, and the second one is misclassification between dyed-lifted-polyps and dyed-resection-margins. Therefore, images from these classes were manually examined to identify the reasons for these misclassifications. For the conflict between esophagitis and normal-z-line, the reason is very close locations of these two landmarks in the GI tract. On the other hand, the confusion between dyed-lifted-polyps vs. dyed-restrictions caused because of the same color patterns and the same texture structures of both types of images.
With these limitations, method 5 showed the best performance with an MCC of 0.9421, which was the important measurement to win the 2018 Medico Task. Based on the MCC value, we won second place in the 2018 Medico Task. The winning team [25] relabeled the development dataset and also generated more images out of the provided instruments class by placing the instrument as a foreground over the images of dyed-lifted-polyps, dyed-resection-margins, and ulcerative colitis to balance the instrument class for improving the performance. However, we developed the model by only using the images provided by the task organizers for a fair comparison of the approaches with the limited dataset.
Then, our next experiments were conducted to find the re-usability of these well-performed models in different datasets with polyps and non-polyps categories (subcategories of the 16 classes of primary tasks).

5.2.2
Polyp and non-polyp classification using the pre-trained models. The following analysis was performed to identify the polyp classification ability of our five models on the same test dataset and different CVC datasets. The 16-class classification results collected from the Medico Task organizers were analyzed to calculate polyp detection performance in the Medico test data. Moreover, our models were tested with CVC-356-plus, CVC-612-plus, and CVC-12k datasets without any modifications to the five models to compare the performance of polyp detection.
According to the correct and incorrect classifications of polyps and non-polyps in the test datasets, the first large column of Table 6 was calculated to measure the polyps detection performance of five models. In this evaluation process, all the 15 classes except the polyp class were considered as the non-polyp classification because the number of outputs is 16 in the first models. For comparison, the MCC values of these tests are plotted in Figure 9. This graph shows that the polyp detection performance of the same dataset (the testing dataset of Medico Task) is higher than on the completely new datasets (CVC-356-plus, CVC-612-plus, and CVC-12k) for both the GF-based approaches and the DNN approaches.  This is the first analysis, and we emphasize that it shows that researchers need to do cross-dataset evaluations to prove the real capabilities of ML models.
From the first column of Table 6 and Figure 9, it is clear that the performance of the GF methods for different datasets Because the performance gap between the 16-class classification and polyps classification showed differences, we retrained our models to classify only the polyps and non-polyps classes. Therefore, our next experiments were performed to test how retraining our five ML models to classify polyps and non-polyps will influence the performance.
For the retraining experiments, we first retrained the two GF methods with new ARFF files generated for polyps and non-polyps categories. Second, in the retraining stage of the three DNN methods, we changed only the last layer into two outputs. However, we did not change the loss function from categorical cross-entropy into binary crossentropy because two-class categorical cross-entropy is equal to binary cross-entropy. Moreover, we retained the original optimization functions as it is. Then, we retrained all five models using the same Medico dataset, which has only polyps and non-polyps classes. At the end, the results of these experiments are tabulated in the right columns of Table 6.
Manuscript submitted to ACM The results in Table 6 show that it can be difficult to evaluate the models and interpret the results after retraining  Table 7. When the models are trained using the balanced CVC-612-plus dataset in combination with the 2018 Medico development data, the DNN models show better MCC values (0.8189, 0.8555, and 0.8606) for methods 3, 4, and 5, respectively. This is true for the Medico test data and the two smaller CVC datasets. Moreover, the MCC values for the CVC-12k test data also achieves the best MCC values of 0.1421, 0.1418, and 0.1802 for method 3, 4, and 5. An important observation from the CVC-12k dataset is also that looking at all other metrics but MCC and specificity could mislead to the assumption that the results are good. For example, scores above 0.8 for accuracy which is often used as the only indicator for performance in similar studies.
In the first comparison, we plotted performance changes for the retraining with the different training datasets and tested them on the Medico test dataset. The changes in the REC, PREC, SPEC, ACC, MCC and F1 values can be seen as hexagon plots in Figures 10a, 10c, 10e, 10g, and 10i which are corresponding to methods 1, 2 ,3, 4 and 5, respectively.
In these plots, T1 is used to present performance values before retraining the ML models into two-class classification  (subfigures (b, d, f, h, j)) shows the results of the CVC-12k dataset. The methods are represented as following: a-b is for method 1, c-d is for method 2, e-f is for method 3, g-h is for method 4 and i-j is for method 5, respectively.   Tables 6 and 7. Then, relevant results from these tables are plotted in Figures 10b, 10d, 10f, 10h, and 10j. These plots use same line notations similar to the above experiments.
Using the plot series in Figure 10, we can examine the re-usability of ML models to classify polyps and non-polyps, which are sub-classes of the primary classes on the task. For example, if we compare plots in Figures 10a and 10b, then we can know that how method 1 performs to classify polyps and non-polyps within the test dataset same as the training dataset and within an entirely new dataset. While investigating these plots, the proportion of the number of polyps and non-polyps is an important factor in explaining the shape of these hexagon plots.
If we compare the GF methods (Figures 10a − 10d ) and the DL methods (Figures 10e − 10j), it is clear that DL methods outperforms the GF methods in both Medico Task and polyps classification task introduced in this paper. This implies that the DL methods are capable of extracting deep features that cannot be extracted by manual feature extraction methods used by the GF methods. With the retraining process in the GF methods, we can see performance differences between the Medico dataset and the CVC-12k dataset. The main conclusion that we make is that GF-based methods are not able to capture the underlying patterns that would allow for efficient classification; thus their performance is low.
Plots in the first column and the second column in Figure 10 show completely different behaviors for the same retraining process when we use different test datasets. The test dataset for the first column comes from the same domain as the training data, and the test dataset for the second column comes from the completely new domain like CVC-12k dataset. To investigate these unusual performance changes, we generated and examined ROC curves and PRC curves for the best DNN model (method 5). The ROC and PRC curves for method 5 with the Medico test data (for the plot in Figure 10) are depicted in Figures 11a and 11c. Similarly, the ROC curve and the PRC curve for the method 5 with CVC-12k data (for the plot in Figure 10  Analysis of ROC curves is more robust for ML models that are used with balanced datasets, whereas PRC curves are more valuable for ML methods when the methods engage with imbalanced datasets. However, we have used both curves in this paper to investigate the behavior of these curves while we are using highly imbalanced datasets. Consequently, the PRC curves show completely different baseline values of 0.0483 for the Medico test dataset and 0.8386 for the CVC-12k dataset. The small baseline value arises in the plot in Figure 11c as a result of small polyps to the non-polyp proportion in the Medico test dataset. Conversely, the high baseline value in Figure 11d appears there as an effect on a high ratio of polyps to non-polyps.
To get a better understanding of the above plots, we selected the plots in Figures 10i and 10j, and ROC and PRC curves in Figure 11. With this selection, first, we analyze T1 and T2 from the hexagon plots and the corresponding ROC and PRC curves. While T2 shows a performance loss compared to T1 in Figure 10i, Figure 10j shows that T2 achieves a performance improvement over T1. Next, we look for the reasons for these performance changes.
In method 5, the model with the 16 outputs corresponding to T1 has 15 choices to classify non-polyp images.
Similarly, the Medico test dataset has more non-polyp images compared to polyp images. On the other hand, the model Manuscript submitted to ACM corresponding to T2 has a 50% chance to classify polyps as well as non-polyps. As a result, the model of T1 shows better performance than the model of T2 in Figure 10i. Because this shows a slight performance change, we cannot see the same difference in ROC and PRC curves in Figures 11a and 11c. In contrast, T2 in the plot in Figure 10j shows were tabulated in Table 8 and corresponding graphs were depicted in Figure 12 to analyze them.
The first row of Figure 12 shows the differences in the performance of testing with the Medico test data. In the second row, it presents the performance changes for the CVC-12k dataset. The dotted lines in plots in Figure 12     TN detection, shows that method 5 is affected by imbalanced data in the CVC-12k dataset. The main reason for the effect is that the CVC-12k dataset contains a lower percentage of negative images compared to positive ones. This reflects an important factor to take into account when developing generalizable ML models which is that the ratio of negative and positive findings needs to be taken into account when looking at metrics. Metrics such as MCC are better suited to interpret results. In terms of ROC compared to PRC, the results show that PRC reflects the performance of the model more realistically than ROC.

DISCUSSION
In this section, we discuss our findings and point out several important considerations for future research. Our discussion follows the same sequence as our contributions in this paper.
Manuscript submitted to ACM of this competition has used additional data items that were made by photo editing tools for the imbalanced classes such as the out-of-patients class. In contrast to this, our method 5 works well without using manually annotated data items because of the procedure we followed to implement and train that model. The procedure of implementing such a complex model is described step by step in Section 4.3 and anyone can follow these steps to get a well-performing DL model in a classification task.
In addition to the implementation and the procedure used in method 5, the data filling mechanism used to fill the out-of-patient imbalance class shows impressive performance gain. This method is preferred when one class has a small number of data items in a multi-class classification task. In our work, without annotating more data ourself which also requires the help of medical experts, we prefer to use random images from the Internet, as described in Section 5.1. This is an efficient way to add more data items without spending more time on manual annotation or creating synthetic data items. The above method works because the random images influence the ML models to make a wider range of possibilities to classify images into a particular class.
Dyed-lifted-polyps, dyed-resection-margins, esophagitis, and normal-z-line arose classification conflicts in our best method (method 5). If we could overcome these conflicts, then the model would perform better than the current recorded performance in the 2018 Medico Task. To identify the reasons for this classification conflicts, we manually investigated the images of these classes. If we compare sample images of dyed-lifted-polyps (Figure 1c), dyed-resection-margins ( Figure 1d), esophagitis (Figure 1e), and normal-z-line (Figure 1i), then we can identify that this conflict caused as a result of similar texture and shapes of these images. To overcome this problem, researchers can select only the images that made conflict and train a new DL model to classify them into the correct classes. Then, this model can be added to the model introduced in method 5 using the property of its expandability.
Can we use our best DL model for real systems in hospitals to classify GI findings? Or can we use the state of the art ML classification models introduced by researchers in real applications? Towards answering this question, this paper focuses on deep evaluations of the proposed methods as one of the main contributions. Regularly, researchers present the performance of their classification models using only a test dataset, which was reserved from the dataset used to produce the training data. Also, they measure the performance selecting only a few measurements out of the REC, PREC, SPEC, ACC, MCC, and F1. However, we emphasize the requirements of an in-depth analysis of all of these six parameters at once to identify the real performance of ML models. Several of the works listed in Table 1 do not use this methodology as part of their evaluations. This makes it difficult to reason about the real-world performance of the proposed methods and how they compare with other methods. In this paper we also consider the importance of evaluating ML models with cross datasets.
Why do we need cross-dataset evaluations? To explain this requirement, we consider the research work done by Wang et al. [76]. They presented an area under the receiver operating characteristic curve of 0.984 and a per-image sensitivity of 94.38 for polyp detection. In our first look, these results show a good DL model. Similarly, our results in Figures 10i, 11a and 11c reflect the same impression in the first look because it shows excellent performance as a DL model. However, after analyzing cross-dataset performance for polyp detection with a completely new dataset like CVC-12k, we recognized that performance gain is not enough for applying it in real applications. Therefore, from this paper, we emphasize that researchers want to consider cross-dataset evaluations very thoroughly before applying their solutions in real-world applications. Otherwise, the selection bias, the capture bias, and the category bias (label bias) Manuscript submitted to ACM problems may appear in the results. Then, we may end up with the wrong conclusion about research works. All of these facts imply that more research works must be performed to improve the generalizability along with the performance improvement on a single dataset or single data source.

CONCLUSIONS
We have studied cross-dataset bias and evaluation metrics interpretation in machine learning (ML) using five methods and four different datasets within the field of Gastrointestinal (GI) endoscopy as respective use case. In particular, we performed an extensive study of ML models in the context medical applications based on a use-case of GI tract abnormality classification across different datasets. The main conclusion and resulting recommendation is that a multi-center or cross-dataset evaluation is important if not essential for ML models in the medical field to obtain a realistic understanding of the performance of such models in real world settings.
We found that the combination of the Deep Neural Network (DNN) ResNet-152 and Densenet-161 with an additional Multi-Layer Perceptron (MLP) performed best on both the validation and test datasets. This model shows that a combination of multiple pre-trained DNN models can have better capabilities to classify images into the correct classes because of their cumulative decision-making capabilities. We also proposed an evaluation method using six measures: Recall (REC), Precision (PREC), Specificity (SPEC), Accuracy (ACC), Matthews Correlation Coefficient (MCC), and F-score (F1). Moreover, we suggest that these measures should be presented all at once using hexagon plots that convey a complete view of real performance. We hope that these tools can enable a more realistic evaluation and comparison of ML methods.
Furthermore, we presented cross-dataset evaluations to identify the generalizability of our ML models emphasizing on the fact that achieving high scores for evaluation metrics does not always represent the real performance of ML models and should be interpreted with care. By evaluating the ML models with cross-datasets experiments, we showed the complexity of understanding the real functional performance of the models. The state of the art research works which perform classification cannot be used in practical applications because of their lack of generalizability. Based on the experimental results, we conclude that researchers should focus on implementing and researching generalizable ML models with cross-dataset evaluations. Rather than presenting metrics calculated from a simple training and testing split of the data, we suggest to always rely on cross-dataset evaluation to obtain a real-world representative indication of the model performance. This is especially important in a medical context since one has to make sure that the obtained models are reliable and not just perform well on a specific dataset.
Finally, we want point out that the lack of generalization, as evidenced by the poor result for cross-dataset evaluation presented in this article, rises the very important question: In the context of cross-dataset or multi-center studies, is it really possible to have generalizable ML models? This is something that we ourselves plan to investigate further in future work, and we hope that other researchers in computer science and medicine will do the same or at least have the question in their mind when performing similar studies.

ACKNOWLEDGMENTS
We would like the reviewers for their contributions to the article. This work is funded in part by the Research Council of Norway project number 263248 (Privaton).
Manuscript submitted to ACM