You are on page 1of 91

AI TO DETECT SOCIAL MEDIA USERS DEPRESSION POLARITY SCORE AND

DIAGNOSE USING AUTO CURATIVE THERAPY

A PROJECT REPORT

Submitted by

DILLIP. K (111418104022)

G. BHARATH CHOWDARY (111418104032)

K. SATHWIK REDDY (111418104050)

in partial fulfilment for the award of the degree

of

BACHELOR OF ENGINEERING

in

COMPUTER SCIENCE AND ENGINEERING

PRATHYUSHA ENGINEERING COLLEGE

THIRUVALLUR-602 025

ANNA UNIVERSITY :: CHENNAI 600 025

JUNE 2022

i
ANNA UNIVERSITY:: CHENNAI 600 025

BONAFIDE CERTIFICATE

Certified that this project report “AI TO DETECT SOCIAL MEDIA USERS

DEPRESSION POLARITY SCORE AND DIAGNOSE USING AUTO CURATIVE

THERAPY” is the bonafide work of the “DILLIP. K (111418104022), G. BHARATH

CHOWDARY (111418104032), K. SATHWIK REDDY(111418104050)” who

carried out the project work under my supervision.

SIGNATURE SIGNATURE
Dr. V. VIJAYARAJA, Ms. B. GUNASUNDARI,
PROFESSOR, ASSISTANT PROFESSOR,
HEAD OF THE DEPARTMENT, SUPERVISOR,
Department of CSE, Department of CSE ,
Prathyusha Engineering college, Prathyusha Engineering college,
Thiruvallur- 602 025. Thiruvallur- 602 025.

Place: Thiruvallur
Date:
Submitted for the Project Viva-Voce held on…………..….at
Prathyusha Engineering College, Thiruvallur- 602 025.

INTERNAL EXAMINER EXTERNAL EXAMINER

ii
ACKNOWLEDGEMENT

Our sincere thanks to Shri. P. RAJARAO, Chairman, Prathyusha Engineering


College for facilitating us to do this project.
We are grateful to our Vice Chairman, Shri. P. CHARAN TEJA & our CEO
Smt. P. PRATHYUSHA, for being a source of Inspiration.
We are sincerely thanking Dr. B.R RAMESH BAPU, Principal, Prathyusha
Engineering College for encouraging our endeavors for this project.
We are sincerely thanking Dr. V. VIJAYARAJA, Professor, Head of
Department, for supporting us in all stages of project conduction.
We are grateful to our project coordinator Ms. R. MEENA, Assistant
professor, for her valuable suggestions and guidance.
We are grateful to our internal guide Ms. B. GUNASUNDARI, Assistant
Professor for her valuable suggestions and guidance for the successful completion of
this project.
We also wish to extend our sincere thanks to all the committee members for
their constant support throughout the review.
We wish to express our sincere gratitude to PARENTS AND FRIENDS for
valuable help, co-operation and encouragement during this project work.
Last but not least, we wish to express our sincere thanks to the entire teaching
faculty and non-teaching staff for their support.

iii
ABSTRACT

Depression is viewed as the largest contributor to global disability and a


major reason for suicide. Generally, clinical psychologists diagnose depressed
people via face-to-face interviews following the clinical depression criteria.
However, often patients tend to not consult doctors in their early stages of
depression. Nowadays, people are increasingly using social media to express their
moods. Sentiment Analysis (SA) is the examination of the polarity of emotions
and opinions expressed in the text by using computational methods. Sentiment
could be expressed implicitly or explicitly in the text. Numerous studies on
mental depression have found that tweets posted by users with major depressive
disorder could be utilized for depression detection. The potential of sentiment
analysis for detecting depression through an analysis of social media messages
has brought increasing attention to this field. In this project, we aim to predict
depressed users as well as estimate their depression intensity via leveraging social
media (Twitter) data, in order to aid in raising an alarm. we propose a lexicon-
enhanced LSTM model. The model first uses sentiment lexicon as an extra
information pre-training a word sentiment classifier and then get the sentiment
embeddings of words including the words not in the lexicon. Combining the
sentiment embedding and its word embedding can make word representation
more accurate. Derived from a combination of feature extraction approaches
using sentiment lexicons and textual contents, these features are able to provide
impressive results in terms of depression detection.

iv
TABLE OF CONTENTS

CHAPTER TITLE PAGE


NO
NO

ABSTRACT iv

LIST OF FIGURES ix

LIST OF TABLES x

LIST OF ABBREVIATION xi

LIST OF SYMBOLS xii

1 INTRODUCTION

1.1 OVERVIEW 2

1.2 OBJECTIVE 3

1.3 LITERATURE SURVEY 3

2 SYSTEM ANALYSIS

2.1 EXISTING SYSTEM 7

2.1.1 DISADVANTAGES 7

2.2 PROPOSED SYSTEM 7

2.2.1 ADVANTAGES 8

v
CHAPTER TITLE PAGE
NO NO

3 SYSTEM REQUIREMENTS
3.1 HARDWARE REQUIREMENTS 10

3.2 SOFTWARE REQUIREMENTS 10

3.3 SOFTWARE DESCRIPTION 11

4 SYSTEM DESIGN

4.1 SYSTEM ARCHITECTURE 16


16
4.2 UML DIAGRAM

4.2.1 USECASE DIAGRAM 16

4.2.2 CLASS DIAGRAM 18

4.2.3 ACTIVITY DIAGRAM 19

4.2.4 SEQUENCE DIAGRAM 20

4.2.5 COLLABORATION DIAGRAM 21

5 SYSTEM IMPLEMENTATION

5.1 LIST OF MODULES 23

5.2 MODULE DESCRIPTION 23

5.2.1 SOCIAL NETWORKING WEB APP 23

vi
CHAPTER TITLE PAGE
NO NO

5.2.2 TRAINING PHASE: DEPRESSRION 24


TWEET COLLECTION
5.2.3 TESTING PHASE 25
6 TESTING
6.1 UNIT TESTING 27

6.1.1 TEST OBJECTIVE

6.1.2 TEST CASES OF AI TO DETECT SOCIAL 28


MEDIA USERS DEPRESSION POLARITY
SCORE AND DIAGNOSE USING AUTO
CURATIVE THERAPY

6.2 INTEGRATION TESTING 29

6.3 SYSTEM TESTING 29

7 RESULTS AND DISCUSSION


7.1 RESULTS 31
7.2 DISCUSSION 31

8 CONCLUSION AND FUTURE ENHANCEMENT


8.1 CONCLUSION 33

8.2 FUTURE ENHANCEMENT 33

vii
ANNEXURE 35

APPENDIX 1 SOURCE CODE 36

APPENDIX 2NSCREENSHOT 72

REFERENCES 77

viii
LIST OF FIGURES

FIGURE NO. FIGURE NAME PAGE NO.


4.1 System Architecture for ai to detect social media users 16
depression polarity score and diagnose using auto
curative therapy

4.2.1 Use case Diagram for ai to detect social media users 17


depression polarity score and diagnose using auto
curative therapy

4.2.2 Class Diagram for ai to detect social media users 18


depression polarity score and diagnose using auto
curative therapy

4.2.3 Activity Diagram for ai to detect social media users 19


depression polarity score and diagnose using auto
curative therapy

Sequence Diagram ai to detect social media users


4.2.4 20
depression polarity score and diagnose using auto
curative therapy

Collaboration Diagram ai to detect social media users


4.2.5 21
depression polarity score and diagnose using auto
curative therapy

ix
LIST OF TABLES

TABLE NO TABLE NAME PAGE NO

Test cases of ai to detect social media


6.1.1 users depression polarity score and 28
diagnose using auto curative therapy

x
LIST OF ABBREVIATIONS

NLP Natural Language Processing

NLTK Natural Language Toolkit

API Application Programming Interface

LDA Latent Dirichlet Allocation

xi
LIST OF SYMBOLS

S.NO NOTATION NOTATION DESCRIPTION


NAME

+ Public Class
Represents a collection of
Name
-Private similar entities grouped
# -attribute together.
1. Class
Protected -attribute

+operation Associations represent


2. Association Class A NAME Class B static relationships
+operation

+operatio between classes.


n

Roles represent the way


ROLE
Class A Class B
the two classes see each
other.

3. Actor Specifies a role played by


a user that interacts with
the subject.

xii
S.NO NOTATION NOTATION DESCRIPTION
NAME

4. Communication Communication between


various use cases.

5. Initial State Initial state of the object

6. Final state Final state of the object

7. Control flow Represents various control


flow between the states.

8. Decision box Represents decision


making process from a
constraint.

xiii
S.NO NOTATION NOTATION DESCRIPTION
NAME

9. Use case Use case Interaction between the


system and external
environment.

10. External entity Represents external


entities such as keyboard,
sensors, etc.

11. Transition Represents


communication that occurs
between Processes.

12. Object Lifeline Represents the vertical


dimensions that the object
communications.

13. Message Message Represents the message


exchanged.

xiv
CHAPTER 1

INTRODUCTION

1
CHAPTER 1

INTRODUCTION

1.1 OVERVIEW

Depression is a mood disorder that causes a persistent feeling of sadness and


loss of interest. Also called major depressive disorder or clinical depression, it
affects how you feel, think and behave and can lead to a variety of emotional and
physical problems. You may have trouble doing normal day-to-day activities, and
sometimes you may feel as if life isn't worth living. Especially when recurrent and
with moderate or severe intensity, depression may become a serious health
condition. It can cause the affected person to suffer greatly and function poorly at
work, at school and in the family. At its worst, depression can lead to suicide. Over
700 000 people die due to suicide every year. Suicide is the fourth leading cause of
death in 15-29-year-olds. , we make an attempt to detect depression from twitter
comments with the present work; we expand the scope of social media-based
depression measures, describing the different features of twitter user comments. We
applied deep learning approaches that can use those measures for the early detection
of individuals who are suffering with depression.

2
1.2 OBJECTIVE
we propose a lexicon-enhanced LSTM model. The model first uses
sentiment lexicon as an extra information pre-training a word sentiment classifier
and then get the sentiment embeddings of words including the words not in the
lexicon.

1.3 LITERATURE SURVEY

[1]. Luna Ansari; Shaoxiong Ji, Ensemble Hybrid Learning Methods for
Automated Depression Detection, JAN 2022
In this paper, text classifiers are trained for depression detection. The key
objective is to improve depression detection performance by examining and
comparing two sets of methods: hybrid and ensemble . The purpose of using the
ensemble approach can vary, and it is mainly applied for three purposes: decreasing
bias in the model, decreasing variance in the model, and enhancing predictions. The
results show that ensemble models outperform the hybrid model classification
results. The strength and effectiveness of the combined features demonstrate that
better performance can be achieved by multiple feature combinations and proper
feature selection.

[2] FELIPE TALIAR GIUNTINI;KAUÊ L. P. DE MORAES, Tracing the Emotional


Roadmap of Depressive Users on Social Media Through Sequential Pattern
Mining, Mar 2021
This paper the TROAD framework for longitudinal recognition of
sequential patterns from depressive users on social media. The framework identifies
the best interval to analyze every user activity, extracts emotional and contextual
features from user data, and models the features into time windows to recognize

3
sequential patterns from depressive user behavior. TROAD (Tracing the Roadmap of
Depressive Users), a framework for the collection, pre-processing, modelling, and
knowledge discovery of sequential patterns of user emotions from social networks.

[3] Diana Ramírez-Cifuentes; Christine Largeron, Enhanced Word


Embedding Variations for the Detection of Substance Abuse and Mental Health
Issues on Social Media Writings, Sep 2021
This paper aims to analyze textual cues that characterize and differentiate
Reddit posts related to depression, eating disorders, suicidal ideation, and
alcoholism, along with control posts. Introduced a method to generate word
embedding enhanced for both binary and multi-class classification tasks that involve
small corpora. This is a method that can also be applied to other domain-specific
classification tasks. Results show that variations of our enhanced representations
outperform in Recall, Accuracy, and F1-Score the embedding’s learned with
Word2vec, DistilBERT, GloVe ’s fine-tuned pre-learned embedding and other
methods based on domain adapted embedding. The approach presented has the
potential to be used on similar binary or multi-class classification tasks that deal with
small domain-specific textual corpora.

[4] Guozheng Rao; Yue Zhang, MGL-CNN: A Hierarchical Posts


Representations Model for Identifying Depressed Individuals in Online
Forums, jul 2020
This paper introduced two hierarchical neural network models with gated
units and convolutional networks for fulfilling depression detection task, which are
named Multi-Gated LeakyReLU CNN (MGL-CNN) and Single-Gated LeakyReLU
CNN (SGL-CNN). The user’s dataset is divided into a certain number of posts, and

4
we can use our models to identify the genuinely crucial sentiment features of each
user’s posts and suppress other unimportant information as possible. The proposed
models can encode the relations between posts in user representation. Experimental
results showed that our models performed better than the previous state-of-the-art
models on the Reddit Self-Reported Depression Diagnosis dataset, and also
performed well on the Early Detection of Depression dataset.

[5] Marcel Trotzek; Sven Koitka, Utilizing Neural Networks and Linguistic
Metadata for Early Detection of Depression Indications in Text Sequence,
September 2020
This paper aims the early detection of depression using machine learning
models based on messages on a social platform. In particular, a convolutional neural
network based on different word embedding is evaluated and compared to a
classification based on user-level linguistic metadata. An ensemble of both
approaches is shown to achieve state-of-the-art results in a current early detection
task. As the results presented in this paper are optimized to obtain the best
performance on the eRisk 2017 task for comparison to previously published results
and among these models, future work will have to show how these models perform
on yet unseen data.

5
CHAPTER 2
SYSTEM ANALYSIS

6
CHAPTER 2
SYSTEM ANALYSIS

The system study is to provide the description about the existing system, its

limitation and proposed system of the project.

2.1 EXISTING SYSTEM:

Early intervention for depression can improve employee productivity and reduce
absenteeism Early detection, intervention, and appropriate treatment can promote
remission and reduce the emotional and financial burdens.
2.1.1 DISADVANTAGES

 Hurdle in detecting depression symptoms from short texts.


 Existing methods require manual selection of features or design of methods
to select features.
 easy to cause dimensionality disaster
 cannot capture the relationship between words and words.
 Occurs overfitting problem

2.2 PROPOSED SYSTEM


We Propose a lexicon-enhanced LSTM model (LE-LSTM) to integrate sentiment
lexicon into LSTM to capture more sentiment information of words. First, we use
sentiment lexicon as the extra information to pre-train a word sentiment classifier.
And then each word can get its sentiment embedding including the words not in
sentiment lexicon. During the main training process, we concatenate the word

7
embedding and its sentiment embedding as the input of LSTM and fine-tune the
word sentiment classifier network.

2.2.1 ADVANTAGES
 Outperforms in terms of accuracy, due to the diversity and richness of its
feature set.
 Reduces the number of words in the corpus
 Decreases the computation time.
 Gives the words strength when fed to the classification model.
 Reduce the possibility of overfitting.

8
CHAPTER 3

SYSTEM REQUIREMENTS

9
CHAPTER 3

SYSTEM REQUIREMENTS

3. INTRODUCTION

The requirements specification is a technical specification of requirements for


the software products. It is the first step in the requirements analysis process; it lists
the requirements of a particular software system including functional, performance
and security requirements. The requirements also provide usage scenarios from a
user, an operational and an administrative perspective. This describes the project's
target audience and its user interface, hardware and software requirements.

3.1 HARDWARE REQUIREMENTS

Processor : Intel Core I5

Disk space 320 GB

Operating system :windows 10,macOS and Linux

3.2 SOFTWARE REQUIREMENTS

Software : Python 3.7.4

Client side :HTML, CSS, Bootstrap

IDE :Flask 1.1.1

Back end :MySQL 5

Server : Wampserver 2i

10
3.3 SOFTWARE DESCRIPTION

Software Description is a technical specification of requirement of software


product. This specifies the environment for development, operation and maintenance
of the product.

3.3.1 PYTHON 3.7

The user can develop the Tweepy functions using Python 3.7 in addition to
the already supported 2.7 and 3.6 versions. Python 3.7 is the newest major release
of the Python language, and it contains many new features such as support for data
classes, customization of access to module attributes, and typing enhancements. The
Python 3.7 runtime is available in all regions where Tweepy is available.

3.3.1.1 Pandas
pandas is a fast, powerful, flexible and easy to use open source data analysis
and manipulation tool, built on top of the Python programming language. pandas is
a Python package that provides fast, flexible, and expressive data structures designed
to make working with "relational" or "labeled" data both easy and intuitive. It aims
to be the fundamental high-level building block for doing practical, real world data
analysis in Python.
3.3.1.2 NumPy
NumPy, which stands for Numerical Python, is a library consisting of
multidimensional array objects and a collection of routines for processing those
arrays. Using NumPy, mathematical and logical operations on arrays can be
performed. NumPy is a general-purpose array-processing package. It provides a
high-performance multidimensional array object, and tools for working with these
arrays.

11
3.3.2 MySQL
MySQL tutorial provides basic and advanced concepts of MySQL. Our
MySQL tutorial is designed for beginners and professionals. MySQL is a relational
database management system based on the Structured Query Language, which is the
popular language for accessing and managing the records in the database. MySQL
is open-source and free software under the GNU license. It is supported by Oracle
Company. MySQL database that provides for how to manage database and to
manipulate data with the help of various SQL queries. These queries are: insert
records, update records, delete records, select records, create tables, drop tables, etc.
There are also given MySQL interview questions to help you better understand the
MySQL database.
3.3.3 WampServer
WampServer is a Windows web development environment. It allows you to
create web applications with Apache2, PHP and a MySQL database. Alongside,
PhpMyAdmin allows you to manage easily your database. WampServer is a reliable
web development software program that lets you create web apps with MYSQL
database and PHP Apache2. With an intuitive interface, the application features
numerous functionalities and makes it the preferred choice of developers from
around the world. The software is free to use and doesn’t require a payment or
subscription.
3.3.4 Bootstrap 4
Bootstrap is a free and open-source tool collection for creating responsive
websites and web applications. It is the most popular HTML, CSS, and JavaScript
framework for developing responsive, mobile-first websites. It solves many
problems which we had once, one of which is the cross-browser compatibility issue.
Nowadays, the websites are perfect for all the browsers (IE, Firefox, and Chrome)
and for all sizes of screens (Desktop, Tablets, Phablets, and Phones). All thanks to

12
Bootstrap developers -Mark Otto and Jacob Thornton of Twitter, though it was later
declared to be an open-source project.

13
CHAPTER 4

SYSTEM DESIGN

14
CHAPTER 4

SYSTEM DESIGN

System design is the process of planning a new system or to replace the


existing system. Simply, system design is like the blueprint for building, it specifies
all the features that are to be in the finished product.

4.1 SYSTEM ARCHITECTURE

A System architecture or systems architecture is the conceptual model that


defines the structure, behavior, and more views of a system. An architecture
description is a formal description and representation of a system, organized in a
way that supports reasoning about the structures and behaviors of the system.

15
Fig 4.1 System Architecture for ai to detect social media users depression
polarity score and diagnose using auto curative therapy

4.2 UML DIAGRAMS


4.2.1 USE CASE DIAGRAM

Use Cases are used to describe the visible interactions that the system will
have with users and external systems. They are used to describe how a user would
perform their role using the system.

16
Fig 4.2.1 Use case diagram for ai to detect social media users depression
polarity score and diagnose using auto curative therapy

17
4.2.2 CLASS DIAGRAM

The class diagram is a static diagram. It represents the static view of an


application. The class diagrams are widely used in the modeling of object-oriented
systems because they are the only UML diagrams which can be mapped directly
with object-oriented languages.

Fig 4.2.3 Class diagram for ai to detect social media users depression polarity
score and diagnose using auto curative therapy

18
4.2.3 ACTIVITY DIAGRAM

Activity diagram is defined as a UML diagram that focuses on the


execution and flow of the behavior of a system instead of implementation. It is also
called object-oriented flowchart. Activity diagrams consist of activities that are
made up of actions which apply to behavioral modeling technology.

Fig 4.2.2 Activity diagram for ai to detect social media users depression
polarity score and diagnose using auto curative therapy

19
4.2.4 SEQUENCE DIAGRAM
A Sequence diagram is a kind of interaction diagram that shows how
processes operate with one another and in what order. It is a construct of a Message
Sequence Chart. A sequence diagram shows object interactions arranged in time
sequence. It depicts the objects and classes involved in the scenario and the sequence
of messages exchanged between the objects needed to carry out the functionality of
the scenario.

Fig 4.2.4 Sequence diagram for ai to detect social media users depression
polarity score and diagnose using auto curative therapy

20
4.2.5 COLLABORATION DIAGRAM
Another type of interaction diagram is the Collaboration diagram. A
collaboration diagram represents a collaboration, which is a set of objects related in
a particular context, and interaction, which is a set of messages exchange among the
objects within the collaboration to achieve a desired outcome.

Fig 4.2.5 Collaboration Diagram for ai to detect social media users depression
polarity score and diagnose using auto curative therapy

21
CHAPTER 5

SYSTEM IMPLEMENTATION

22
CHAPTER 5

SYSTEM IMPLEMENTATION

5.1 LIST OF MODULES

1. Social networking web app

2. Training phase: Depression tweet classification

3. Testing phase: Predication

4. Auto motivational loader

5.2 MODULE DESCRIPTION

5.2.1 Social networking web app

Build a social networking service is an online platform which people use to


build social networks or social relationships with other people who share similar
personal or career interests, activities, backgrounds or real-life connections. Social
networking services vary in format and the number of features. The classification
model has been exposed as a REST API which was consumed by a Web application
built using Python’s Flask framework. The main features include an Admin
dashboard for visualization of Depression activities, an option to search tweets, and
automatic generation and emailing of reports of Depression activity.
5.2.1.1 Aadhar User Account Management
 New User
Create user account with aadhar number.
 Existing User

23
The existing users of Facebook will also have to upload a scanned copy of their
Aadhar Card. If they fail to do so, their profile will be suspended within the next 15
days.
5.2.1.2 Depression Analysis API
In this module we developed the API for Depression analytics on chat or post
user data. It focuses on keywords and analyzes chat or post according to a two-pole
scale (positive and negative).

5.2.2 Training Phase: Depression Tweet Classification


5.2.2.1 Depression Data Set Annotation
We used Depression data from Kaggle. The dataset in consisted of two labels,
positive and negative, while was composed of three labels of positive, neutral, and
negative. Furthermore, the dataset in was composed of five labels of positive,
somewhat positive, neutral, somewhat negative, and negative.
5.2.2.2 Pre-Processing
Datasets contain unnecessary data in raw form that can be unstructured or
semi-structured. Such unnecessary data increases training time of the model and
might degrades its performance. Pre-processing plays a vital role in improving the
efficiency of DL models and saving computational resources. Text pre-processing
boosts the prediction accuracy of the model. The preprocessing step is essential in
Depression detection. It consists of both cleaning of texts (e.g., removal of stop
words and punctuation marks), as well as spam content removal. In the proposed
model, it has been applied to remove and clean unwanted noise in text detection.
5.2.2.3 Feature Extraction

After the data pre-processing step, the next essential step is the choice of
features on a refined dataset. Supervised deep learning classifiers require textual data
in vector form to get trained on it. The textual features are converted into vector form

24
using TF and TF-IDF techniques in this project. Features extraction techniques not
only convert textual features into vector form but also helps to find significant
features necessary to make predictions. For the most part all features do no
contribute to the prediction of the target class. This will be achievable with the
intention of a term would seem a lot further in lengthy documents than short
documents because every document is variant in extent. Like the mode about
standardization:
No. of times term t shows in a document
TF(t)= ----------------------------------------------------------
Total no. of terms inside document

5.2.3 Testing Phase: Prediction


5.2.3.1 Depression Predictor
In this module, user login and give comments about the post and also chat
with the other social networking users. Finally, we used matrix factorization to
predict depressed words or text and motivate the user.
5.2.3.2 Depression Level Indicator
This module computes the final depression score by adding up the users’
emotion polarity and semantic scores together and taking their min-max
normalization value, where min and max are the minimum and maximum values of
the summation of polarity and semantic scores. This way the user depression score
lies in the range [0-1].
(polarity score + semantic score) −min
Depression score= ----------------------------------------------
max − min

25
CHAPTER 6

TESTING

26
CHAPTER 6

TESTING

TESTING AND IMPLEMENTATION

Testing is the process of executing a program or application with the intent of


finding software bugs, and to verify that the software product is fit for use.

6.1 UNIT TESTING

Unit testing is performed for testing modules against detailed design. Inputs to the
process are usually compiled modules from the coding process. Each module is
assembled into a larger unit during the unit testing process. Testing has been performed
on each phase of projects design and coding. We carry out testing of the module
interface to ensure the proper flow of information in and out of the unit while testing.
We make sure that the live streaming data is fetched from twitter and its integrity
throughout the algorithm execution by examining Natural language processing.

6.1.1 TEST OBJECTIVES


 Signup
 Login
 Logout
 Model Building
 Depression Detection

27
6.1.2 TEST CASES OF TOPIC MODELING AND EMOTION ANALYSIS

ID TEST PRE- EXPECTED ACTUAL PASS/FAIL


CONDITIONS
CASES RESULTS RESULTS

User can Successfully


Sign up Username and register to the
registered PASS
TC001 email must not application
exist previously. successfully.

PASS
TC002 Registration User can login
Log in must be done Successfully
to the
previously. application logged in
successfully.

Must exist as User can Successfully PASS


logout from logged out
TC003 Log out logged in user the application
successfully. from
already
application

User is logged Successfully PASS


TC004 Model in to the system An efficient developed
model will be efficient
Building and enter
developed. model
required inputs

User is logged
Automatically PASS
Depression in to the system extract social Successfully
TC005 Detection media news shows the
and enter feed and result
classify it.
required inputs

28
6.2 INTEGRATION TESTING

Integration testing (sometimes called integration and testing, abbreviated


(I&T) is the phase in software testing in which individual software modules are
combined and tested as a group. It occurs after unit testing and before verification
testing. Integration testing takes as its input modules that have been unit tested,
groups them in larger aggregates, applies tests defined in an integration test plan to
those aggregates, and delivers as its output the integrated system ready for system
testing.

6.3 SYSTEM TESTING

The listed tests were conducted by the admin manually at the various
development stages. Unit testing was conducted and errors are changed. The
integration testing is performed after the system integration of the web page with
the emotions portrayed and errors are rectified systems like accurately labelling
tweets etc. The results were analyzed, and the appropriate alterations were made.
The test results proved to be positive and henceforth the application is feasible, and
test approved.

29
CHAPTER 7

RESULTS AND DISCUSSION

30
CHAPTER 7

RESULTS AND DISCUSSION

7.1 RESULTS

The main purpose of our propose model is to sentiment lexicon as an extra


information pre-training a word sentiment classifier and then get the sentiment
embeddings of words including the words not in the lexicon. Combining the
sentiment embedding and its word embedding can make word representation more
accurate. Derived from a combination of feature extraction approaches using
sentiment lexicons and textual contents, these features are able to provide impressive
results in terms of depression detection.

7.2 DISCUSSION
The results and comparisons of different classifiers after data training and
testing are presented in this section. We gathered 49799 tweets from the online
resource ‘kaggle’ and translated them into English using the python library
Googletrans, which uses the Google Translate Ajax API. 42797 tweets were used to
train various ML and DL models. One seven thousand tweets were used for testing
in order to quantify accuracy and assessment metrics. As explained about evaluation
measures in chapter 9, we have evaluated accuracy, precision, recall, and f-measures
that are evaluation measures measured using LR, XGBM and Naive Bayes, LSTM-
CNN and BiLSTM. Finally, using various graphs, a comparison of models is
presented below. The findings in Table 4 show that the deep learning algorithm
(BiLSTM) is a stronger method for detecting Depression tweet classification, with
high accuracy of 98.4%.

31
CHAPTER 8

CONCLUSION AND FUTURE ENHANCEMENT

32
CHAPTER 8

CONCLUSION AND FUTURE ENHANCEMENT

8.1 CONCLUSION

Depression is a pressing issue of our society today, affecting more than 264
million people globally and still increasing. It may become a serious health issue
when it lasts more than two weeks with moderate or severe intensity. It can even
lead to suicide if a depressed person is not receiving proper treatment. This work
aims to make timely depression intensity estimation from social media, in order to
aid in a proper treatment according to the depression level. Detecting and Classifying
depression levels is critical for various different types of posts. In this project, we
proposed a framework for classifying depression levels using LE-LSTM algorithms.
By using the sentiment lexicon to train a word sentiment classifier, we can get the
sentiment embedding of each word. Concatenating the word embedding and its
sentiment embedding as the input of LE-LSTM can make a higher performance in
sentiment analysis tasks. The algorithms are designed to analyze the tweet for
emotion detection as well as for detection of suicidal thoughts among people on
social media. We validated the performance of our method by conducting extensive
experiments on a standard dataset and outperformed the other alternatives for
polarity estimation.

8.2 FUTURE ENHANCEMENT

This project leads to several promising future directions. It would be


interesting to explore the social network structure and user’s locations for identifying
the propagation of depression among the social communities. Explore the proposed

33
framework for analyzing other mental health disorders, such as anxiety,
schizophrenia, bipolarity, among others. This project will lead to the development of
automatic preliminary assessment methods based on social data.

34
ANNEXURE

35
ANNEXURE

APPENDIX 1

SOURCE CODE:

Main.py

from flask import Flask

from flask import Flask, render_template, Response, redirect, request, session, abort,
url_for

from datetime import datetime

from datetime import date

import datetime

import random

from random import seed

from random import randint

from flask_mail import Mail, Message

from flask import send_file

import re # for regular expressions

import nltk # for text manipulation

import string # for text manipulation

import warnings

36
import numpy as np

import pandas as pd # for data manipulation

import matplotlib.pyplot as plt

from nltk.stem.porter import *

#nltk.download()

#from xgboost import XGBClassifier

#import xgboost as xgb

'''from sklearn.ensemble import RandomForestClassifier

from sklearn.linear_model import LogisticRegression

from sklearn import svm

from sklearn.metrics import accuracy_score

from sklearn.model_selection import train_test_split

from sklearn.feature_extraction.text import CountVectorizer'''

import os

import time

import shutil

import hashlib

import urllib.request

import urllib.parse

37
from urllib.request import urlopen

import webbrowser

import mysql.connector

mydb = mysql.connector.connect(

host="localhost",

user="root",

passwd="",

charset="utf8",

database="depression_social_media"

app = Flask(_name_)

##session key

app.secret_key = 'abcdef'

#######

UPLOAD_FOLDER = 'static/upload'

app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

#####

#####

##email

38
print("yes")

else:

print("no")'''

if request.method == 'POST':

username1 = request.form['uname']

password1 = request.form['pass']

mycursor = mydb.cursor()

mycursor.execute("SELECT count(*) FROM ds_register where uname=%s


&& pass=%s",(username1,password1))

myresult = mycursor.fetchone()[0]

if myresult>0:

session['username'] = username1

result=" Your Logged in sucessfully**"

return redirect(url_for('userhome'))

else:

msg="Your logged in fail!!!"

return render_template('index.html',msg=msg,act=act)

39
@app.route('/register',methods=['POST','GET'])

def register():

result=""

act=""

mycursor = mydb.cursor()

if request.method=='POST':

name=request.form['name']

gender=request.form['gender']

email=request.form['email']

uname=request.form['uname']

pass1=request.form['pass']

now = datetime.datetime.now()

rdate=now.strftime("%d-%m-%Y")

mycursor.execute("SELECT count(*) FROM ds_register where


uname=%s",(uname, ))

cnt = mycursor.fetchone()[0]

if cnt==0:

mycursor.execute("SELECT max(id)+1 FROM ds_register")

40
maxid = mycursor.fetchone()[0]

if maxid is None:

maxid=1

sql = "INSERT INTO ds_register(id, name, gender, email, uname, pass)


VALUES (%s, %s, %s, %s, %s, %s)"

val = (maxid, name, gender, email, uname, pass1)

act="success"

mycursor.execute(sql, val)

mydb.commit()

print(mycursor.rowcount, "record inserted.")

act="success"

return redirect(url_for('index'))

else:

act="wrong"

result="User Already Exist!"

return render_template('register.html',act=act)

@app.route('/login',methods=['POST','GET'])

def login():

cnt=0

41
act=""

msg=""

if request.method == 'POST':

username1 = request.form['uname']

password1 = request.form['pass']

mycursor = mydb.cursor()

mycursor.execute("SELECT count(*) FROM admin where username=%s &&


password=%s",(username1,password1))

myresult = mycursor.fetchone()[0]

if myresult>0:

session['username'] = username1

result=" Your Logged in sucessfully**"

return redirect(url_for('admin'))

else:

result="Your logged in fail!!!"

return render_template('login.html',msg=msg,act=act)

42
@app.route('/userhome', methods=['GET', 'POST'])

def userhome():

uname=""

photo=""

fn=""

if 'username' in session:

uname = session['username']

name=""

print(uname)

now = datetime.datetime.now()

rdate=now.strftime("%d-%m-%Y")

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM ds_register where uname=%s",(uname, ))

value = mycursor.fetchone()

name=value[1]

if request.method=='POST':

detail=request.form['detail']

file = request.files['file'

sg1=sg.split('|')

43
sgg=len(sg1)

sn=sgg-1

rn=randint(1,sn)

sugges=sg1[rn]

nx=0

ddf=[]

for fname in os.listdir("static/motive"):

ddf.append(fname)

nx+=1

rn2=randint(1,nx)

fn=ddf[rn2]

motive=fn

elif deptype==3:

print("mail")

'''mycursor.execute("SELECT count(*) FROM ds_comment where


uname=%s",(uname, ))

cm1 = mycursor.fetchone()[0]

if cm1>0:

44
mycursor.execute("SELECT * FROM ds_contact where
cname=%s",(uname,))

fdd2 = mycursor.fetchone()

un=fdd2[1]

if cn==una or un==una:

ss=""

else:'''

#sd.append(una)

ss=""

else:

sd.append(una)

ln=len(sd)

fdata=[]

if ln>0:

for sr in sd:

mycursor.execute("SELECT * FROM ds_register where uname=%s",(sr,))

srow = mycursor.fetchone()

ffd=[]

ffd.append(srow[0])

45
ffd.append(srow[1])

ffd.append(srow[2])

ffd.append(srow[3])

ffd.append(srow[4])

ffd.append(srow[5])

ffd.append(srow[6])

ffd.append(srow[7])

ffd.append(srow[8])

ffd.append(srow[9])

fdata.append(ffd)

return
render_template('userhome.html',value=value,data=data,fdata=fdata,fn=fn)

@app.route('/cover_photo', methods=['GET', 'POST'])

def cover_photo():

uname=""

photo=""

if 'username' in session:

uname = session['username']

46
name=""

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM ds_register where uname=%s",(uname, ))

value = mycursor.fetchone()

if request.method=='POST':

file = request.files['file2']

try:

if file.filename == '':

flash('No selected file')

return redirect(request.url)

if file:

fn=file.filename

photo="C"+str(value[0])+fn

#fn1 = secure_filename(fn)

file.save(os.path.join(app.config['UPLOAD_FOLDER'], photo))

mycursor.execute("update ds_register set cover_st=1,cover_img=%s


where uname=%s", (photo,uname))

mydb.commit()

maxid=1

47
sql = "INSERT INTO ds_comment(id,uname,pid,comment,rdate,name)
VALUES (%s, %s, %s, %s, %s, %s)"

val = (maxid,uname,pid,comment,rdate,name)

mycursor.execute(sql, val)

mydb.commit()

return redirect(url_for('userhome'))

return render_template('userhome.html',value=value)

@app.route('/send_req', methods=['GET', 'POST'])

def send_req():

uname=""

photo=""

user = request.args.get('user')

act = request.args.get('act')

if 'username' in session:

uname = session['username']

name=""

now = datetime.datetime.now()

rdate=now.strftime("%d-%m-%Y")

48
mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM ds_register where uname=%s",(uname, ))

value = mycursor.fetchone()

name=value[1]

if act=="req":

mycursor.execute("SELECT max(id)+1 FROM ds_contact")

maxid = mycursor.fetchone()[0]

if maxid is None:

maxid=1

sql = "INSERT INTO ds_contact(id,uname,cname,status) VALUES (%s, %s,


%s, %s)"

val = (maxid,uname,user,'0')

mycursor.execute(sql, val)

mydb.commit()

maxid2=maxid+1

sql = "INSERT INTO ds_contact(id,uname,cname,status) VALUES (%s, %s,


%s, %s)"

val = (maxid2,user,uname,'0')

mycursor.execute(sql, val)

mydb.commit()

49
return redirect(url_for('userhome'))

return render_template('userhome.html',value=value)

@app.route('/contact', methods=['GET', 'POST'])

def contact():

uname=""

photo=""

act = request.args.get('act')

cname = request.args.get('cname')

if 'username' in session:

uname = session['username']

name=""

print(uname)

now = datetime.datetime.now()

rdate=now.strftime("%d-%m-%Y")

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM ds_register where uname=%s",(uname, ))

value = mycursor.fetchone()

###Frnd

50
mycursor.execute("SELECT * FROM ds_contact where uname=%s &&
status=1",(uname, ))

fdd = mycursor.fetchall()

fdata=[]

for rd in fdd:

mycursor.execute("SELECT * FROM ds_register where uname=%s",(rd[2], ))

fdd1 = mycursor.fetchone()

dd=[]

dd.append(fdd1[1])

dd.append(fdd1[4])

dd.append(fdd1[6])

dd.append(fdd1[7])

fdata.append(dd)

flen=len(fdata)

#######Req

mycursor.execute("SELECT * FROM ds_contact where cname=%s &&


status=0",(uname, ))

fdd2 = mycursor.fetchall()

fdata2=[]

51
for rd2 in fdd2:

mycursor.execute("SELECT * FROM ds_register where uname=%s",(rd2[1],


))

fdd11 = mycursor.fetchone()

dd1=[]

dd1.append(fdd11[1])

dd1.append(fdd11[4])

dd1.append(fdd11[6])

dd1.append(fdd11[7])

fdata2.append(dd1)

flen2=len(fdata2)

##########

if act=="ok":

mycursor.execute("update ds_contact set status=1 where uname=%s &&


cname=%s", (uname,cname))

mydb.commit()

mycursor.execute("update ds_contact set status=1 where cname=%s &&


uname=%s", (uname,cname))

mydb.commit()

return redirect(url_for('contact'))

52
return
render_template('contact.html',value=value,fdata=fdata,fdata2=fdata2,flen=flen,fle
n2=flen2)

@app.route('/messages', methods=['GET', 'POST'])

def messages():

uname=""

photo=""

act = request.args.get('act')

cname = request.args.get('cname')

if 'username' in session:

uname = session['username']

name=""

print(uname)

now = datetime.datetime.now()

rdate=now.strftime("%d-%m-%Y")

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM ds_register where uname=%s",(uname, ))

value = mycursor.fetchone()

###Frnd

53
mycursor.execute("SELECT * FROM ds_contact where uname=%s &&
status=1",(uname, ))

fdd = mycursor.fetchall()

fdata=[]

for rd in fdd:

mycursor.execute("SELECT * FROM ds_register where uname=%s",(rd[2], ))

fdd1 = mycursor.fetchone()

dd=[]

dd.append(fdd1[1])

dd.append(fdd1[4])

dd.append(fdd1[6])

dd.append(fdd1[7])

fdata.append(dd)

flen=len(fdata)

#####

mdata=[]

value2=[]

if act=="chat":

mycursor.execute("SELECT * FROM ds_register where uname=%s",(cname,


))

54
value2 = mycursor.fetchone()

mycursor.execute("SELECT * FROM ds_message where (uname=%s &&


cname=%s) || (cname=%s && uname=%s)",(uname,cname,uname,cname))

mdata = mycursor.fetchall()

value3=[]

if act=="mess":

if request.method=='POST':

message=request.form['message']

mycursor.execute("SELECT * FROM ds_register where


uname=%s",(cname, ))

value3 = mycursor.fetchone()

mycursor.execute("SELECT max(id)+1 FROM ds_message")

maxid = mycursor.fetchone()[0]

if maxid is None:

maxid=1

sql = "INSERT INTO ds_message(id,uname,cname,message) VALUES


(%s, %s, %s, %s)"

val = (maxid,uname,cname,message)

mycursor.execute(sql, val)

mydb.commit()

55
return redirect(url_for('messages',act='chat',cname=cname))

return
render_template('messages.html',value=value,fdata=fdata,value2=value2,act=act,m
data=mdata)

@app.route('/admin', methods=['GET', 'POST'])

def admin():

uname=""

if 'username' in session:

uname = session['username']

name=""

print(uname)

return render_template('admin.html')

@app.route('/process', methods=['GET', 'POST'])

def process():

uname=""

if 'username' in session:

uname = session['username']

pd.set_option("display.max_colwidth", 200)

warnings.filterwarnings("ignore") #ignore warnings

56
data =
pd.read_csv("static/data/training.1600000.processed.noemoticon.csv",encoding='la
tin-1')

dat=data.head()

data1=[]

for ss in dat.values:

data1.append(ss)

DATASET_COLUMNS = ["target", "ids", "date", "flag", "user", "TweetText"]

data.columns = DATASET_COLUMNS

dat2=data.head()

data2=[]

for ss2 in dat2.values:

data2.append(ss2)

data.drop(['ids','date','flag','user'],axis = 1,inplace = True)

dat3=data.head()

data3=[]

for ss3 in dat3.values:

data3.append(ss3)

positif_data = data[data.target==4].iloc[:25000,:]

print(positif_data.shape)

57
negative_data = data[data.target==0].iloc[:1000,:]

print(negative_data.shape)

data = pd.concat([positif_data,negative_data],axis = 0)

print(data.shape)

dat4=data.head()

data4=[]

for ss4 in dat4.values:

data4.append(ss4)

return
render_template('process.html',data1=data1,data2=data2,data3=data3,data4=data4)

@app.route('/process2', methods=['GET', 'POST'])

def process2():

uname=""

if 'username' in session:

uname = session['username']

pd.set_option("display.max_colwidth", 200)

warnings.filterwarnings("ignore") #ignore warnings

58
data =
pd.read_csv("static/data/training.1600000.processed.noemoticon.csv",encoding='la
tin-1')

data.head()

DATASET_COLUMNS = ["target", "ids", "date", "flag", "user", "TweetText"]

data.columns = DATASET_COLUMNS

data.head()

data.drop(['ids','date','flag','user'],axis = 1,inplace = True)

data.head()

positif_data = data[data.target==4].iloc[:25000,:]

print(positif_data.shape)

negative_data = data[data.target==0].iloc[:1000,:]

print(negative_data.shape)

data = pd.concat([positif_data,negative_data],axis = 0)

print(data.shape)

data['Clean_TweetText'] = data['TweetText'].str.replace("@", "")

dat=data.head()

data1=[]

59
for ss in dat.values:

data['Clean_TweetText'] = data['Clean_TweetText'].str.replace(r"http\S+",
"")

dat2=data.head()

data2=[]

for ss2 in dat2.values:

data2.append(ss2)

data['Clean_TweetText'] = data['Clean_TweetText'].str.replace("[^a-zA-Z]", " ")

dat3=data.head()

data3=[]

for ss3 in dat3.values:

data3.append(ss3)

stopwords=nltk.corpus.stopwords.words('english')

def remove_stopwords(text):

clean_text=' '.join([word for word in text.split() if word not in stopwords])

return clean_text

data['Clean_TweetText'] = data['Clean_TweetText'].apply(lambda text :


remove_stopwords(text.lower()))

dat4=data.head()

data4=[]

60
for ss4 in dat4.values:

data4.append(ss4)

data['Clean_TweetText'] = data['Clean_TweetText'].apply(lambda x: x.split())

dat5=data.head()

data5=[]

for ss5 in dat5.values:

data5.append(ss5)

stemmer = PorterStemmer()

data['Clean_TweetText'] = data['Clean_TweetText'].apply(lambda x:
[stemmer.stem(i) for i in x])

dat6=data.head()

data6=[]

for ss6 in dat6.values:

data['Clean_TweetText'] = data['Clean_TweetText'].apply(lambda x: ' '.join([w


for w in x]))

dat7=data.head()

data7=[]

for ss7 in dat7.values:

data['Clean_TweetText'] = data['Clean_TweetText'].apply(lambda x: ' '.join([w


for w in x.split() if len(w)>3]))

61
dat8=data.head()

data8=[]

for ss8 in dat8.values:

data8.append(ss8)

return
render_template('process2.html',data1=data1,data2=data2,data3=data3,data4=dta4,
data5=data5,data6=data6,data7=data7,data8=data8)

, methods=['GET', 'POST'])

def process3():

uname=""

if 'username' in session:

uname = session['username']

pd.set_option("display.max_colwidth", 200)

warnings.filterwarnings("ignore") #ignore warnings

data =
pd.read_csv("static/data/training.1600000.processed.noemoticon.csv",encoding='la
tin-1')

data.head()

DATASET_COLUMNS = ["target", "ids", "date", "flag", "user", "TweetText"]

data.columns = DATASET_COLUMNS

62
data.head()

data.drop(['ids','date','flag','user'],axis = 1,inplace = True)

positif_data = data[data.target==4].iloc[:25000,:]

print(positif_data.shape)

negative_data = data[data.target==0].iloc[:1000,:]

print(negative_data.shape)

data = pd.concat([positif_data,negative_data],axis = 0)

print(data.shape)

data.head()

data['Clean_TweetText'] = data['TweetText'].str.replace("@", "")

data.head()

data['Clean_TweetText'] = data['Clean_TweetText'].str.replace(r"http\S+", "")

data.head()

data['Clean_TweetText'] = data['Clean_TweetText'].str.replace("[^a-zA-Z]", "


")

stopwords=nltk.corpus.stopwords.words('english')

def remove_stopwords(text):

63
clean_text=' '.join([word for word in text.split() if word not in stopwords])

return clean_text

data['Clean_TweetText'] = data['Clean_TweetText'].apply(lambda text :


remove_stopwords(text.lower()))

data['Clean_TweetText'] = data['Clean_TweetText'].apply(lambda x: x.split())

plt.show()'''

depressive_words =' '.join([text for text in data['Clean_TweetText'][data['target']


== 0]])

wordcloud = WordCloud(width=800, height=500, random_state=21,


max_font_size=110).generate(depressive_words)

'''plt.figure(figsize=(10, 7))

plt.imshow(wordcloud, interpolation="bilinear")

plt.axis('off')

plt.show()'''

'''count_vectorizer = CountVectorizer(stop_words='english')

cv = count_vectorizer.fit_transform(data['Clean_TweetText'])

cv.shape

X_train,X_test,y_train,y_test = train_test_split(cv,data['target'] ,
test_size=.2,stratify=data['target'], random_state=42)

xgbc = XGBClassifier(max_depth=6, n_estimators=1000, nthread= 3)

64
xgbc.fit(X_train,y_train)

prediction_xgb = xgbc.predict(X_test)

print(accuracy_score(prediction_xgb,y_test))

rf = RandomForestClassifier(n_estimators=1000, random_state=42)

rf.fit(X_train,y_train)

prediction_rf = rf.predict(X_test)

print(accuracy_score(prediction_rf,y_test))

lr = LogisticRegression()

lr.fit(X_train,y_train)

prediction_lr = lr.predict(X_test)

print(accuracy_score(prediction_lr,y_test))

svc = svm.SVC()

svc.fit(X_train,y_train)

prediction_svc = svc.predict(X_test)

print(accuracy_score(prediction_svc,y_test))'''

filename2 = 'static/data/lexicon_enhance.csv'

dat2 = pd.read_csv(filename2, header=0)

dat22 = list(dat2.values.flatten())

cnt2=0

65
sd2=len(dat2)

data2=[]

for ss2 in dat2.values:

if i<30:

cnt2=len(ss2)

data2.append(ss2)

i+=1

cols2=cnt2

return render_template('process4.html',data2=data2)

##LE-LSTM

def load_data(stock, seq_len):

amount_of_features = len(stock.columns)

data = stock.as_matrix() #pd.DataFrame(stock)

sequence_length = seq_len + 1

result = []

for index in range(len(data) - sequence_length):

result.append(data[index: index + sequence_length])

result = np.array(result)

row = round(0.9 * result.shape[0])

66
train = result[:int(row), :]

x_train = train[:, :-1]

y_train = train[:, -1][:,-1]

x_test = result[int(row):, :-1]

y_test = result[int(row):, -1][:,-1]

x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1],


amount_of_features))

x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1],


amount_of_features))

return [x_train, y_train, x_test, y_test]

def build_model(layers):

model = Sequential()

model.add(LSTM(

input_dim=layers[0],

output_dim=layers[1],

return_sequences=True))

model.add(Dropout(0.2))

model.add(LSTM(

layers[2],

return_sequences=False))

67
model.add(Dropout(0.2))

model.add(Dense(1,init='uniform',activation='linear'))

model.compile(loss='mse',optimizer='adam',metrics=['accuracy'])

return model

@app.route('/classify_data', methods=['GET', 'POST'])

def classify_data():

nondep_len=0

tot_len=0

dep_len=0

'''dat1 = pd.read_csv("static/data/training.1600000.processed.noemoticon.csv",
header=0)

tot_len=len(dat1)

filename2 = 'static/data/feature_extracted_depressed_twits.csv'

dat2 = pd.read_csv(filename2, header=0)

dat22 = list(dat2.values.flatten())

i=0

cnt2=0

dep_len=len(dat2)

nondep_len=tot_len-dep_len

68
data2=[]

for ss2 in dat2.values:

if i<30:

cnt2=len(ss2)

data2.append(ss2)

i+=1

cols2=cnt2

#############

'''

ff=open("static/data/det1.txt","r")

det=ff.read()

ff.close()

value=det.split(",")

tot_len=value[0]

dep_len=value[1]

dd2=[int(dep_len),int(nondep_len)]

dd1=['Depressed','Non-Depressed']

doc = dd1 #list(data.keys())

69
values = dd2 #list(data.values())

# creating the bar plot

plt.bar(doc, values, color ='blue',

plt.ylim((1,int(tot_len)))

plt.xlabel("Class")

plt.ylabel("Count")

plt.title("")

rr=randint(100,999)

fn="graph4.png"

plt.xticks(rotation=20)

plt.savefig('static/data/'+fn)

#plt.close()

plt.clf()

#########

v1=int(value[3])

v2=int(value[4])

v3=int(value[5])

dep=int(dep_len)

#graph5

70
dd2=[v3,v2,v1]

ax=dd2

dd1=['Highly','Medium','Low']

doc = dd1 #list(data.keys())

values = dd2 #list(data.values())

fig = plt.figure(figsize = (10, 5))

c=['red','blue','green']

# creating the bar plot

plt.bar(doc, values, color =c,

width = 0.4)

plt.ylim((1,dep))

plt.xlabel("Depression Level")

plt.ylabel("Count")

plt.title("")

rr=randint(100,999)

fn="graph5.png"

plt.xticks(rotation=20)

plt.savefig('static/data/'+fn)

#plt.close()

71
APPENDIX 2

SCREENSHOTS

TRAINING PHASE

72
73
74
OUTPUT

75
REFERENCES

76
REFERENCES

[1] B. A. Primack, A. Shensa, J. E. Sidani, C. G. Escobar-Viera, and M. J.


Fine, ``Temporal associations between social media use and depression,''
Amer. J. Preventive Med., vol. 60, no. 2, pp. 179-188, Feb. 2021.

[2] S. Maxim, N. Ignatiev, and I. Smirnov, ``Predicting depression with


social media images,'' in Proc. 9th Int. Conf. Pattern Recognit. Appl.
Methods, vol. 2, 2020, pp. 128-138.

[3] J. A. Diaz-Garcia, M. D. Ruiz, and M. J. Martin-Bautista, ``Non-query


based pattern mining and sentiment analysis for massive microblogging
online texts,'' IEEE Access, vol. 8, pp. 78166-78182, 2020.

[4] G. Xu, Y. Meng, X. Qiu, Z. Yu, and X. Wu, ``Sentiment analysis of


comment texts based on BiLSTM,'' IEEE Access, vol. 7, pp. 51522_51532,
2019.

[5] Y. Li and H. B. Dong, ``Text emotion analysis based on CNN and


BiLSTM network feature fusion,'' Comput. Appl, vol. 38, no. 11, pp. 29-34,
2018.4

[6] A.Yadav and D. K.Vishwakarma, ``Sentiment analysis using deep


learning architectures: A review,'' Artif. Intell. Rev., vol. 53, no. 6, pp. 4335-
4385, Aug. 2020, doi: 10.1007/s10462-019-09794-5.

77

You might also like