Miniaturized silicon photonics spectrometers capable of detecting specific absorption features have great potential for mass market applications in medicine, environmental monitoring, and hazard detection. However, state-of-the-art silicon spectrometers are limited by fabrication imperfections and environmental conditions, especially temperature variations, since uncontrolled temperature drifts of only 0.1°C distort the retrieved spectrum precluding the detection and classification of the absorption features. Here we present a new strategy that exploits the robustness of machine learning algorithms to signal imperfections, enabling recognition of specific absorption features in a wide range of environmental conditions. We combine on-chip spatial heterodyne Fourier-transform spectrometers and supervised learning to classify different input spectra in the presence of fabrication errors, without temperature stabilization or monitoring. We experimentally show the differentiation of four different input spectra under an uncontrolled 10°C range of temperatures, about $ 100\times $100× increase in operational range, with a success rate up to 82.5% using state-of-the-art support vector machines and artificial neural networks.