# Data Mining Techniques for Endometriosis Detection in a Data-Scarce Medical Dataset
## 2 Materials and Methods
### Machine Learning Models
result \(\leftarrow\)\(\emptyset\) for each: score_name, score_array_in:\(filtered\_scores\)do global_mean \(\leftarrow\) mean(score_array) global_std \(\leftarrow\) std(score_array) length \(\leftarrow\) len(score_array) \(result[score\_name]\leftarrow\)\(\langle global\_mean,global\_std,length\rangle\)
2 end for returnresult
```  
**Algorithm 1**classify(X, Y, k, classifier)  
When there were no data from the EM class in the test set, we faced a major zero-division problem in calculating precision, recall, and F1. In these cases, we considered the zero-division argument and calculated the classification for the two possible values for the score: 0, which would be penalized, and 1, which would be rewarded. Subsequently, we only took scores with the same value for the same classification that were not affected by this situation, and then we filtered them using Algorithm 2. Although there were no zero-division problems in the accuracy calculation, we calculated this metric only when precision and recall were well defined to ensure the consistency of the results. We applied this method to all the algorithms in this study. ```
1\(filtered\_accuracy\leftarrow\emptyset\)
2\(filtered\_precision\leftarrow\emptyset\)
3\(filtered\_recall\leftarrow\emptyset\)
4\(result\leftarrow\emptyset\)
5\(result\leftarrow\emptyset\)
6\(result\leftarrow\emptyset\)
7\(result\leftarrow\emptyset\)
8\(result\leftarrow\emptyset\)
9\(result\leftarrow\emptyset\)
10\(result\leftarrow\emptyset\)
11\(result\leftarrow\emptyset\)
12\(result\leftarrow\emptyset\)
13\(result\leftarrow\emptyset\)
14\(result\leftarrow\emptyset\)
15\(result\leftarrow\emptyset\)
16 end while
17
18 end while
19 returnresult
```  
**Algorithm 2**filter_non_zero_division(precision_zd0, precision_zd1, recall_zd0, recall_zd1)  
For the calculation of the F1 score, the method defined in Algorithm 3 based on Equation (6) (previously shown) was used. This method prevented a zero-division error, which occurs when the divisor in the formula is zero, by returning not a number, or NaN. The scikit-learn library expected the default value of 0 or 1. However, we were interested in using NaN as the default value. Using this approach, we could later discard the undefined values in our evaluation. ```
precision:Input. An array of decimals with all the precision metrics. The length of this array is n. recall:Input. An array of decimals with all the recall metrics. The length of this array is n. Result:This method returns a set of arrays of cross-validation scores when zero_division has not happened. 1\(result\leftarrow\emptyset\)
2 for\(i\leftarrow\)1 to\(n\)do
3 if\(precision(i)+recall(i)\
eq 0\)then
4\(f1\gets 2\cdot



#### 2.4.1 Logistic Regression Classification

Algorithm 4 is a binary classification algorithm that uses LogisticRegression[36; 43] from the scikit-learn library as the classifier, with the default value of C=1.0 as the inverse of the regularization strength. The regularization strength is a parameter that controls the complexity of the model and prevents overfitting. The solver \"liblinear\" was chosen because it performed well on small datasets. ```
X:Input. X matrix. Y:Input. Y matrix. k:Input. The number of folds for cross-validation. Result: This method returns a dictionary with the tuples of the mean, standard deviation, and length of the cross-validation scores for each metric. The keys of the dictionary are \"accuracy\", \"precision\", \"recall\", and \"f1\". \(C\gets 1.0\)// Inverse of regularization strength solver \(\leftarrow\) \"liblinear\" classifier \(\leftarrow\) new: LogisticRegression(C, solver) // Evaluate classification result \(\leftarrow\) classify(x, y, k, classifier) returnresult
```
**Algorithm 4**classify_by_logistic_regression(X, Y, k)

#### 2.4.2 Decision Tree Classification

Algorithm 5 is a classification algorithm that uses DecisionTreeClassifier[44; 36] from the scikit-learn library to predict EM disease based on a set of decision rules.