# Prediction of Cyanobacteria Using Decision Tree Algorithm and Sensor Monitoring Data
## 2 Research Method
### Data Acquisition
Additionally, we judged an explainable machine learning technique to be more advantageous than a black box model for predicting blue-green algae outbreaks [26; 27; 28]. It can capture the non-linear dependency between predictor and response variables [29]. Additionally, it is easier to use compared to deep learning-based models [30; 31]. With regard to parameters, it has a small number of model parameters, and the algorithm's default settings are appropriately configured, making it convenient to construct optimal parameters [32; 33]. In this study, the RandomForestRegressor, RandomForestClassifier, XGBoost, and CatBoost modules of the Scikit-learn package in Python (Version 3.9) were applied for the machine learning algorithm. The RF model has been verified to show improved prediction performance as a bagging ensemble model. [32; 33]. And compared to other algorithms, it is faster [34] and can effectively handle small sample sizes [32]. The boosting method of ensemble algorithms primarily aims to reduce the bias and variance in supervised learning problems. It is an ensemble meta-algorithm approach that seeks to enhance the predictive performance of multiple weak algorithms [35]. Boosting has often been more successfully implemented in challenging problems compared to the bagging (RF) approach [36]. While XGBoost remains the most popular algorithm, the creators of CatBoost claim that their solution is not only significantly faster but also provides better predictions [27]. Therefore, in this study, machine learning models were built using both the bagging RF method and the boosting methods XGBoost and CatBoost. To build the model, 70% of the total input data was used as training data and 30% as test data. Hyperparameters were optimized to achieve the optimal prediction performance of the model using GridSearchCV. The parameters applied to the model were as follows: To prevent overfitting, RF used gini, XGBoost used gamma, and Catboost used Learning_rate. Additionally, the maximum depth of the tree (max_depth) and the number of decision trees (n_estimators) were commonly optimized. In addition, the number of model execution times was set to 10, 101, and 10, and the most appropriate parameter combination was simulated using rank_test_score among the repeatedly performed models. Parameters such as'min_samples_split','min_samples_leaf','max_features', and'max_leaf_nodes' were used with their default values. The default value for the parameter 'n_estimators' was set to 10. This variable can be used to control performance and time. Increasing the number of trees can potentially improve performance, but it may also increase computation time. Finally, tests of accuracy and average cross-validation of accuracy were conducted to evaluate the model performance. Accuracy is a measure of how well a model correctly predicts the outcomes among all the problems, and it ranges from 0 to 1, with higher values closer to 1 indicating higher accuracy. The calculation is as described in Equation (1). \[Accuracy=\frac{TP+TN}{TP+TN+FP+FN} \tag{1}\]  
\(TP\) (true positive) represents cases where the model correctly predicts a positive outcome, _TN_ (true negative) represents cases where the model correctly predicts a negative outcome, _FP_ (false positive) represents cases where the model incorrectly predicts a positive outcome when the actual outcome is negative, and _FN_ (false negative) represents cases where the model incorrectly predicts a negative outcome when the actual outcome is positive. To assess the generalization of a trained algorithm, average cross-validation of accuracy is used. K-fold cross-validation is employed, where the entire dataset is divided into K folds. In each iteration, one of the K folds is used as the test data, while the remaining K-1 folds serve as the training data. This process is repeated, exchanging the train and test data, to evaluate the algorithm's performance.