%0 Journal Article %@ 1438-8871 %I JMIR Publications %V 27 %N %P e63962 %T Emotion Forecasting: A Transformer-Based Approach %A Paz-Arbaizar,Leire %A Lopez-Castroman,Jorge %A Artés-Rodríguez,Antonio %A Olmos,Pablo M %A Ramírez,David %+ Signal Theory and Communications Department, Universidad Carlos III de Madrid, Av. de la Universidad, 30, Leganés, 28911, Spain, 34 91 624 9157, lpaz@pa.uc3m.es %K affect %K emotional valence %K machine learning %K mental disorder %K monitoring %K mood %K passive data %K Patient Health Questionnaire-9 %K PHQ-9 %K psychological distress %K time-series forecasting %D 2025 %7 18.3.2025 %9 Original Paper %J J Med Internet Res %G English %X Background: Monitoring the emotional states of patients with psychiatric problems has always been challenging due to the noncontinuous nature of clinical assessments, the effect of the health care environment, and the inherent subjectivity of evaluation instruments. However, mental states in psychiatric disorders exhibit substantial variability over time, making real-time monitoring crucial for preventing risky situations and ensuring appropriate treatment. Objective: This study aimed to leverage new technologies and deep learning techniques to enable more objective, real-time monitoring of patients. This was achieved by passively monitoring variables such as step count, patient location, and sleep patterns using mobile devices. We aimed to predict patient self-reports and detect sudden variations in their emotional valence, identifying situations that may require clinical intervention. Methods: Data for this project were collected using the Evidence-Based Behavior (eB2) app, which records both passive and self-reported variables daily. Passive data refer to behavioral information gathered via the eB2 app through sensors embedded in mobile devices and wearables. These data were obtained from studies conducted in collaboration with hospitals and clinics that used eB2. We used hidden Markov models (HMMs) to address missing data and transformer deep neural networks for time-series forecasting. Finally, classification algorithms were applied to predict several variables, including emotional state and responses to the Patient Health Questionnaire-9. Results: Through real-time patient monitoring, we demonstrated the ability to accurately predict patients’ emotional states and anticipate changes over time. Specifically, our approach achieved high accuracy (0.93) and a receiver operating characteristic (ROC) area under the curve (AUC) of 0.98 for emotional valence classification. For predicting emotional state changes 1 day in advance, we obtained an ROC AUC of 0.87. Furthermore, we demonstrated the feasibility of forecasting responses to the Patient Health Questionnaire-9, with particularly strong performance for certain questions. For example, in question 9, related to suicidal ideation, our model achieved an accuracy of 0.9 and an ROC AUC of 0.77 for predicting the next day’s response. Moreover, we illustrated the enhanced stability of multivariate time-series forecasting when HMM preprocessing was combined with a transformer model, as opposed to other time-series forecasting methods, such as recurrent neural networks or long short-term memory cells. Conclusions: The stability of multivariate time-series forecasting improved when HMM preprocessing was combined with a transformer model, as opposed to other time-series forecasting methods (eg, recurrent neural network and long short-term memory), leveraging the attention mechanisms to capture longer time dependencies and gain interpretability. We showed the potential to assess the emotional state of a patient and the scores of psychiatric questionnaires from passive variables in advance. This allows real-time monitoring of patients and hence better risk detection and treatment adjustment. %R 10.2196/63962 %U https://www.jmir.org/2025/1/e63962 %U https://doi.org/10.2196/63962