Research ArticleUnder Review

An Explainable Counterfactual and Agent-Assisted Machine Learning Framework for Emotion-Aware Digital Mental Well-Being Decision Support

A Random Forest reads seven social media usage habits to tell apart seven emotional states at 0.98 accuracy, explains each prediction with LIME and SHAP, and uses DiCE counterfactuals and a rule-based agent to suggest small changes toward a positive or stable state.

Muhammad Usman Tariq, Sheikh Muhammad Saqib, Muhammad Adnan Tariq, Ramy E. El Reqib, Tehseen Mazhar

Corresponding author: Tehseen Mazhar

Applied Computational Intelligence and Soft ComputingWiley2026
Accuracy
0.98
Optimised Random Forest, 40% held-out test split
F1-score
0.96–1.00
Range across the seven emotion classes
ROC AUC
≥ 0.995
Every class; 1.000 for four of the seven
Emotional states
7
Predicted from 7 social media usage features

Abstract

Digital behavior data derived from social media and online engagement offer new opportunities for computational mental well-being assessment, yet many existing prediction systems remain difficult to interpret and provide limited support for actionable intervention. In this study, we propose an explainable and prescriptive machine learning framework for emotion-aware digital mental well-being decision support, aligned with the goals of biomedical informatics and computer-based health support systems. The framework uses structured behavioral features, including age, platform type, daily usage time, posting activity, likes, comments, and messages, to classify seven emotional well-being states: Aggression, Anger, Anxiety, Boredom, Happiness, Neutral, and Sadness.

We developed an optimized Random Forest classifier as the predictive core, achieving 98% overall accuracy on the study dataset. To improve transparency and support interpretability in high-stakes health-related analytics, the framework integrates LIME and SHAP to provide local and global explanations of model behavior. We further incorporated a DiCE-based counterfactual module to identify minimal behavior changes associated with transitions from negative emotional states toward more stable or positive states. We operationalized these outputs through an agent-assisted recommendation layer that generates real-time, rule-based behavioral guidance.

The proposed framework advances beyond conventional black-box classification by combining prediction, interpretability, recourse generation, and decision support within a unified computational pipeline. The results indicate that structured digital-behavior features can support accurate emotion-aware well-being modeling, while the explainability and counterfactual components improve transparency and practical usability. This work contributes a deployable biomedical informatics framework for digital mental well-being monitoring and personalized behavioral support.

Overview

An explainable, prescriptive machine learning framework for digital mental well-being. It predicts a person's dominant emotional state from how they use social media, explains that prediction for the individual and across the whole dataset, finds the smallest behaviour changes that would move a negative state toward a positive or stable one, and turns the result into real-time guidance through a rule-based agent.

Key Contributions

  • 1Optimised Random Forest classifier that separates seven emotional well-being states (Aggression, Anger, Anxiety, Boredom, Happiness, Neutral, Sadness) from seven behavioural and social media usage features.
  • 2Dual explainability layer: LIME for instance-level reasoning behind each prediction and SHAP for global feature importance across the dataset.
  • 3DiCE-based counterfactual module that finds the minimal behaviour changes needed to move from a negative state to Happiness or Neutral, under realistic constraints such as age only staying the same or rising.
  • 4Agentic AI intervention module that turns predicted emotions and counterfactual suggestions into real-time, rule-based well-being recommendations.
  • 5One deployable pipeline that joins prediction, explanation, counterfactual recourse and automated intervention for digital mental well-being decision support.

Figures

Flow diagram: a dataset with seven independent features and a dominant-emotion label trains a machine learning model. The trained model outputs one of seven emotions, statistical analysis, LIME and SHAP analysis, and a DiCE model that modifies features to move Aggression, Anger, Anxiety, Boredom or Sadness to Happiness or Neutral. A user interface sends inputs to the DiCE model and the predictor, and the prediction flows into an Agentic AI suggestions box.
Figure 1. Proposed framework: seven usage features train a Random Forest. The trained model feeds statistical analysis, LIME and SHAP explanations, a DiCE counterfactual module that moves negative states toward Happiness or Neutral (age may only stay the same or rise, up to 60), and an Agentic AI layer that turns the prediction into suggestions.
Stacked horizontal bar chart of mean absolute SHAP value for seven features, coloured by classes 0 to 6. Comments_Received_Per_Day is longest at about 0.36, then Daily_Usage_Time at about 0.32 and Likes_Received_Per_Day at about 0.31, Age and Messages_Sent_Per_Day at about 0.29, Platform at about 0.21, and Posts_Per_Day shortest at about 0.19.
Figure 17. Global SHAP analysis: mean absolute SHAP value per feature, split by emotion class. Comments received per day has the largest overall impact, followed by daily usage time and likes received; posts per day has the least.
Left, an input form: age 26, platform Facebook, daily usage 75 minutes, 2 posts, 30 likes, 14 comments and 20 messages per day, with an 'Agentic AI Click Here' button. Right, the result panel: Predicted Emotion Category: Anxiety, with three recommendations: engage in mindfulness or guided meditation, break tasks into smaller steps to reduce stress, and reduce exposure to overwhelming notifications.
Figure 20. Case study 3: a 26-year-old Facebook user (75 minutes a day, 2 posts, 30 likes, 14 comments and 20 messages per day) is predicted as Anxiety, and the Agentic AI module recommends mindfulness, breaking tasks into smaller steps and fewer notifications.

Methodology

Seven behavioural features (age, platform, daily usage time, and posts, likes, comments and messages per day) are used to predict a user's dominant emotion across seven classes. The platform is encoded as a number, and an ANOVA test confirms every feature is significant (p < 0.05), with likes and comments received showing the largest effect.

The classes were highly imbalanced, so Random Oversampling brought every class to 257 samples before a 60/40 train-test split. An optimised Random Forest is the predictive core. LIME explains individual predictions and SHAP gives global feature importance.

A DiCE counterfactual module then searches for the closest feature vector the model classifies as Happiness or Neutral, with every feature kept inside its range and age allowed only to stay the same or rise (up to 60). Finally, an Agentic AI module applies 15 decision rules on the predicted emotion, age, platform, usage and engagement to produce personalised recommendations through a simple input form.

Datasets

Results & Findings

The optimised Random Forest reached 0.98 overall accuracy on the 40% held-out test split, with per-class F1-scores between 0.96 and 1.00. ROC AUC was 1.000 for four of the seven classes and no lower than 0.995 for the rest, and average precision was close to 1.000 for every class. The calibration curves stayed close to the diagonal, with small deviations for Anxiety and Sadness, so the confidence scores are a reasonable input for the recommendation layer.

SHAP ranked comments received per day as the most influential feature overall, followed by daily usage time and likes received; platform and posts per day mattered least. The DiCE case studies gave concrete recourse: for example, a 33-year-old Instagram user predicted as Aggression reaches Neutral with fewer posts (6 to 1), fewer messages (29 to 19) and slightly less daily use (140 to 135 minutes). The agent module produced matching recommendations for all seven emotional states.

Conclusion

Structured social media behaviour can predict emotional well-being states accurately, and pairing the prediction with LIME and SHAP explanations, DiCE counterfactual recourse and a rule-based agent turns a black-box classifier into a transparent, prescriptive decision-support tool. Its outputs are decision-support insights, not clinical diagnoses. Future work targets larger, longitudinal and multi-modal datasets, causal explanations, and recommendations that adapt to user feedback.

Author Affiliations

  1. 1Department of Marketing, Operations, and Information Systems, College of Business, Abu Dhabi University, Abu Dhabi, United Arab Emirates
  2. 2Department of Computing and Information Technology, Gomal University, Dera Ismail Khan 29050, Pakistan
  3. 3Department of Computer Engineering, COMSATS University Islamabad, Sahiwal Campus, Sahiwal 57000, Pakistan
  4. 4Department of Computer Science, Virtual University of Pakistan, Lahore 51000, Pakistan

Explore More Publications

Check out my other research publications in AI, machine learning, and emerging technologies.

View All Publications