# Olive Oils Classification via Laser-Induced Breakdown Spectroscopy
## 2 Materials and Methods
### Data Analysis  
For the analysis of the LIBS spectroscopic data collected from the different olive oils, some machine learning techniques were selected, employed and assessed for this kind of input data set, i.e., LIBS spectral data, using the Python library Scikit-learn [28]. Among the different machine learning algorithms applied, were the Principal Component Analysis (PCA) [29], the Linear Discriminant Analysis (LDA) [30], the k-Nearest Neighbors (k-NN) [31] and the Support Vector Classifiers (SVC) [32]. Briefly, the PCA is an unsupervised machine learning technique well known for its efficiency for dimensionality reduction of large data sets while maintaining most of the initial information. To accomplish this task, PCA uses an orthogonal transformation to convert the initial dataset (i.e., the LIBS spectra here) into a set of uncorrelated variables, namely the Principal Components (PCs), where the first principal component, PC1, has the largest possible variance, and each succeeding component, in turn, has the highest possible variance under the constraint that it is orthogonal to the preceding components. These variables can be plotted and, thus, the original dataset can be visualized based on its variance, providing a simple and straightforward approach for the visual inspection of the classes. Oppositely to the PCA algorithm, LDA is a supervised algorithm. It is commonly used for dimensionality reduction problems as a pre-processing step for machine learning applications and for visualization purposes as well. As a supervised learning technique, it can be used as a classification algorithm, as well. LDA maximizes the ratio of the between-class variance over the within-class variance through a classifier with a linear decision boundary, generated by fitting class conditional densities to the data and using Bayes' theorem. The LDA model fits a Gaussian probability density to each class with the assumption that all classes share the same variance-covariance matrix. In addition to the LDA approach, two more supervised algorithms were employed in this work for the olive oils classification: the k-NN and SVC algorithms. In both k-NN and SVC classifications, the output is a class membership. In particular, in k-NN, an object is classified by a majority vote of its neighbors, with the object being assigned to the most common class among its k-nearest neighbors. In a different view, in SVC, each data point is viewed as a vector in a n-dimensional space with the value of each feature being the value of a coordinate. Then, SVC classification is performed by finding a hyper-plane that best differentiates the different classes. The supervised algorithms (LDA, k-NN and SVC) were applied both on raw and on pre-processed data. The latter ones were obtained by pre-processing using the PCA algorithm on the raw LIBS data and the resulting principal components were used as inputs for the classification algorithms. In general, such pre-treatment procedures result in effective reduction of the data dimensionality, and therefore, the subsequently used supervised techniques can be trained with much less inputs compared to the use of the raw (i.e., the un-treated) data, having a direct impact on the computational time without any significant loss of information. Moreover, the dimensionality reduction with PCA can act as a noise removal technique, since PCA has the ability to maintain only the features with the greater variation of the original data and principal components with low variance (e.g., may represent noise of a spectra) can be discarded. The maximum variance in the LIBS spectral data corresponds to the peaks (e.g., emission lines) which contain most of the information. For the model evaluation, the k-fold cross validation technique was implemented in the algorithmic training in order to ensure the stability of the algorithm and obtain the prediction accuracy with k = 5. For both the k-NN and SVC models, hyperparameter tuning was performed, ensuring robustness and preventing overfitting.