The absence of verbal communication in some patients (e.g., critically ill, suffering from advanced dementia) difficults their pain assessment due to the impossibility to self-report pain. Functional near-infrared spectroscopy (fNIRS) is a non-invasive technology that has showed promising results in assessing cortical activity in response to painful stimulation. In this study, we used fNIRS signals to predict the state of pain in humans using machine learning methods. Eighteen healthy subjects were stimulated using thermal stimuli with a thermode, while their cortical activity was recorded using fNIRS. Bag-of-words (BoW) model was used to represent each fNIRS time series. The effect of different step sizes, window lengths, and codebook sizes was investigated to improve computational cost and generalization. In addition, we explored the effect of choosing different features as neurological biomarkers in three different domains: time, frequency, and time-frequency (wavelet). Classification on the histogram representation was performed using K-nearest neighbours (K-NN). The performance is evaluated by using leave-one-out cross validation and with different nearest neighbours. The results showed that wavelet-based features produced the highest accuracy (88.33 %) to distinguish between heat and cold pain while discriminate between low and high pain. It is possible to use fNIRS to assess pain in response to four types of thermal pain. However, future research is needed for the assessment of pain in clinical settings.