# A Laser-Based Method for the Detection of Honey Adulteration
## 2 Materials and Methods
### Data Analysis  
The collected LIBS spectroscopic data were analyzed in the Python programming environment using the libraries Pandas, Numpy, and Scikit-Learn [41]. Pandas and Numpy were used to read the obtained spectroscopic data, while Scikit-Learn was used for the classification of the data. Three machine learning methods were used for analyzing the obtained LIBS spectra: one unsupervised (i.e., multidimensional scaling (MDS) [42]) and one supervised (i.e., linear discriminant analysis (LDA) [43] and extremely randomized trees (ERT) [44]).  
MDS is an unsupervised algorithm used to visualize LIBS spectroscopic data, taking into consideration their degree of resemblance. More specifically, MDS generates a matrix of distances between the raw data or objects, in pairs, and projects each object into an abstract Cartesian space of lower dimensionality compared to the dimensions of the raw data objects, so achieving the dimensionality reduction of a given dataset, where the spectroscopic data points are plotted, initially in a three-dimensional, and then in a two-dimensional, scatter plot, to visualize the LIBS data).  
LDA is a supervised algorithm, which is used as a classifier and/or as a dimensionality reduction technique. LDA implements a linear decision boundary, which is generated by fitting class conditional densities, such as the Gaussian density, to the data. These data are sorted to certain classes and the LDA model assumes that all classes share the same covariance matrix. In the present work, LDA is used both as a classifier (i.e., to generate a predictive model) and as a dimensionality reduction technique as well. In more detail, for the development of the LDA model, the training dataset was used, and the training procedure was performed by k-fold cross-validation. k was chosen to have a value of 10, and the training data were shuffled and split into k groups. The k-1 groups were used to train the classifier, while the remaining group was used for assessing the predictive ability of the classifier, by computing its classification accuracy. All of the k subsamples were used for prediction and the procedure was repeated k-times, with the total accuracy of the classifier being derived from the averaging of the accuracies of each fold, thus evaluating the standard deviation of the classifier's overall accuracy. Furthermore, the predictive ability of the LDA model was tested via external validation, by predicting the test set described in Section 2.1, concluding that the prediction accuracy of the LDA model is evaluated by the confusion matrix, which is a specific table layout used to verify how much of the data were correctly classified. In this table, the columns represent the actual classes of the samples and the rows represent the classes predicted by the model. Its diagonal elements indicate the number of spectra that were predicted correctly.  
Extremely randomized trees (ERT) were used for assessing the feature importances by using the experimental LIBS spectra as inputs. This method natively describes the importance of each feature to the classification result. Feature importance refers to techniques that assign a score to the input features based on how useful they are in predicting a target variable.  
Following the first approach for classification, spectra from 33 samples were used for training the algorithms, and spectra from 12 samples for external validation. As a result, the LIBS raw dataset for training consisted of a data matrix of 1650 rows and 2751 columns, while the external validation dataset consisted of a data matrix of 600 rows and 2751 columns. For the second approach, spectra from 30 samples were used for training the algorithms and spectra from 15 samples for external validation. As a result, the LIBS raw dataset for training consisted of a data matrix of 1500 rows and 2751 columns, while the external validation dataset consisted of a data matrix of 750 rows \(\times\) 2751 columns.