Migraine is a common and complex neurovascular disorder. Clinically, the diagnosis of migraine mainly relies on scales, but the degree of pain is too subjective to be a reliable indicator. It is even more difficult to diagnose the medication-overuse headache, which can only be evaluated by whether the symptom is improved after the medication adjustment. Therefore, an objective migraine classification system to assist doctors in making a more accurate diagnosis is needed. In this research, 13 healthy subjects (HC), 9 chronic migraine subjects (CM), and 12 medication-overuse headache subjects (MOH) were measured by functional near-infrared spectroscopy (fNIRS) to observe the change of the hemoglobin in the prefrontal cortex (PFC) during the mental arithmetic task (MAT). Our model shows the sensitivity and specificity of CM are 100% and 75%, and that of MOH is 75% and 100%.The results of the classification of the three groups prove that fNIRS combines with machine learning is feasible for the migraine classification.