# Advancing Visible Spectroscopy through Integrated Machine Learning and Image Processing Techniques
## 3 Methodology
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Steps** & **Code** & **Comment** \\ \hline
1. & X\_train, X\_test, y\_train, y\_test = train\_test\_split & Splitting the data into training and testing sets \\
2. & poly\_reg = PolynomialFeatures (degree = 6) & Creating polynomial features with specified degree \\
3. & X\_poly = poly\_reg\_fit\_transform (X\_train) & Transforming the training features into polynomial features \\
4. & pol\_reg = LinearRegression () & Initialising linear regression model \\
5. & pol\_reg\_fit (X\_poly, y\_train) & Fitting the polynomial features to the target variable \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Code snippet of polynomial regression. in the dataset. Remarkably, the 6 th-degree polynomial regression model demonstrates improved performance, exhibiting better alignment with the dataset and reduced errors compared to lower-degree models. This highlights the importance of selecting an appropriate model complexity to accurately represent the underlying data distribution. The successful implementation of the 6 th-degree polynomial regression model lays the groundwork for further advancements in the research. With an effective mathematical model in place, the next step involves integrating machine learning algorithms to enhance the spectroscopic analysis process. Specifically, the developed model serves as a basis for training machine learning algorithms to predict dominant wavelengths based on hue values extracted from input images. By combining polynomial regression with machine learning algorithms, the proposed methodology offered a framework for visible spectroscopy. This integrated approach leverages the strengths of both techniques, enabling accurate and efficient analysis of spectral data. The ML algorithms were integrated into another algorithm, which calculated the corresponding wavelength values based on hue values extracted from images of different vapours. The hue value is calculated using OpenCV framework. OpenCV calculates the hue value of an image using the HSV (Hue, Saturation, Value) colour space. In this colour space, hue represents the dominant wavelength of light, effectively denoting the colour itself. To calculate the hue value of an image, OpenCV first converts the image from the default BGR (Blue, Green, Red) colour space to HSV. This conversion separates the colour information from the brightness and intensity components, facilitating easier manipulation and analysis of colours. Once the image is in the HSV colour space, OpenCV extracts the hue component, which ranges from 0 to 179 degrees or 0 to 255, depending on the data type used. This hue component is essentially a measure of the colour's position on the colour wheel, with red at 0 degrees, green at 120 degrees, and blue at 240 degrees. By isolating the hue component, OpenCV effectively quantifies the colour of each pixel in the image, providing a numerical representation of its hue. This combined approach enabled the ML model to accurately predict the dominant wavelengths associated with the hue values obtained from the input images. In simpler terms, the algorithm processed the images to extract hue values, which were then fed into the ML model to determine the corresponding wavelengths, as shown in Figure 1. This allowed the system to effectively analyse various vapour sources and provide accurate spectral information based on the visual data input. Figure 1: Process flow of the work. In this study, machine learning algorithms were seamlessly integrated into an image processing framework, orchestrating the extraction of hue values from images capturing different vapours. This synergistic approach facilitated the ML model's ability to make precise predictions regarding the predominant wavelengths corresponding to these hue values derived from the input imagery.