Sitemap
Peter Liu

Peter Liu

Business Intelligence | Software Engineer | Data | Chemist

Scan-and-Bingo Approach for Product Authentication

12 min readJul 9, 2018

--

Recently I was at the mall with my wife, who spent most of her time in Sephora choosing lipsticks and face serums. I asked why she felt confident in buying certain cosmetic products.

“I go to trusted brands and expect that they won’t sell adulterated products,” she replied.

I asked her what else she takes into consideration.

“I can tell by the packaging, by smelling and touching the products. There are lots of YouTube videos out there to tell you what the real products should look and feel like,” she said.

I did not argue with my wife, but her judgments are purely based on physical properties of products. However, obtaining chemical information is crucial to evaluating product quality. So, how do you collect and evaluate the chemical information as proof of authentication?

One of the most common ways to authenticate chemical products is to collect samples and send them to certified labs for comprehensive analysis, but that’s inconvenient as well as time-consuming. What we want is a more reliable and efficient way to “red flag” those suspected counterfeits. This is especially crucial for product distributors such as Amazon, Walmart, Target, and Whole Foods, where they need a reliable way to verify the origin of products within a short period.

Herein, I designed a scan-and-bingo approach for product authentication: The first step is to use a handheld FTIR device to scan samples, delivering a immediate authentication prediction. I will use three examples — fruit, meat, and olive oil — to demonstrate how powerful the integration of FTIR with machine learning is as proof of authentication. The accuracy rate is higher than 98%! Moreover, this approach can tell us the key difference between authentic and adulterated products, and I will discuss the chemistry meanings behind this. (All the data are publicly available through Quadram Institute.)

Why do we choose FTIR to collect chemical information?

Fourier-transform infrared spectroscopy offers us with quick approach of collecting chemical information by hand-held scanning.

Hand-held FTIR used for quality control of surface coating of airplane

Unlike other common chemical analysis instruments such as HPLC, GC and Mass Spectrometry, FTIR analysis is non-destructive, meaning you can evaluate the chemical information without causing damage. More importantly, the FTIR devices are portable and less expensive, and are thus widely applied to collect spectra data on-site.

It works in three easy steps: 1. Light is generated; 2. Light is transmitted or reflected by the sample; and 3. Light is received and analyzed by the detector. The detector will analyze the difference of light intensity between emitted and received.

Portable Spectrometry collecting spectrum on-site

Below is one typical analysis result of PEG (polyethylene glycol, a common chemical used in cosmetic industry). It shows the light absorption as a function of wavenumber. The x-axis is the wavenumber, which represents the number of wavelength per centimeter. The higher the wavenumber is, the lower the wavelength is. The y-axis is the intensity of light absorbed at each wavenumber. If you are interested in the chemical meanings behind those peaks, please refer to SDBS database(Search compound name polyethylene glycol).

Press enter or click to view image in full size

While we can easily identify PEG by simple searching our spectrum within database, the spectrum tends to get complicated when FTIR is used to analyze products (mixtures of hundreds and thousands of chemicals). Therefore, in most cases, FTIR only serves as the crude product component analysis such as identification of functional groups (aldehyde, ketone, aromatics).

But FTIR has its own advantage as we mentioned previously: potable, fast, easy, non-destructive. Can we use it for product authentication? In the following examples, we will use machine learning tools to analyze FTIR spectra and see if we can use this crude analysis method to generate accurate prediction results.

I. Authentication of Strawberry Puree

Visit my Github for more details

This data set contains a collection of 983 Mid-infrared spectra collected from two different classes: 351 samples of “Strawberry” (purees prepared from fresh whole fruits by the researchers) and 632 samples of “NON-Strawberry” (diverse collection of other purees, including: strawberry adulterated with other fruits and sugar solutions; raspberry; apple; blackcurrant; blackberry; plum; cherry; apricot; grape juice and mixtures of these). I combined all the spectra and generated a data frame, with each row being one sample and labeled as 0 (adulterated) or 1 (authentic), and each column as signal intensity at individual wavenumber.

Press enter or click to view image in full size

After averaging the spectra of authentic (label 1)and adulterated strawberry (label 0) samples, it seems like there is significant difference between authentic and adulterated strawberry spectra at around 1200, 1600, and 1700 cm-1.

Press enter or click to view image in full size

So, what is the distribution of the data? Can we efficiently separate data into two classes (authentic and adulterated)? To help us view the sample distribution, I projected all the samples in the first two principal components space. The purple points represent the adulterated strawberry samples, and the yellow points represent the authentic strawberry samples. It is apparent that a “circle” boundary can efficiently separate these two classes, and thus flexible models is supposed to outperform linear models. We will discuss this later.

Using Principle Components Analysis (PCA), I can extract/reconstruct features that can efficiently explain the data variance. Instead of using 235 features for prediction, I can use only 4 reconstructed features (also know as eigenspectra) for the prediction, which already explained almost 98% of the variance. In other words, each original spectrum can be constructed using the linear combination of these 4 eigenspectra. Although the eigenspectra look creepy and are totally different from original spectra, we can still get some interesting information: Eigenspectrum 1 shows spectrum having higher intensity of peaks at 1200, 1600 and 1700 cm-1, while Eigenspectrum 2 shows spectrum with more information on regions below 1300 cm-1.

The following is the typical Python code to find out how many principal components should we use to get the highest accuracy of prediction. Our goal is to achieve the highest prediction accuracy with fewest number of principal components. Herein, I used random forest classifier to start with. The number of principal components ranged from 1 to 19, and for each case, data were split into training and testing sets, hyperparameters were tuned by GridSearch, and the prediction accuracy was appended to the score list. Thereafter, I compared the performance of three common models, including Random Forest, K Nearest Neighbors (KNN), and Supported Vector Classifier (SVC). It turned out SVC performed the best and 9 principal components rendered the highest accuracy at 97.6%.

Press enter or click to view image in full size
Typical Python code for selecting the number of principal components
Press enter or click to view image in full size

Previously, I mentioned a “circle” boundary could efficiently separate authentic and adulterated samples based on PCA features. But how exactly the linear model performed in this case?

Before we start, I would like to introduce confusion matrix that is commonly used for evaluating model performance. In the following table, the rows represent the real results (positive or negative), and the columns represent our prediction results (positive or negative). Our prediction could thus be separated into 4 classes (True Negative, True Positive, False Negative and False Positive). Herein, I used three parameters to evaluate the model performance: Accuracy, AUC, and F1-score, and I listed the definition of these concepts as refreshment.

Press enter or click to view image in full size
Elements for confusion matrix

Accuracy = (TN+TP)/(TN+TP+FP+FN);

Get Peter Liu’s stories in your inbox

Join Medium for free to get updates from this writer.

AUC : Area under ROC (TP rate vs. FP rate). It indicates how much confidence do we have to separate two classes;

F1-score: Harmonica average of precision and recall for separating two classes

The followings are comparison between linear models using Logistic model and SVC using radial kernel. For logistic model, because it tried to use straight line to separate two classes (whereas the samples cannot be separated by straight line), all samples were predicted as negative or adulterated samples. Notice here we not only had low accuracy of prediction, but also obtained AUC score of 0.5(same as random guess) and F1-score at 0. In comparison, SVC using radial kernal showed much better performance in every aspect. So it is always the best practice to use simple exploratory data analysis(EDA) to visualize our data before we implemented any model.

We observed several spectra misclassified. What do those misclassified spectra look like?

There are two types of misclassified samples: misclassifier authentic and misclassifier adulterated. The former ones are authentic samples predicted as adulterated samples, and the latter ones are adulterated samples predicted as authentic samples. It can be seen that misclassified authentic samples (blue) are far apart from the authentic strawberry samples (green) in lower region (1000–1100 cm-1) and higher region(1600–1800 cm-1), while misclassified adulterated samples(yellow) are very close to authentic strawberry samples (green). To reduce the prediction errors, we need a broader range of spectra or more training samples.

Press enter or click to view image in full size

What is the key difference between authentic and adulterated strawberry samples? Does it make sense in Chemistry?

Instead of using feature extraction, I used feature elimination to select the most important wavenumbers between authentic and adulterated samples. Tree method is a natural way of feature elimination, because tree is always splitting towards the largest Gini gain, which is heavily influenced by important features. I used random forest to select top 10 key wavenumbers to differentiate authentic and adulterated samples, shown as follows:

It is surprised to see the observed difference around 1700 cm-1 is not the key difference. In fact, this is true, because this region represents typical sugar C=O aldehydes/ketones signals(herein glucose or fructose signal), which are very easy to blend into samples. Meanwhile, it is indicated that 1550–1620 and 1180–1250 regions are within the top 10 regions determining the authentication of samples, which correspond to aromatic C=C double bonds and S=O bounds naturally occurred in authentic strawberry samples. The above two regions are “fingerprint” regions of strawberry purees that can differentiate the authentic samples from adulterated samples.

App Development for Product Authentication

This tool could be easily converted to App using dash and heroku as I demonstrated in earlier articles, where you can easily upload your FTIR spectrum, and the app will provide with prediction results.

For the next two examples, because they follow the exact procedures as Strawberry example, I will briefly mention on the key points. If you are interested, please visit my Github for more details.

II. Authentication of Fresh Meat

Visit my Github for more details

Herein, I demonstrated that machine learning tools can distinguish fresh meat (chicken, pork and turkey) in up to 100% accuracy based on FTIR spectra. This data set contains a collection of 120 Mid-infrared spectra collected from chicken, pork and turkey meat with 40 samples in each category. I combined all the spectra and generated a data frame, with each row being one sample and labeled as 1 (Chicken), 2 (Pork) or 3 (Turkey), and each column as signal intensity at individual wavenumber. After averaging the spectra of within each class, it seems like there is significant difference among three classes, especially at peaks between 1500 and 1650 cm-1.

Press enter or click to view image in full size

Using PCA, I can extract/reconstruct features that can efficiently explain the data variance. Instead of using 448 features for prediction, I can use only 1 reconstructed feature for the prediction, which explained almost 93% of the variance. I also projected all samples in the first two principal components space for visualization. The purple points represent chicken samples, the blue points represent pork samples, and the yellow points represent turkey samples. In this case, a linear boundary could efficiently separate these three classes, and thus I chose SVC and LDA (Linear Discriminate Analysis) model for comparison.

After optimization of number of principal components and hyperparameters, it turned out both SVC and LDA rendered high accuracy of prediction up to 100%. Feature elimination rendered by random forest confirmed our hypothesis that part of fingerprint wavenumbers for determining different types of meat distributed between 1500 to 1650 cm-1.

III. Authentication of Origin Country of Olive Oil

Visit my Github for more details

For certain products, such as wine, olive oil and honey, country of origin has great impacts on the taste, quality and value of the products. Taking olive oil as an example, according to official index of best olive oils, the top lists of olive oils are dominated by Mediterranean countries such as Spain, Italy, Greece and Portugal, where Asian countries rarely come to the top. However, the difference of taste and quality of olive oils from top producers are sometimes minimal, and even professionals are not able to tell the country of origin. Herein, I demonstrated that machine learning tools can distinguish the country of origin in up to 100% accuracy based on FTIR spectra.

I collected 120 Mid-infrared spectra from 60 different authenticated extra virgin olive oils, supplied to the Institute of Food Research, UK, by the International Olive Oil Council. This data set contains a collection of 20 samples are from Greece, 34 from Italy, 16 from Portugal and 50 from Spain. I combined all the spectra and generated a data frame, with each row being one sample and labeled as 1 (Greece), 2 (Italy), 3 (Portugal) or 4 (Spain), and each column as signal intensity at individual wavenumber. By averaging the spectra of within each class, it seems like the four types of spectra were largely overlapped, except for the region between 1700 to 1730 cm-1.

Press enter or click to view image in full size

Using PCA, I can extract/reconstruct features that can efficiently explain the data variance. Instead of using 570 features for prediction, I can use only 6 reconstructed features for the prediction, which explains 95% of the variance. I also projected samples in the first two principal components space for visualization. The purple points represent samples from Greece, the blue points represent samples from Italy, the green points represent samples from Portugal and the yellow points represent samples from Spain. In this case, a non-linear boundary could efficiently separate four classes, and thus I chose SVC, KNN and Random Forest model for comparison.

After optimization of number of principal components and hyperparameters, it turned out SVC rendered high accuracy of prediction up to 100%. Top 10 selected features by random forest confirmed our hypothesis that part of fingerprint wavenumbers for determining origin country of olive oil distributed between 1700 to 1730 cm-1.

Conclusion

Using three examples (i.g., fruit, meat and oil), I demonstrated that it is applicable to use scan-and-bingo approach as proof of authentication: Scan sample by hand-held FTIR and analyze by machine learning tools. A satisfactory high accuracy (>98%) was achieved, and this method also offered us with deep understandings on the key difference between samples. This toolkit is especially interesting for product distributors, such as Walmart, Target, and Wholefoods, for quick assessment of product quality.

Feeling inspired and interested? Please give me some claps and follow me on LinkedIn!

--

--

Peter Liu
Peter Liu

Written by Peter Liu

Business Intelligence | Software Engineer | Data | Chemist