Attention is constantly required in many daily life tasks. Attention-related behavior, such as driving distraction, has been reported as a major reason in traffic accidents. Therefore, the recognition of attention can enhance task performance. Electroencephalogram (EEG) is used to study attention, since it provides a direct measure of the brain activity with high temporal resolution at 1-10ms. In this thesis, we study the recognition of selective attention and sustained attention (vigilance) using machine learning. We start by proposing an experiment which aims to recognize unattended and attended conditions induced by Test of Variables of Attention (TOVA), using EEG features supported by the event-related potential (ERP) literature. However, ERP does not work for real-time applications where the external stimuli (event) required by ERP cannot be controlled. In face of the low signal-to-noise ratio (SNR) in the non-ERP approach, we propose Channel Selection with Different Features (CSDF) algorithm, which selects channels with their own different feature sets, as well as restricts features to as few channels as possible. Using CSDF, 83 out of 868 features are selected to distinguish the unattended and attended conditions. The accuracy 94.3% (±5.6%) is the best compared to other feature selection and channel selection algorithms. Based on CSDF, we find that the first and second order difference in the left parietal and temporal lobes, as well as the Higuchi fractal dimension and mean signal amplitude in the right frontal lobe, are relevant to selective attention. Unlike selective attention which has discrete conditions such as attended/unattended, the vigilance stages cannot be easily observed. Analogous to sleep stages, we want to define the vigilance stages in open eye and situation-aware state in a subject-independent and vii SUMMARY SUMMARY data-driven way. In the literature, there are vigilance stage models defined under closed eye. However, the EEG signals are more complex in open eye and situation-aware state. Extreme learning machine autoencoder (ELMAE) is used to learn the EEG spectral features and define the vigilance stages during simulated driving. Results show that ELMAE is an efficient alternative to restricted Boltzmann machine (RBM) in vigilance recognition: ELMAE achieves root mean square error at 0.189 (±0.049), which is better than RBM at 0.195 (±0.046); and training speed significantly faster than RBM. Based on ELMAE, we define three vigilance stages in open eye and situation-aware state. Stage I is high vigilance, where the subject is attentive. Stage II is low vigilance, which is further divided into Stage II.1: drowsiness and difficulty in attention allocation; and Stage II.2: distraction instead of falling asleep. A possible explanation for stage II.2 is that, the environment contains not enough external stimuli to keep the open eye and situation-aware state, so that the brain performs vigilance regulation to seek external stimuli, and hence leading to distraction. A major limitation of ELMA...