| Algorithm 2. Pseudocode of genetic-based extreme gradient boosting (GXGBoost) model. | |
| 1. | Initialization |
| 2. | minPopulation = 5;//Minimum population of GA |
| 3. | maxPopulation = 10;//Maximum population of GA |
| 4. | numIterations = 10;//Number of iterations to evaluate GA |
| 5. | minNumEstimators =5, minLearningRate =0.1, lowMaxDepth =2; |
| 6. | maxNumEstimators =50, maxLearningRate =0.4, highMaxDepth =20; |
| 7. | Input |
| 8. | TrainingSet, ValidationSet; |
| 9. | Begin |
| 10. | numPopulation = random.randint (minPopulation, maxPopulation);//Generating random number of population |
| 11. | populationGXGBoost = []; |
| 12. | For i in range (numPopulation): |
| 13. | GXGBoostParameters = random.randint (minNumEstimators, minLearningRate, lowMaxDepth, maxNumEstimators, maxLearningRate, highMaxDepth);//Generating random values of GXGBoost’s parameters |
| 14. | GXGBoostModel = generateGXGBoost (GXGBoostParameters); |
| 15. | populationGXGBoost.append (GXGBoostModel); |
| 16. | End for i |
| 17. | maxAccuracy = 0; |
| 18. | best_model = None; |
| 19. | populationValidationAccuracy = []; |
| 20. | For i in range (numIterations): |
| 21. | For j in range (numPopulation): |
| 22. | GXGBoostModel = populationGXGBoost [j];//Evaluating population |
| 23. | validationAccuracy = evaluateGXGBoost (GXGBoostModel, TrainingSet, ValidationSet); |
| 24. | populationValidationAccuracy.append (validationAccuracy); |
| 25. | If validationAccuracy > maxAccuracy: |
| 26. | maxAccuracy = validationAccuracy; |
| 27. | bestModel = GXGBoostModel; |
| 28. | End if |
| 29. | End for |
| //Creating the new generations from the current best GXGBoostModel | |
| 30. | For popIndex in range (numPopulation): |
| 31. | model_1 = populationGXGBoost [popIndex]; |
| 32. | model_1ValidationAccuracy = populationValidationAccuracy [popIndex]; |
| 33. | model_2 = bestModel; |
| 34. | model_2ValidationAccuracy = maxAccuracy; |
| //Creating the new generations with crossovers | |
| 35. | newModel = crossoverGXGBoost (model_1, model_1ValidationAccuracy, model_2, model_2ValidationAccuracy); |
| 36. | mutateGXGBoost (newModel);//Mutating the new generations |
| 37. | populationGXGBoost [popIndex] = newModel;//Replace current model |
| 38. | End for |
| 39. | End for |
| 40. | Return bestModel, maxAccuracy; |
| 41. | End |