# Sensory Perception Systems and Machine Learning Methods for Pesticide Detection in Fruits
## 2 Materials and Methods
### Data Processing  
To analyze the measurement acquired, data treatment was previously conducted on the information collected; these were normalized to give a similar scaled value and extract \begin{table}
\begin{tabular}{c c} \hline \(\mathbf{z}\) & **Assigned Value** \\ \hline Econd [V] & 0 \\ \hline Edep [V] & 0 \\ \hline Tcond [s] & 0 \\ \hline Tdep [s] & 0 \\ \hline Tequil [s] & 0.3 \\ \hline Ebegin [V] \\ \end{tabular} & 0 \\ \hline Evtx1 [V] & \(-1\) \\ \hline Evtx2 [V] & 1 \\ \hline Estep [V] & 0.01 \\ \hline Srate [V/s] & 0.05 \\ \hline Nscans & 1 \\ \hline \end{tabular}
\end{table} 
Table 3: E-tongue operation parameters. Figure 2: Operation diagram of E-nose: (**A**) cleaning phase, (**B**) measurement phase. the most relevant characteristics (minimum weight and maximum value of signals) to be later implemented by data processing algorithms. Therefore, for the data discrimination and classification process, different multivariate analysis methods such as PCA and LDA were used, and machine learning algorithms such as decision tree classifiers, linear discrimination, the naive Bayes method, quadratic SVM, cubic SVM, and the fine K-NN method; the previous two were applied with the respective kernel. The methods outlined in the previous sections were implemented using the \"Classification Learner\" interface in MATLAB 2020b. This tool significantly streamlined the development process for classification methods, providing an intuitive and efficient platform for selecting features, training models, and evaluating performance metrics. It was crucial to undertake a comprehensive process involving several key steps to effectively utilize machine learning algorithms through this tool for detecting fruit pesticides. First, a feature extraction technique based on two parameters was obtained for each signal: the maximum (max) and minimum (min) values of the signal (i.e., voltage for gas sensor signals and current for electrochemical responses), which represent the highest and lowest points that the signal reaches over a given period. This value provided a quantitative measure of the signal's variability, which was subsequently used for signal analysis by applying PCA and LDA methods and classification techniques, as described above. On the other hand, data normalization was applied to the dataset using the \"mean-centering\" and \"Auto-scaled\" algorithms to ensure that each feature contributes equally to the model. Then, these parameters were calculated by subtracting the mean or dividing by the standard deviation for each feature. Afterward, it was necessary to optimize the parameters of ML methods (decision tree classifiers, linear discrimination, naive Bayes, quadratic SVM, cubic SVM, and fine K-NN) and select appropriate hyperparameters (i.e., kernel) for each method, such as, for cubic SVM and fine K-NN, learning rates, and regularization parameters. Consequently, the models were refined through a meticulous process of fine-tuning. This involved iteratively adjusting the models based on feedback from initial training and validation runs to enhance their predictive accuracy and generalization capabilities. The training data were randomly divided into multiple subsets to validate the model's performance across different segments, and regularization helped control model complexity. For example, when k = 5, the dataset is split into five equal parts. Therefore, k-fold cross-validation divides the dataset into k subsets, and the model is trained and tested k times, each time using a different fold as the test set and the remaining folds as the training set. Afterward, test data were used with the trained model to assess the model's performance and generalization ability. These data were not used in any way during the training or validation phases. Each of the methods is briefly described below:  
* Principal Component Analysis (PCA): A supervised and unsupervised learning method in which observations or data are reordered by decreasing the correlation of all data and choosing new orthogonal axes for each component [60].