Introduction

The proliferations of internet and communication technologies, especially the online social networks have rejuvenated how people interact and communicate with each other electronically. The applications such as Facebook, Twitter, Instagram and alike not only host the written and multimedia contents but also offer their users to express their feelings, emotions and sentiments about a topic, subject or an issue online. On one hand, this is great for users of social networking site to openly and freely contribute and respond to any topic online; on the other hand, it creates opportunities for people working in the health sector to get insight of what might be happening at mental state of someone who reacted to a topic in a specific manner. In order to provide such insight, machine learning techniques could potentially offer some unique features that can assist in examining the unique patterns hidden in online communication and process them to reveal the mental state (such as ‘happiness’, ‘sadness’, ‘anger’, ‘anxiety’, depression) among social networks’ users. Moreover, there is growing body of literature addressing the role of social networks on the structure of social relationships such as breakup relationship, mental illness (‘depression’, ‘anxiety’, ‘bipolar’ etc.), smoking and drinking relapse, sexual harassment and for suicide ideation [1, 2].

In this study, we aim to analyze Facebook data to detect any factors that may reflect the depression of relevant Facebook’s users. Various machine learning techniques are employed for such purpose. Considering the key objective of this study, the following are subsequent research challenges addressed in paper.

Define what depression is and what are the common factors contributing toward depression.

What are the factors to look for depression detection in Facebook comments?

How to extract these factors from Facebook comments?

What is the relationship between these factors and attitudes toward depression?

When is the most influential time to communicate within depressive Indicative Facebook user?

What are the most influential machine learning techniques for detection of depression in Facebook comments?

In the context of above mentioned challenges, we analyse depression from Facebook users’ data [3, 4]. As users express their feeling as a post or comments in the Facebook platform, sometimes their posts and comments refer to as emotional state such as ‘joy’, ‘sadness’, ‘fear’, ‘anger’, or ‘surprise’ [5, 6]. We analyze various features of Facebook comments by collecting data through an effective method of machine learning classification techniques and to make overall judgements regarding their various parts. In this study, we used publically available Facebook data (from bipolar, depression and anxiety Facebook page) containing users’ comments. Once we access the data, it was cleaned from any inconsistency and then analyzed by a software application called LIWC [7, 8].

In this study, we examine various linguistic cues which help to detect emotion cause events: the position of cause event and experiencer relative to the emotion keyword: emotional process like positive emotion (e.g. ‘happy’, ‘love’, ‘nice’), negative emotion (e.g. ‘worthless’, ‘loser’, ‘hurt’, ‘ugly’, ‘nasty’), sadness (e.g. ‘worry’, ‘crying’, ‘grief’, ‘sad’), anger (e.g. ‘stop’, ‘shit’, ‘hate’, ‘kill’, ‘annoyed’) and anxiety (e.g. ‘worried’, ‘fearful’). A temporal process like present focus (e.g. ‘today’, ‘is’, ‘now’), past focus (e.g. ‘ago’, ‘did’, ‘talked’) and future focus (e.g. ‘shall’, ‘may’, ‘will’, ‘soon’). Linguistic words like articles (e.g. ‘a’, ‘an’, ‘the’), prepositions (e.g. ‘for’, ‘in’, ‘of’, ‘to’, ‘with’, ‘above’), auxiliary verbs (e.g. ‘do’, ‘have’, ‘am’, ‘will’), conjunctions (e.g. ‘and’, ‘but’, ‘whereas’), personal pronoun (e.g. ‘I’, ‘them’, ‘her’, ‘him’), impersonal pronouns (e.g. ‘it’, ‘it’s’, ‘those’), verbs (e.g. ‘go’, ‘good’) and negation (e.g. ‘deny’, ‘dishonest’, ‘no’, ‘not’, ‘never’).

The main contributions of this paper are listed as follows:

  • First, we synthesized the literature on various emotion detection techniques to detect depression.

  • Second, we designated four features for our specific research problem and elaborate on the lesson learned from using each type.

  • Third, our experiments are carried out on datasets of Facebook user comments.

  • Fourth, we suggest machine learning techniques to utilize all factors and maintain robustness. We also identify that a Decision Tree classifier outperforms other classifiers (a SVM, KNN and Ensemble) for our dataset. Finally, our work also shows the importance of depression detection for mental disorder detection.

The remainder of the paper is organized as follows: “Related work” presents the related work of detecting depression analysis of social network data. Methodology is explained in the third section. The experimental analysis is presented in the fourth section, and its discussion in the fifth section. Finally, the conclusion and future work are provided in the last section.

Related work

There is growing body of literature that analyses the properties of depression [9,10,11,12]. Choudhury et al. [13] argue that depression constitutes a genuine test in individual and general wellbeing. Considerable number of individuals experiences the ill-effects of despondency and just a division gets sufficient treatment every year. They also investigated the possibility to utilize online networking to identify and analyze any sign of significant depression issue in people. Through their web-based social networking postings, they quantified behavioral credits identifying with social engagement, feeling, dialect and semantic styles, sense of the self-system, and notices of antidepressant medications.

Choudhury et al. [14] considered online networking as a promising instrument for public health, concentrating on the utilization of Twitter presents on fabricating predictive models about the forthcoming impact of childbirth on the conduct and disposition of new mothers. Utilizing Twitter posts, they measured postpartum changes in 376 mothers along measurements of social engagement, feeling, informal community, and phonetic style. O’Dea et al. [15] examined that Twitter is progressively researched as methods for recognizing psychological well-being status, including depression and suicidality in the population. Their investigation revealed that it is conceivable to recognize the level of worry among suicide-related tweets, utilizing both human coders and a programmed machine classifier.

Zhang et al. [16] have shown that if individuals with a high danger of suicide can be recognized through online networking like microblog, it is conceivable to actualize a dynamic intervention system to save their lives.

Many researchers have demonstrated that utilizing user-created content (UGC) accurately may help decide individuals’ psychological wellness levels. For instance, Aldarwish and Ahmad [17] examined that the utilization of Social Network Sites (SNS) is expanding these days, particularly by the more youthful eras. Because the accessibility of SNS enables clients to express their interests, sentiments and offer day by day schedule [18, 19].

Nguyen et al. [20] utilized machine learning and statistical strategies to separate online messages amongst depression and control groups utilizing temperament, psycholinguistic procedures and substance subjects removed from the posts created by individuals from these groups.

Park et al. [21] investigated states of mind and practices toward online web-based social networking in view of whether one is discouraged or not. They directed semi-organized up close and personal meetings with 14 dynamic Twitter users, half of whom were discouraged and the other half non-discouraged. Other than they examined a few plan implications for future social networks that could better suit users with depression and give bits of knowledge towards helping discouraged users address their issues through online web-based social networking [22].

Bachrach et al. [23] studied how user’s activity on Facebook identifies with their identity, as measured by the standard Five Factor Model. They analyzed relationships between user’s identity and the properties of their Facebook profiles. For instance, the size and thickness of their friendship network, number of transferred photographs, and number of occasions went to, number of gathering enrolment’s, and number of times the user has been tagged in photographs. Ortigosa et al. [24] have exhibited a new strategy for sentiment examine in Facebook that suggests that starting from messages composed by users, as to extract data about the users’ assessment extremity (positive, unbiased or negative), as transmitted in the messages they write; and to show the users’ standard conclusion extremity and to distinguish huge passionate changes.

In the context of Facebook mining, Holleran [9] found initial evidence that depression is a major contributor to the overall global burden of diseases. In other related work, Wang et al. [19] and Shen et al. [25] examined various depression-related features, and built a multimodal depressive model to detect the depressed users.

Although, some of the above reported work has discussed emotional process, temporal process, linguistic style to detect depression, the following shortcomings are observed in the existing literature:

There are few individual studies that have applied SVM, KNN, Decision Tree and Ensemble separately. There are no well-known studies that have combined all these techniques together at same dataset to investigate the variations in technique-based findings.

There is no significant study that has applied the above-mentioned machine learning techniques on Facebook data for depression detection.

To address the above-listed shortcomings, we make an attempt to detect depression from Facebook comments with the present work; we expand the scope of social media-based depression measures, describing the different features of Facebook user comments. We applied machine learning approaches that can use those measures for the detection of individuals who are suffering with depression.

Methodology

In this study, we first focused on four types of factors such as emotional process, temporal process, linguistic style and all (emotional, temporal, linguistic style) features together for the detection and processing of depressive data received as Facebook posts. We then apply supervised machine learning approaches to study each factor types independently. The classification techniques such as ‘decision tree’, ‘k-Nearest Neighbor’, ‘Support Vector Machine’, and ‘ensemble’ are deemed suitable for each type (refer to Fig. 1).

Fig. 1
figure 1

A methodological overview of Facebook data analysis for depression analysis

Data set exploration

We worked on Facebook users’ comments for depressive behavioral exploration and detection. We collected data from the social network [26]. Preparing of social network data, in particular Facebook user’s comments is one of the primary challenges which bear information on whether or not they could contain depression bearing content. To tackle this issue we use NCapture for collecting data from Facebook [27, 28]. For qualitative data analysis, NCapture is a powerful tool in the world today. It is intended to enable to arrange, break down and discover knowledge in unstructured data like open-ended survey responses, social media, interviews, articles and web content. Furthermore it gives a place to arrange and deal with material to discover knowledge in a more proficient way [29].

Data set preparation

After collecting the raw data from Facebook, it was analyzed by using LIWC Software [7, 8]. LIWC is the heart of the text analysis strategy and can process text on a line by line. Our primary dataset contains total 21 columns where 13 columns represent the linguistic style (articles, prepositions, auxiliary verbs, conjunctions, personal pronoun, impersonal pronouns, verbs, negation etc.) information, 5 columns represent the emotional (positive, negative, sad, anger and anxiety) information, 3 columns represent the temporal process (past, present and future) information and each column gives the individual information’s about depressive behavior (refer to Table 1).

Table 1 Characteristics of raw data

Building ground truth dataset

This section discusses the process employed to construct our dataset with ground truth label information (on whether the comments is depression indicative). The Facebook data containing users’ comments were divided into two sets (a) for the positive (YES) class (depression indicative comments) and (b) for the negative (NO) class (non-depression indicative comments).

Out of the total 7145 comments, 58% obtained ‘YES’ for depression indicative comments and 42% obtained ‘NO’ for non-depressive indicative comments. Table 1 illustrated the dataset information and a few examples of depression indicative comments are given in Tables 2 and 3.

Table 2 Depression indicative distribution of dataset
Table 3 Examples of depression indicative comments

Feature extraction

To describe and demonstrate amongst depressive and non-depressive posts, we extract the different features in view of psycholinguistic measurements from the user’s post. It is clarified briefly as follows:

Psycholinguistic features LIWC is a psycholinguistic vocabulary package made by psychological analysts to perceive the different affective, intellectual, and etymological parts lies on user’s verbal or written correspondence. It returns more than 70 different factors with higher level of psycholinguistic features, for example,

  • Psychological process—affective process, social process, cognitive process, perceptual process, biological process, drives, time orientations, relativity, personal concerns

  • Linguistic process—word count, word/sentence, pronoun, personal pronoun, articles, prepositions, auxiliary verbs, adverbs, conjunctions, Negations

  • Others grammar—verbs, adjectives, comparisons, interrogatives, number, quantifiers.

These higher-level categories are also divided into subcategories such as

  • Biological processes—sexual, body, ingestion and health

  • Affective processes—anxiety, anger, sadness, positive emotion, negative emotion

  • Time orientations—present, past, future

  • Social processes—family, friends, male, female

  • Perceptual processes—see, hear, feel.

To do our research work, we took 23 among 70 factors, and changed over every depressive and non-depressive post into numerical values in view of psycholinguistic features. Table 4 demonstrates the different classes of LIWC psycholinguistic processes.

Table 4 Break down of target terms into various categories

Measuring depressive behavior

We presented a set of attributes like emotional process, temporal process, and linguistic style that can be used to characterize the depressive behaviors of users. Our dataset consists of five emotional variables (positive, negative, sad, anger, anxiety), three temporal categories (present focus, past focus and future focus), and 9 standard linguistic dimensions (e.g., articles, prepositions, auxiliary verb, adverbs, conjunctions, pronoun, verbs and negations) [30,31,32,33,34,35,36]. We calculate their values by the standard LIWC2015 scales. A complete list of the standard LIWC2015 scales including examples of our dataset is included in Table 4.

Emotional processes Emotion process, a complex experience of consciousness, bodily sensation, and behaviour that reflects the personal significance of a thing, an event, or a state of affairs. The analysis of the emotional comments of social network data can be leveraged to produce reliable predicts in a variety of circumstances [25]. We use psycholinguistic dimensions for considering five features of the emotion state manifested in the comments: positive affect (PA), negative affect (NA), sadness affect (SA), anger affect (AA), and anxiety affect (AnA) [37,38,39,40,41].

Temporal process

Generally, temporal process word provides information about past focus category, present focus category and future focus category of how people are referencing each other and their degree of emotionality.

Linguistic process

Linguistics process is one of the largest parts of LIWC psycholinguistics vocabulary package. It was intended to quantify word use in mentally significant classifications. Also it has been effectively used to recognize connections between people in social co-operations, including relative status, trickiness, and the nature of close relationship. So, In our study we use nine specific linguistics features (articles, prepositions, auxiliary verbs, adverbs, conjunctions, personal pronoun, impersonal pronouns, verbs, and negations) to characterize user comments for our experimental analysis.

Classification model

This stage constructs prediction model for depression post/comments recognition, by considering the psycholinguistic features as input. Considering our training corpus B = p1; p2….. pn of n posts/comments, such that each post/comments pi is labeled with the class either as depressive or non-depressive, where L = l1|l2. The task of a classifier f is to find the corresponding label for each posts/comments.

$$f:B \in L \qquad f(p) = l$$

In this work, we employ four popular classifiers: Support Vector Machine (SVM), Decision Tree, Ensemble, and k-Nearest Neighbor (kNN).

Support Vector Machines (SVM) Support Vector Machines also known as support vector networks. It is a non-probabilistic linear binary classifier that analyzes data for classification or anomaly detection. It builds a hyperplane into high dimensional feature space and finds a hyperplane that isolates the data into two classes with the biggest separation to the closest training data purpose of any class.

Decision Tree (DT) Decision tree is a simple and all around used classification based systematic approach that makes the hierarchical tree from the training dataset. The state of decision tree is to divide the data hierarchically that have different characteristics. For instance of text documents classification, roots are commonly identified in terms and internal individual nodes may be sub-divided to its children in view of the yes or no of a term in the document.

Ensemble Ensemble methods use multiple learning algorithms of decision tree for better predictive performance.

K-Nearest Neighbor (KNN) K-Nearest Neighbor (KNN) is a non-parametric approach use to discover the distances from point of interest to points in training set.

Experimental analysis

In this study, we examine the execution of various classifiers for depression detection in a shorter time.

Data analysis

The analysis is conducted using MATLAB 2016b. We applied four major classifiers: Support Vector Machine (SVM), K-Nearest Neighbors (KNN), Decision trees (DT), and Ensemble. Each classifier has sub-classifiers such as Decision trees—Simple DT, Medium DT, and Complex DT; SVM—Linear, Quadratic, Cubic, Fine Gaussian, Medium Gaussian, and Coarse Gaussian; KNN—Fine, Medium, Coarse, Cosine, Cubic and Weighted, Ensemble—Boosted tree, Bagged tree, Subspace discriminant, Subspace KNN, RUSBoosted Tree [42,43,44].

Using the above classification techniques, we examined detection performance of Facebook user comments. To comprehend the significance of different feature types, we applied four classifiers techniques each utilizing: emotional process, linguistic style, temporal process and all features. The results of the analysis are reported in Tables 5 and 6 that suggests Decision Tree as best performing model. Although KNN gives the high precision but Decision Tree gives the highest result for recall and F-measure relating to the class of depression indicative comments of Facebook user. Similarly, for linguistic style Decision Tree gives the highest result for precision, recall and F-measure.

Table 5 Performance metrics of machine learning classifiers based on emotional process and linguistic style features set
Table 6 Performance metrics of machine learning classifiers based on temporal process and all features set

The evaluation matrices parameters (precision, recall and F-measure) have been used to execute these classifiers. It has conducted based on four different ways. True Positive (TP) = the depression cases that are positive and anticipated as positive True Negative (TN) = the depression cases that are negative and anticipated as negative. False Negative (FN) = the depression cases that are positive but anticipated to be negative. False Positive (FP) = the depression cases that are actually negative but anticipated to be positive.

All the evaluation metrics are defined as follows.

Precision is the proportion of true positives to the cases that are anticipated as positive. It is the level of chosen cases that are right.

$$\textit{Precision} (P) = \frac{\textit{True\;Positive}}{\textit{True\;Positive}+\textit{False\;Positive}}$$

Recall is the proportion of true positives to the cases that truly positive. It is the level of chosen cases that are selected.

$$\textit{Recall} (R) = \frac{\textit{True\;Positive}}{\textit{True\;Positive}+\textit{False\;Negative}}$$

F-measure is the mean of Precision and Recall. It takes both false positives and false negatives into a record. F-measure is calculated as:

$$\textit{F-Measure} = 2 \frac{PR}{P+R}$$

The experimental evaluation is done by using 10-fold cross-validation on all level of testing data set. For each classifier, we demonstrate the estimation of its sub-classifier which holds on to high F-measure (refer to Tables 5 and 6). Table 5 demonstrates the sub classifier of the primary classifier that has maximum F-measure values. For example, Coarse Gaussian SVM give better results as compared to Medium Gaussian SVM. Similarly, we have selected the F-measure for other classifiers too. Results are discussed in Fig. 2.

Fig. 2
figure 2

Depression detection accuracy on depression dataset by different classifier

Similarly, we show the results of these prediction models in Table 6. The outcome shows that the best performing model is Decision Tree. Here, for temporal process and all features, KNN and SVM gives almost same the high precision but Decision Tree gives the highest result for Recall and F-measure relating to the class of depression indicative comments of Facebook user (refer to Fig. 2)

Time series analysis

In general, the definition of time series is a record of phenomenon unpredictably fluctuating with time is called time series and Time-series data is a kind of fleeting information which is normally high dimensional and large in data size. In this section, we focus on understanding of the time patterns of Facebook users, at AM (0 h-0 m-1 s–11 h-59 m-59 s) and PM (12 h-0 m-1 s–23 h-59 m-59 s). We use the same data as mentioned in Table 7 to study levels of depression detection among Facebook users. As in correspondence with our findings in Table 7, we see that the AM and Yes values for all of the features are higher than PM.

Table 7 Depressive indicative comments at AM and PM

From the above mentioned table, we can see that depression indicates that 2247 out of 7145 comments suffering from depression at AM [5]. We observed that depression rate higher at AM than PM because that time because of loneliness, break from work, absence of vitality, or different communications between light/darkness and the nervous system. Next, we analyses our dataset over the month of a year. We already mentioned that we have collected data of August and September month. The monthly patterns of depression for Facebook users with high depression rate (see Table 7 for details) are shown in Fig. 3. We observe the monthly depression pattern. It is showing that we have total 7146 number of comments. 91.14% samples of comments ranging between August 01, 2017–August 30, 2017, and 8.85% between September 01, 2017–September 09, 2017.

Fig. 3
figure 3

Time series analysis of depressive indicative comments

We also show an average trend for all comments, combining all times (denoted as “AM” and “PM”). We observed that the hourly depression patterns with highest rate in AM. We also observed that the monthly depression pattern shows a seasonal trend, with highest depression observed during both August and September in the AM, while the lowest during both August and September in the PM. In addition, we observe that depression problem among Facebook users are more associated with personal problems than others. In summary, we view persistent rhythms in depression expression on social media throughout multi day crosswise over people. This provides us with a promising mechanism to monitor fine-grained temporal trends of depression across populations and regions.

Discussion

For a better understanding of the general intuition behind depression, in this paper, we applied Decision Tree, KNN, SVM and Ensemble classifier techniques for depression detection of emotional terms. We showed that all of these classification techniques based on linguistic style, emotional process, temporal process and all (Linguistic, emotional and temporal) features are able to successfully extract the depressive emotional result. Tables 5 and 6 demonstrate the results of various characterizations with various proportions of four features. It can be observed that Decision Tree gives the better outcome. We believe that the current study has laid the ground for future research on inferences and discovery of additional information based on cause-event relation, such as detection of implicit emotion or cause, as well as prediction of public opinion based on cause events, etc. Moreover, in this paper, we applied total 21 types of attributes of LIWC software for detecting depression, but we can apply more than 54 attributes. Though we achieved accuracy between 60 and 80%; there is still some room for improvement. It is important to note that this study does not identify who the sufferers are; but assess the Facebook comments for depression detection.

Conclusion and future work

In this paper we have exhibited the capability of using Facebook as a tool for measuring and detecting major depression among its users. To give a clear understanding of our work, numbers of research challenges were stated at the start of this paper. The analytics performed on the selected dataset, provide some insight on the research challenges. Below is the summary of our findings:

What depression is and what are the common factors contributing toward depression.

While we feel moody, sad or low from time to time, few people encounter these emotions seriously, for drawn out stretches of time (weeks, months or even years) and in some cases with no apparent reason. Despondency is something other than a low state of mind—it’s a genuine condition that influences someone’s physical and emotional feelings.

Depression can influence any of us anytime. However, some phases or events make us more vulnerable to depression. Physical and emotional changes associated with growing-up, losing a loved one, beginning a family, retirement may trigger some emotional influx that could lead toward depression for few people.

What are the factors to look for depression detection in Facebook comments?

It is important to remember that depressive emotions have several signs and symptoms spread across various categories as reported in Table 8.

Table 8 Signs and symptoms of depression

Based on the above mentioned signs and symbols we divided our dataset into 5 emotional variables (positive, negative, sad, anger, anxiety), 3 temporal categories (present focus, past focus and future focus), 9 standard linguistic dimensions (e.g., articles, prepositions, auxiliary verb, adverbs, conjunctions, pronoun, verbs and negations) (See the section III) .

How to extract these factors from Facebook comments?

To extract the above-mentioned factors, we applied Linguistic Inquiry and Word Count (LIWC) on our dataset. The LIWC2015 Dictionary is the heart of the text analysis strategy. It processes our Facebook comments on a ‘line by line’ basis within and across columns of spreadsheet and accesses a single text within a spreadsheet and analyzes each line sequentially and reads one target word at a time.

What is the relationship between these factors and attitudes toward depression?

The relationship between the above-mentioned issues with the attitudes towards depression are varies from person to person. Tables 3 and 4 presents information on depressive and non-depressive condition of Facebook users.

When are the most influential time to communicate within depressive Indicative Facebook user?

In this study, we analyzed 7146 depressive indicative Facebook comments to identify the most influential time. We got 54.77% depressive indicative Facebook users communicate with their friends from midnight to midday and 45.22% from midday to midnight. To prove the findings of above mentioned results, we observed that at AM, most of the depressive indicative Facebook users feels loneliness, stress, lack of energy, or other interactions between light/darkness, interactions problem between family members, suffering from physical problems and the nervous system.

What are the most influential machine learning techniques for detection of depression in Facebook comments?

We utilize different machine learning techniques to assess the execution learned by three unique features. Tables 5 and 6 demonstrate the results of various characterizations with proportions of these features. Firstly, as shown in Table 5, we break down the emotional process and linguistic style and it is evident that decision tree gives the better outcome. Moreover, in Table 6, we examined the temporal procedure and all (emotional, linguistic, temporal together) features. It can be observed that SVM fundamentally performed superior to another classifier. But, for features precision, recall and F-measure calculation decision tree gives the most astounding outcome.

In summary, we studied three types of factors (emotional process, temporal process, linguistic style) and trained a model to utilize each type of factor independently and jointly. We use machine learning techniques to classify the features of comments. Our findings showed that all of the classifiers results are almost between 60 and 80%.

In future work, we plan to use another technique to extract paraphrases from more types of emotional features. Also, we plan to use more dataset to verify our techniques efficiency and effectiveness. We in agreement with the existing body of literature that suggests that more focused studies in depression analysis are needed. Although LIWC has more than 50 attributes, we took total 21 attributes for detecting depression of Facebook users, the most significant attributes are found to be from emotional process factor.