Instrumentation & Measurement Magazine 24-4 - 44

Fig. 1. Spectra acquired using Raman spectroscopy (top) and after applying the four-step pre-processing (bottom). (a) On copper sulphate (antlerite Cu3
(b) On copper hydroxychloride (clinoatacamite Cu2(OH)3
Cl).
where the most important peaks are labelled, indicating the
bond to which they relate.
Principal Components Computation
After the pre-processing, it is possible to build the PCA model
and compute the principal components. As mentioned above,
this can be readily done using the Scikit-learn class called
sklearn.decomposition.PCA [11] that as input parameter allows
the user to choose the number of components to build the
model.
In order to show the capabilities of the PCA for spectra processing,
hereinafter a practical example is provided. Fourteen
Raman spectra of different copper sulphates (namely antlerite,
brochantite, chalcanthite, langite and orthoserpierite) are processed
to show the possibility of easily discriminating among
spectra that, at a first glance, could look very similar. All spectra
have been extracted from the RRuff database, an open
access library that provides a unique tool for researchers interested
in mineralogy and materials science [12], so the reader
can download them to carry out the processing independently
and then use this code to interpret his/her own data.
In Python environment, let the initial fourteen spectra be
in an array-like object (named all_data), in which the spectra
are stored after performing the pre-processing as previously
described. It is possible to apply dimensionality reduction of
this dataset, that has initial dimension of 14 × 1000, as follows:
from sklearn.decomposition import PCA as sklearnPCA
k=3
model_pca = sklearnPCA(n_components= k)
model_pca.fit(all_data)
eigenvalues = model_pca.transform(all_data)
First, the number of components for the model is chosen,
here k; then the model is fitted with the original dataset
44
(all_data) and eventually the original data (all_data) is projected
on the principal components just computed. This way
it is possible to calculate the final eigenvalues (with dimensions
m x k). The choice of the components' number in the first instruction
does not affect the subsequent computation, and the
eigenvectors will not be modified by the number of considered
components. However, it is a critical point because it affects the
total variance explained by the model: using a low number of
components could create a model that is not able to correctly fit
the acquired data, leading to not reliable results.
It is possible to start analyzing the obtained result computing
the per cent cumulative explained variance for the
considered components:
cev = np.cumsum(model_pca.explained_variance_ratio_)*100
As hinted previously, choosing the correct number of components
for the model is not trivial. First of all, it is necessary
to build a model that captures a sufficiently high fraction of
the initial variance, otherwise it would be not representative of
the acquired data set. Common advice is to reach at least 70%
or even 80% of the initial variance. Another important rule of
thumb is to add components only if they have an explained
variance of at least 4% or 5%, to avoid fitting noise instead of
spectra features.
In the described example, the trend for cumulative explained
variance is shown in Fig. 2. In this case, the best choice
would be probably to use the first three components in order
to avoid any over-fitting and also allow a prompt visual representation
of the data. As can be seen from the plot, the first
three components already account for almost 90% of the initial
variance, so the fourth and subsequent, capturing individually
less than 5% of the variance, can be omitted. At this point it is
possible to visualize the eigenvectors that, dealing with spectroscopic
data, show the main features present in the spectra:
IEEE Instrumentation & Measurement Magazine
June 2021
(SO4
)(OH)4
).

Instrumentation & Measurement Magazine 24-4

Table of Contents for the Digital Edition of Instrumentation & Measurement Magazine 24-4

No label
Instrumentation & Measurement Magazine 24-4 - No label
Instrumentation & Measurement Magazine 24-4 - Cover2
Instrumentation & Measurement Magazine 24-4 - 1
Instrumentation & Measurement Magazine 24-4 - 2
Instrumentation & Measurement Magazine 24-4 - 3
Instrumentation & Measurement Magazine 24-4 - 4
Instrumentation & Measurement Magazine 24-4 - 5
Instrumentation & Measurement Magazine 24-4 - 6
Instrumentation & Measurement Magazine 24-4 - 7
Instrumentation & Measurement Magazine 24-4 - 8
Instrumentation & Measurement Magazine 24-4 - 9
Instrumentation & Measurement Magazine 24-4 - 10
Instrumentation & Measurement Magazine 24-4 - 11
Instrumentation & Measurement Magazine 24-4 - 12
Instrumentation & Measurement Magazine 24-4 - 13
Instrumentation & Measurement Magazine 24-4 - 14
Instrumentation & Measurement Magazine 24-4 - 15
Instrumentation & Measurement Magazine 24-4 - 16
Instrumentation & Measurement Magazine 24-4 - 17
Instrumentation & Measurement Magazine 24-4 - 18
Instrumentation & Measurement Magazine 24-4 - 19
Instrumentation & Measurement Magazine 24-4 - 20
Instrumentation & Measurement Magazine 24-4 - 21
Instrumentation & Measurement Magazine 24-4 - 22
Instrumentation & Measurement Magazine 24-4 - 23
Instrumentation & Measurement Magazine 24-4 - 24
Instrumentation & Measurement Magazine 24-4 - 25
Instrumentation & Measurement Magazine 24-4 - 26
Instrumentation & Measurement Magazine 24-4 - 27
Instrumentation & Measurement Magazine 24-4 - 28
Instrumentation & Measurement Magazine 24-4 - 29
Instrumentation & Measurement Magazine 24-4 - 30
Instrumentation & Measurement Magazine 24-4 - 31
Instrumentation & Measurement Magazine 24-4 - 32
Instrumentation & Measurement Magazine 24-4 - 33
Instrumentation & Measurement Magazine 24-4 - 34
Instrumentation & Measurement Magazine 24-4 - 35
Instrumentation & Measurement Magazine 24-4 - 36
Instrumentation & Measurement Magazine 24-4 - 37
Instrumentation & Measurement Magazine 24-4 - 38
Instrumentation & Measurement Magazine 24-4 - 39
Instrumentation & Measurement Magazine 24-4 - 40
Instrumentation & Measurement Magazine 24-4 - 41
Instrumentation & Measurement Magazine 24-4 - 42
Instrumentation & Measurement Magazine 24-4 - 43
Instrumentation & Measurement Magazine 24-4 - 44
Instrumentation & Measurement Magazine 24-4 - 45
Instrumentation & Measurement Magazine 24-4 - 46
Instrumentation & Measurement Magazine 24-4 - 47
Instrumentation & Measurement Magazine 24-4 - 48
Instrumentation & Measurement Magazine 24-4 - 49
Instrumentation & Measurement Magazine 24-4 - 50
Instrumentation & Measurement Magazine 24-4 - 51
Instrumentation & Measurement Magazine 24-4 - 52
Instrumentation & Measurement Magazine 24-4 - 53
Instrumentation & Measurement Magazine 24-4 - 54
Instrumentation & Measurement Magazine 24-4 - 55
Instrumentation & Measurement Magazine 24-4 - 56
Instrumentation & Measurement Magazine 24-4 - 57
Instrumentation & Measurement Magazine 24-4 - 58
Instrumentation & Measurement Magazine 24-4 - 59
Instrumentation & Measurement Magazine 24-4 - 60
Instrumentation & Measurement Magazine 24-4 - 61
Instrumentation & Measurement Magazine 24-4 - 62
Instrumentation & Measurement Magazine 24-4 - 63
Instrumentation & Measurement Magazine 24-4 - 64
Instrumentation & Measurement Magazine 24-4 - 65
Instrumentation & Measurement Magazine 24-4 - 66
Instrumentation & Measurement Magazine 24-4 - 67
Instrumentation & Measurement Magazine 24-4 - 68
Instrumentation & Measurement Magazine 24-4 - 69
Instrumentation & Measurement Magazine 24-4 - 70
Instrumentation & Measurement Magazine 24-4 - 71
Instrumentation & Measurement Magazine 24-4 - 72
Instrumentation & Measurement Magazine 24-4 - 73
Instrumentation & Measurement Magazine 24-4 - 74
Instrumentation & Measurement Magazine 24-4 - 75
Instrumentation & Measurement Magazine 24-4 - 76
Instrumentation & Measurement Magazine 24-4 - 77
Instrumentation & Measurement Magazine 24-4 - 78
Instrumentation & Measurement Magazine 24-4 - 79
Instrumentation & Measurement Magazine 24-4 - 80
Instrumentation & Measurement Magazine 24-4 - 81
Instrumentation & Measurement Magazine 24-4 - 82
Instrumentation & Measurement Magazine 24-4 - 83
Instrumentation & Measurement Magazine 24-4 - 84
Instrumentation & Measurement Magazine 24-4 - 85
Instrumentation & Measurement Magazine 24-4 - 86
Instrumentation & Measurement Magazine 24-4 - 87
Instrumentation & Measurement Magazine 24-4 - 88
Instrumentation & Measurement Magazine 24-4 - 89
Instrumentation & Measurement Magazine 24-4 - 90
Instrumentation & Measurement Magazine 24-4 - 91
Instrumentation & Measurement Magazine 24-4 - 92
Instrumentation & Measurement Magazine 24-4 - 93
Instrumentation & Measurement Magazine 24-4 - 94
Instrumentation & Measurement Magazine 24-4 - 95
Instrumentation & Measurement Magazine 24-4 - 96
Instrumentation & Measurement Magazine 24-4 - 97
Instrumentation & Measurement Magazine 24-4 - 98
Instrumentation & Measurement Magazine 24-4 - 99
Instrumentation & Measurement Magazine 24-4 - 100
Instrumentation & Measurement Magazine 24-4 - 101
Instrumentation & Measurement Magazine 24-4 - 102
Instrumentation & Measurement Magazine 24-4 - 103
Instrumentation & Measurement Magazine 24-4 - 104
Instrumentation & Measurement Magazine 24-4 - 105
Instrumentation & Measurement Magazine 24-4 - 106
Instrumentation & Measurement Magazine 24-4 - 107
Instrumentation & Measurement Magazine 24-4 - 108
Instrumentation & Measurement Magazine 24-4 - 109
Instrumentation & Measurement Magazine 24-4 - 110
Instrumentation & Measurement Magazine 24-4 - 111
Instrumentation & Measurement Magazine 24-4 - 112
Instrumentation & Measurement Magazine 24-4 - 113
Instrumentation & Measurement Magazine 24-4 - 114
Instrumentation & Measurement Magazine 24-4 - 115
Instrumentation & Measurement Magazine 24-4 - 116
Instrumentation & Measurement Magazine 24-4 - 117
Instrumentation & Measurement Magazine 24-4 - 118
Instrumentation & Measurement Magazine 24-4 - 119
Instrumentation & Measurement Magazine 24-4 - 120
Instrumentation & Measurement Magazine 24-4 - Cover3
Instrumentation & Measurement Magazine 24-4 - Cover4
https://www.nxtbook.com/allen/iamm/26-6
https://www.nxtbook.com/allen/iamm/26-5
https://www.nxtbook.com/allen/iamm/26-4
https://www.nxtbook.com/allen/iamm/26-3
https://www.nxtbook.com/allen/iamm/26-2
https://www.nxtbook.com/allen/iamm/26-1
https://www.nxtbook.com/allen/iamm/25-9
https://www.nxtbook.com/allen/iamm/25-8
https://www.nxtbook.com/allen/iamm/25-7
https://www.nxtbook.com/allen/iamm/25-6
https://www.nxtbook.com/allen/iamm/25-5
https://www.nxtbook.com/allen/iamm/25-4
https://www.nxtbook.com/allen/iamm/25-3
https://www.nxtbook.com/allen/iamm/instrumentation-measurement-magazine-25-2
https://www.nxtbook.com/allen/iamm/25-1
https://www.nxtbook.com/allen/iamm/24-9
https://www.nxtbook.com/allen/iamm/24-7
https://www.nxtbook.com/allen/iamm/24-8
https://www.nxtbook.com/allen/iamm/24-6
https://www.nxtbook.com/allen/iamm/24-5
https://www.nxtbook.com/allen/iamm/24-4
https://www.nxtbook.com/allen/iamm/24-3
https://www.nxtbook.com/allen/iamm/24-2
https://www.nxtbook.com/allen/iamm/24-1
https://www.nxtbook.com/allen/iamm/23-9
https://www.nxtbook.com/allen/iamm/23-8
https://www.nxtbook.com/allen/iamm/23-6
https://www.nxtbook.com/allen/iamm/23-5
https://www.nxtbook.com/allen/iamm/23-2
https://www.nxtbook.com/allen/iamm/23-3
https://www.nxtbook.com/allen/iamm/23-4
https://www.nxtbookmedia.com