Coffee is one of the most popular and frequently consumed beverages on the planet. Coffee has a significant commercial value, estimated to be in the billions of dollars and consumption has risen steadily over the last two decades. Near-infrared spectroscopy is one of the non-destructive optical technologies for the evaluation of agricultural products to identify food adulteration. Thus, it is an interesting and worthwhile subject to research and study. In this research, a near-infrared spectroscopy approach along with statistical methods of principal component analysis (PCA), partial-least-squares regression (PLSR), latent dirichlet allocation (LDA), and artificial neural network (ANN) as a fast and non-destructive method was used with to detect and classify coffee beans using reference data obtained by gas chromatography–mass spectrometry (GC–MS). Results showed that the accuracy of PLSR, LDA, and ANN while our reference data was palmitic acid, respectively were 97.3%, 97.92%, and 97.3% and while reference data was caffeine, accuracy results were 94.71%, 95.83%, and 98.96%, respectively.