# Early Risk Prediction of Diabetes Based on GA-Stacking
## 3 GA-Stacking  
### GA for the Feature Selection in Classifiers Based on DT  
The feature dimension of physical examination data is relatively large, which is not suitable for direct use in diabetes prediction. Extracting representative attribute subsets from it can reduce not only the training time of model but also the probability of overfitting. There are three main methods of feature selection, namely the packing method, embedding method, and filtering method. GA based on the input packing method combined with DT is used in this paper. Its pseudocode is shown in Algorithm 1. The basic operation process of GA for feature selection is as follows:Initialization: We set the number of evolutions to 100, the crossover probability to 0.6, the mutate probability to 0.01, and the number of chromosomes to 32, that is, the number of attributes in the physical examination dataset. We initialize the evolution counter \(t=0\). For the training data \(x_{i}\) of the physical examination dataset, whether to be selected or not is encoded in binary. When \(x_{i}=1\), it indicates that this attribute is selected, and \(x_{i}=0\) indicates that it is not selected. Each generation produces a population \(\mathrm{P(t)}\) composed of 20 individuals, and the first generation is the initial population \(\mathrm{P(0)}\). 2. Calculate individual fitness: Calculate the fitness of each individual in the population \(\mathrm{P(t)}\) of the current evolutionary generation. The attributes coded as 1 in the individual are classified by DT, and its F1-Score is used as the fitness of this individual. 3. Select, crossover, and mutate: The roulette wheel selection is applied to the population based on fitness. The higher the fitness, the higher the probability of being selected. The selected individual will be the parent of \(\mathrm{P(t+1)}\). Firstly, according to the crossover probability \(\mathrm{P_{c}}=0.6\), select two consecutive individuals in the population, and then exchange their gene selected by a random function to form a new individual. Secondly, according to the mutate probability \(\mathrm{P_{m}}=0.01\), select some individuals in the population and select the position of the mutated gene through a random function. If the original gene is 0, it will be mutated to 1, and vice versa. After the above operations, \(\mathrm{P(t+1)}\) is generated. Repeat steps 2 and 3 until the number of evolutions is 100, then stop the loop. The individual with the greatest fitness in \(\mathrm{P(100)}\) is the output. The attribute coded as 1 in this output is the most representative attribute subset we need. Algorithm 1 presents the pseudocode of the genetic algorithm for the feature selection in classifiers based on decision tree. ```
1:Input: Attributes:\(X=\{x_{i}\}_{i=1}^{m}\), Class: \(Y\in\{0,1\}\)
2:Output: Binary coded attributes which are selected
3:Initial the number of evolutions: \(T=100\), the number of attributes: \(n=32\), Crossover probability: \(P_{c}=0.6\), Mutate probability: \(P_{m}=0.01\), Evolution counter: \(t=0\), Initial population with 20 randomly generated individuals: \(P\) (0). 4:function FITNESS(\(P\) (t)):
5:for\(i=0,i\)\(\leq\)\(j\) (\(P\) (t)); \(i++\)do
6:// Determine the selected attributes according to \(\mathrm{P(t)}\). 7:for\(j=0;j<sizeof(P\) (\(t\))[\(i\)]: \(j++\)do
8:if\(P\) (\(t\))[\(i\)][\(j\)] == 1 then
9: Attributes\({}_{\mathrm{position}}\).push(\(j\));
10:endif
11:endfor
12:\(X=\{\mathrm{x}|Attributes_{position}\}\);
13:\(\mathit{Score(p(t))}\). push (\(F\)1 score (\(X\), \(Y\)));
14:endfor
15:return\(\mathit{Score(p(t))}\);
16:endfunction
17:while\(t<T+1\)do
18:// Individuals with higher fitness are more likely to be selected. 19: Parent1=\(\mathit{Select(P\) (t)}\), \(\mathit{FITNESS(P\) (t)}\), Parent2=\(\mathit{Select(P\) (t)}\), \(\mathit{FITNESS(P\) (t)}\));
20:// Randomly select the position of the gene value and exchange the selected gene value of Parent1 and Parent2. 21: Child=\(\mathit{Crossover(Parent1,Parent2,P_{c})}\);
22:// Randomly select the position of the mutated gene value.