0% found this document useful (0 votes)
5 views8 pages

Sentiment Analysis for Depression Detection

This project focuses on using sentiment analysis to detect signs of depression from social media texts and developing a chatbot that provides emotional support. The research evaluates various machine learning models, with XGBoost achieving the highest accuracy of 80% for classifying mental health conditions. The chatbot is designed to interact with users, offering supportive feedback based on their emotional state as determined by the sentiment analysis model.

Uploaded by

souleymane
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Sentiment Analysis for Depression Detection

This project focuses on using sentiment analysis to detect signs of depression from social media texts and developing a chatbot that provides emotional support. The research evaluates various machine learning models, with XGBoost achieving the highest accuracy of 80% for classifying mental health conditions. The chatbot is designed to interact with users, offering supportive feedback based on their emotional state as determined by the sentiment analysis model.

Uploaded by

souleymane
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ASSIGNMENT [X] ON [COURSE NAME]

Student’s Code Deadline

[Your Code] [Date, Time]

3 mai 2025 2024-2025

Lecturer: Cheikh Bamba Dione

1 Introduction
Today, many students and workers feel stressed because of too much work, short
deadlines, and everyday problems. These situations can lead to mental health issues, like
depression or anxiety, which are not always easy to detect or talk about. Many people stay
silent because they are afraid of being judged or don’t know who to talk to. Social media
has become a space where people can share their feelings more freely and anonymously.
These posts can help identify if someone might be going through a hard time.
In this project, we want to build a model that looks at social media texts to check if
someone might be depressed, using sentiment analysis. We also plan to add this model
into a smart chatbot that gives emotional support and simple advice to users.

Problem Statement
How can we use sentiment analysis to detect signs of depression or other mental
health issues from written messages, and build a chatbot that can understand if the user
is depressed or not, and give them some recommendations ?

Objectives and Motivation


Our project has two main goals :
— Build a good sentiment analysis model to automatically detect signs of depres-
sion from social media messages ;
— Add this model to an interactive chatbot that can simulate a short support conver-
sation and give useful suggestions if needed.
This solution uses Natural Language Processing (NLP) and machine learning
techniques. It aims to be accurate, easy to use, and helpful for public health.
We are motivated by :
— The large amount of text data shared on social media ;
— The urgent need to address mental health, especially in low-resource areas.

Research Questions
— Which machine learning model works best to detect mental health problems in text ?
— What words or features in text are good indicators of depression ?
— Can a simple chatbot have meaningful and helpful conversations with users ?

[Link] 1418 Mbour-Thies, phone (+221) 33 956 7693, [Link] Page 1 of 8


Structure of the Report
— Section 2 : Techniques used, data and how the model was built ;
— Section 3 : Model evaluation and results ;
— Section 4 : Discussion, limitations, and future improvements ;
— Section 5 : References.

2 Methodology
Our work is primarily based on the use of sentiment analysis techniques and the
development of a chatbot. In this section, we describe the data used and then present
these two approaches in detail, as they form the core of our methodology.

2.1 The techniques used


For our project, we use two main techniques. First, we apply sentiment analysis to
assess the user’s emotional state. Then, we use machine learning classification methods to
predict whether the person is depressive or not. Based on the prediction, we implement a
chatbot that interacts with the user and provides advice or support if depressive symptoms
are detected.

2.1.1 Sentiment analysis


Definition Sentiment analysis, or opinion mining, is the process of analyzing large vo-
lumes of text to determine whether it expresses a positive sentiment, a negative sentiment
or a neutral sentiment.
Companies now have access to more data about their customers than ever before,
presenting both an opportunity and a challenge : analyzing the vast amounts of textual
data available and extracting meaningful insights to guide their business decisions.
— Why is sentiment analysis important ?
With more ways than ever for people to express their feelings online, organizations
need powerful tools to monitor what’s being said about them and their products and
services in near real time. As companies adopt sentiment analysis and begin using
it to analyze more conversations and interactions, it will become easier to identify
customer friction points at every stage of the customer journey.
— Deliver more objective results from customer reviews
— Achieve greater scalability of business intelligence programs
— Perform real-time brand reputation monitoring
In our project, we use sentiment analysis to evaluate the user’s emotional state
based on what they write on social media, in order to determine whether they
show signs of depression or not.
— Machine learning sentiment analysis
With a machine learning (ML) approach, an algorithm is used to train software to
gauge sentiment in a block of text using words that appear in the text as well as
the order in which they appear. Developers use sentiment analysis algorithms to
teach software how to identify emotion in text similarly to the way humans do. ML

[Link] 1418 Mbour-Thies, phone (+221) 33 956 7693, [Link] Page 2 of 8


models continue to “learn” from the data they are fed.

Here are classification algorithms we used :


— Naive Bayes : An algorithm that uses Bayes’ theorem to categorize words in
a block of text.
— Logistic regression : Logistic regression is a supervised machine learning algo-
rithm widely used for binary classification tasks, such as identifying whether
an email is spam or not and diagnosing diseases by assessing the presence or
absence of specific conditions based on patient test results.
— Decision tree : A decision tree is a decision support recursive partitioning
structure that uses a tree-like model of decisions and their possible conse-
quences, including chance event outcomes, resource costs, and utility.
— XGBoost : It is an implementation of gradient boosting that is specifically
designed to be efficient and scalable, making it a popular choice for working
with large datasets. Mathematically, XGBoost is an ensemble learning method
that combines the predictions of multiple weak models to produce a strong
prediction.

2.1.2 Chatbot technique


— Definition
Chatbots are computer programs that simulate human conversation, written or spo-
ken. These days, chatbots are starting to integrate conversational AI, such as natural
language processing (NLP), to understand questions even if it isn’t grammatically
correct and then respond based on data it has collected.
A chatbot may prompt you to ask a question or describe a problem, to which it
will either clarify what you said or provide a response. Some chatbots are simple,
responding only to the question asked. Some are sophisticated, learning information
about you based on data collected and evolving to better assist you over time.
— Types of chatbot
Chatbot type is determined by its capabilities. Declarative chatbots are more basic
than predictive chatbots.
— Declarative chatbots perform one function. These chatbots use NLP, defined
rules, and ML to generate automated responses when you ask a question.
— Predictive chatbots Predictive chatbots are more sophisticated and personali-
zed than declarative chatbots.
In our project, we built a predictive chatbot that interacts with users and gives them
advice to support and improve their mental health.

2.2 Data and Resources


2.2.1 Why did we choose this dataset ?
We selected this dataset due to the high quality of its annotations : the labels are
clearly defined, which greatly facilitates supervised learning. It also offers a rich set of
variables, containing relevant information that allows the extraction of useful features
for the classification task. Moreover, its size is sufficient to train a machine learning

[Link] 1418 Mbour-Thies, phone (+221) 33 956 7693, [Link] Page 3 of 8


model effectively, minimizing the risk of overfitting while ensuring good generalization
capacity.

2.2.2 Dataset Description


Source : Dataset from Kaggle (Depression and Mental Health Dataset).

Format : CSV file

Size : The dataset contains 53,042 observations and 2 variables.

Classes : 7 categories representing different mental disorders or emotional states.

Figure 1 – Distribution of Mental Health Conditions

Preprocessing steps :
— Handling of missing values :
In our dataset, we found 362 missing values in the Statement variable. Since this
represents a very small portion of the 53042 observations, we simply removed them.
— Tokenization and stemming :
We Apply word tokenisation to have our text in token form and we write a function
to stem tokens and convert them to strings
— Removing stopwords and converting text to lowercase ;
— Vectorization using TF-IDF :
The texts are vectorized using the TF-IDF method, which captures the relative
importance of words in the corpus. Two manual features (text length and number
of sentences) are added to enrich the representations.
— Word Clouds Token Virtualization
We generate word clouds to visualize the most frequent words associated with each
sentiment (positive, negative, neutral) across different states.

[Link] 1418 Mbour-Thies, phone (+221) 33 956 7693, [Link] Page 4 of 8


2.2.3 Modelization
Data split : 80% for training and 20% for testing, using stratified sampling to pre-
serve class proportions.
After splitting our dataset, we tested four supervised machine learning algorithms : De-
cision Tree, Naive Bayes, Logistic Regression, and XGBoost. The goal was to predict
whether the user is in a depressive state or not, based on the text they write to express
how they feel.

3 Evaluation
3.1 Experimental results
We evaluated the performance of the four models on the multi-class classification task.
To evaluate each model, we used four evaluation metrics : accuracy, precision, recall, and
F1-score, as well as the confusion matrix.
— Naive Bayes

[Link] 1418 Mbour-Thies, phone (+221) 33 956 7693, [Link] Page 5 of 8


— Decision Tree

— Logistic Regression

— XGBoost

[Link] 1418 Mbour-Thies, phone (+221) 33 956 7693, [Link] Page 6 of 8


3.2 Models comparaison

Table 1 – Performances des modèles sur la classification multi-classe

Modèle Accuracy Précision Recall F1-score


Decision Tree 0.62 0.65 0.64 0.64
Naive Bayes 0.64 0.60 0.59 0.60
Logistic Regression 0.76 0.70 0.70 0.70
XGBoost 0.80 0.76 0.75 0.76

Figure 2 – Best model

3.3 Performance analysis and discussion


The XGBoost model outperformed all other algorithms, achieving an accuracy of 80%,
which confirms its robustness for multi-class text classification. Therefore, we chose XG-
Boost for the rest of our work. We trained the model to predict whether a user is in a
depressive state or not, based on a given input text.

3.4 Binary simplification : depressive vs. non-depressive


To make the chatbot more accessible and practical, we simplified the task to binary
classification. The original 7 labels were grouped into two categories :
— Depressive : Stress, Anxiety, Bipolar Disorder, Depression, Suicidal, Personality
Disorder
— Non-depressive : Normal

[Link] 1418 Mbour-Thies, phone (+221) 33 956 7693, [Link] Page 7 of 8


3.5 Chatbot demonstration
To complete the evaluation of our model, we show some screenshots of the chatbot in
action. These examples help to see how our classification model is used in a simple text-
based conversation. The chatbot can detect if a user is depressed based on the message
they write, and then give a helpful or supportive reply. These screenshots show that the
model works well, not only in theory, but also in a real-world situation.

Chatbot Interface
Chatbot Interface

4 Conclusion
In this project, we explored how sentiment analysis can help detect mental health
issues, especially depression, from short written messages. We used a labeled dataset
from social media and tested four machine learning models. Among them, the XGBoost
model gave the best results, with an accuracy of 80% in the multi-class task. We then
simplified the task into a binary classification to make the system more practical for real
use.
We also built a simple chatbot that uses this model to detect if a user is depressed or
not, based on what they write. The chatbot gives supportive feedback to the user. This
shows how a machine learning model can be used not only to classify text, but also to
support users in need.
Through this work, we learned how to clean and prepare text data, train and evaluate
models, and apply the results in an interactive system. Our main research question was :
Can we design a chatbot that analyzes text messages to detect mental distress such as
depression ? Based on our results, the answer is yes.
In the future, we could improve the chatbot by using more advanced NLP models or
by adding more personalized responses.

References
— Kaggle. Depression and Mental Health Dataset. Retrieved from [Link]
com/datasets
— IBM. Article about Sentiment Analysis. Retrieved from [Link]
think/topics/sentiment-analysis
— IBM. Article about Chatbots. Retrieved from [Link]
chatbots

[Link] 1418 Mbour-Thies, phone (+221) 33 956 7693, [Link] Page 8 of 8

Common questions

Powered by AI

The XGBoost model outperformed other machine learning models tested for predicting depressive states from text, achieving an accuracy of 80% . This performance surpasses that of Naive Bayes (64%), Decision Tree (62%), and Logistic Regression (76%) in multi-class classification tasks . Due to its robustness and high accuracy, the XGBoost model was selected for further implementation in the project .

Machine learning models significantly contributed to achieving the project's goals by providing a mechanism to automatically and accurately identify depressive symptoms from textual data. The application of models such as XGBoost, Naive Bayes, Logistic Regression, and Decision Tree allowed for extensive analysis of social media text and classification based on detected sentiment . Among these, XGBoost proved most effective, achieving an accuracy of 80%, making it the preferred model for its robustness and ability to handle the complexity of multi-class sentiment classification tasks . This effectiveness facilitated the project's aim of identifying mental health issues and supporting it within the chatbot system .

The project integrates machine learning with the chatbot by using sentiment analysis to evaluate user text for emotional states suggestive of depression. Machine learning algorithms such as XGBoost are employed to classify these emotional states as depressive or non-depressive. This classification enables the chatbot to recognize when a user might be experiencing depression and initiate supportive interactions, offering personalized advice and responses based on the user's detected emotional state . By leveraging machine learning, the chatbot's ability to accurately interpret and respond to nuanced human emotions is significantly enhanced, allowing for more meaningful and effective support .

The TF-IDF method plays a crucial role in the project by transforming raw text into meaningful numerical representations that reflect the importance of each word in the context of the entire corpus . In sentiment analysis, this method helps quantify the significance of certain words that may indicate depressive symptoms. By assigning a weight to each word based on its frequency within a document relative to its frequency across the dataset, TF-IDF enhances the model's ability to discern key emotional indicators, thereby improving the accuracy of sentiment classification .

The project tackles this challenge by utilizing advanced NLP techniques and diverse machine learning models that can process and analyze text despite grammatical inconsistencies or informal language often found on social media. Techniques such as stemming, tokenization, and the use of TF-IDF for vectorization help normalize the text input . Additionally, by employing robust machine learning models like XGBoost, which excels with large and complex datasets, the project enhances the system's capacity to accurately detect emotional states indicative of mental health issues amidst the variability in social media language .

The main limitations discussed include the simplicity of the current chatbot responses and the reliance on a dataset that may not fully represent the diverse linguistic and emotional expressions found on social media . Future improvements suggested are the incorporation of more advanced NLP models like transformers to enhance understanding and response to user inputs, and expanding the dataset to include more varied and representative samples to improve the model's generalization capacity . Furthermore, integrating more personalized response mechanisms could also make the chatbot interactions more engaging and supportive .

The project uses sentiment analysis and machine learning classification methods to detect signs of depression from social media text. Sentiment analysis is utilized to assess the emotional state of the user by processing large volumes of text to categorize sentiment as positive, negative, or neutral . Machine learning models such as Naive Bayes, Logistic Regression, Decision Tree, and XGBoost are then applied to predict the probability of depressive states based on the text . Specifically, text data is vectorized using the TF-IDF method and then classified using these models to determine the presence of depressive symptoms .

The primary motivations for developing such a chatbot are addressing the increasing levels of stress and mental health issues in society, especially given the vast amount of emotional content shared on social media. It aims to provide a non-intrusive way to identify individuals who may be struggling with depression, offering them support and recommendations, which is particularly significant in low-resource areas where mental health support might be less accessible . The project seeks to make mental health support more accessible and reduce the stigma associated with seeking help .

Declarative chatbots are basic and perform a single function, using NLP and predefined rules to respond to queries. Predictive chatbots, on the other hand, are more sophisticated and personalized, utilizing data to predict user needs and provide relevant support . The project employs a predictive chatbot, enabling it to interact with users and provide tailored advice to support their mental health based on the analysis conducted by the sentiment analysis model .

Preprocessing the dataset involves several crucial steps: 1) Handling of missing values by removing incomplete entries to maintain data integrity; 2) Tokenization and stemming, where text is broken into tokens and converted to base form to normalize the data; 3) Removing stopwords and converting text to lowercase for consistency; 4) Vectorization using TF-IDF to capture the importance of words for better classification. These steps are vital to ensure the data is clean, structured, and ready for effective machine learning model application, minimizing noise and improving model performance .

You might also like