0% found this document useful (0 votes)
19 views66 pages

Emotional Health Monitoring System

Uploaded by

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

Emotional Health Monitoring System

Uploaded by

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

An Innovative System for Monitoring Emotional Health to

Identify Individuals at Risk of Psychological Disturbances

ABSTRACT

Mental health issues, such as anxiety, depression, and other psychological disturbances, have
become a significant public health concern globally. Identifying individuals at risk of these
conditions early on can lead to timely interventions and improved outcomes. With the rise of
technology and the increasing use of smartphones and wearable devices, there is an
opportunity to develop an innovative system that can monitor emotional health in real-time,
helping to detect potential psychological disturbances before they escalate. Traditionally,
mental health assessments relied on self-reporting and periodic check-ins with mental health
professionals. These approaches often had limitations, as individuals may not always
accurately report their emotional state, and there could be significant delays between
assessments. Additionally, access to mental health services was not always readily available,
leading to potential delays in diagnosis and treatment. Therefore, the need for an innovative
system for monitoring emotional health arises from the desire to overcome the limitations of
traditional approaches. By leveraging technology, such as machine learning, natural language
processing, we can create a continuous and unobtrusive monitoring system. Such a system
could gather real-time data on an individual's emotional state, behavior, and physiological
responses. Early detection of emotional disturbances can lead to timely intervention and
support, improving the overall mental well-being of individuals and reducing the burden on
mental health services. This innovative monitoring system has the potential to significantly
improve mental health outcomes on a broader scale. It offers a proactive approach to
emotional well-being, empowering individuals to take control of their mental health and
providing an invaluable tool for mental health professionals in identifying and supporting
those at risk of psychological disturbances.
CHAPTER 1

INTRODUCTION

1.1 Overview

Mental illness is a health problem that undoubtedly impacts emotions, reasoning, and social
interaction of a person. These issues have shown that mental illness gives serious
consequences across societies and demands new strategies for prevention and intervention.
To accomplish these strategies, early detection of mental health is an essential procedure.
Medical predictive analytics will reform the healthcare field broadly as discussed by Miner et
al. [1]. Mental illness is usually diagnosed based on the individual self-report that requires
questionnaires designed for the detection of the specific patterns of feeling or social
interactions [2]. With proper care and treatment, many individuals will hopefully be able to
recover from mental illness or emotional disorder [3].

Machine learning is a technique that aims to construct systems that can improve
through experience by using advanced statistical and probabilistic techniques. It is believed to
be a significantly useful tool to help in predicting mental health. It is allowing many
researchers to acquire important information from the data, provide personalized experiences,
and develop automated intelligent systems [4]. The widely used algorithms in the field of
machine learning such as support vector machine, random forest, and artificial neural
networks have been utilized to forecast and categorize the future events [5].

Supervised learning in machine learning is the most widely applied approach in many
types of research, studies, and experiments, especially in predicting illness in the medical
field. In supervised learning, the terms, attributes, and values should be reflected in all data
instances [6]. More precisely, supervised learning is a classification technique using
structured training data [7]. Meanwhile, unsupervised learning does not need supervision to
predict. The main goal of unsupervised learning is handling data without supervision. It is
very limited for the researchers to apply unsupervised learning methods in the clinical field.

The World Health Organization (WHOTh reports the region-wise status of different
barriers in diagnosing mental health problems and encourages researchers to be equipped
with the scientific knowledge to address the issue of mental health [9]. Now, there are various
techniques to predict the state of mental health due to advancement of technology. Research
in the field of mental health has increased recently and contributed to the information and
publications about different features of mental health, which can be applied in a wide range
of problems [10]. Many steps are involved in diagnosing mental health problems, and it is not
a straightforward process that can be done quickly. Generally, the diagnosis will begin with a
specific interview that is filled with questions about symptoms, medical history, and physical
examination. Besides that, psychological tests and assessment tools are also available and are
used to diagnose a person for mental health problems. There are several types of research
carried out to investigate and examine the movements of the face to identify certain mental
disorders [11]. The increase of research in the mental health field has led to the rise of
information in the form of finding suitable solutions to reduce mental health problems.
However, the precise reasons for mental illnesses are still unclear and uncertain.

1.2 Problem Definition

The problem addressed in this research is the development of an "Innovative System for
Monitoring Emotional Health to Identify Individuals at Risk of Psychological Disturbances"
through the implementation of a chatbot.

 Emotional Health Monitoring: The system aims to monitor and assess the emotional
well-being of individuals. This involves understanding the emotions and sentiments
expressed in their text-based input.
 Identification of Risk: The system's primary objective is to identify individuals who
may be at risk of psychological disturbances based on their interactions with the
chatbot. This identification is crucial for early intervention and support.
 Chatbot Functionality: The system includes a chatbot interface that engages in
conversations with users. Users can input text messages, and the chatbot responds
based on the content and sentiment analysis of these messages.

1.3 Significance

The significance of this system lies in its potential to address several important aspects of
mental health and support:

 Early Intervention: By monitoring user interactions and identifying potential signs of


psychological disturbances, the system can enable early intervention and support for
individuals who may be struggling with emotional or mental health issues.
 Accessible Support: A chatbot provides an easily accessible and non-judgmental
platform for individuals to express their emotions and seek help or guidance. It can
operate 24/7, ensuring that support is available whenever needed.
 Data-Driven Insights: The system can accumulate a large dataset of user interactions
over time. Analyzing this data can provide valuable insights into trends, common
issues, and potentially identify at-risk populations more broadly.
 Reducing Stigma: Chatbots can help reduce the stigma associated with seeking help
for mental health issues. People may be more comfortable sharing their feelings and
concerns with a virtual entity rather than a human.
 Scalability: Once developed, the chatbot system can be scaled to serve a large number
of users simultaneously, making it a cost-effective solution for providing emotional
support and monitoring.
 Research Tool: The system, with appropriate data anonymization and consent, could
also serve as a valuable tool for mental health research, helping researchers better
understand emotional trends and challenges.

Finally, the proposed system has the potential to make a positive impact on mental health
support and early intervention by leveraging chatbot technology and sentiment analysis to
identify and assist individuals at risk of psychological disturbances.

CHAPTER 2
LITERATURE SURVEY
According to the paper by Greenstein et al., classification of childhood-onset schizophrenia
has been performed [12]. The data consist of genetic information, clinical information, and
brain magnetic resonance imaging. The authors use a random forest method to calculate the
probability of mental disorder. Random forest is being used in this paper because it has lower
error rates compared with other methods. The accuracy of 73.7% is obtained after the
classification.

In one of the research works conducted by Jo et al., they used network analysis and machine
learning approaches to identify 48 schizophrenia patients and 24 healthy controls [13]. The
network properties were rebuilt using the probabilistic brain tractography. After that, machine
learning is being applied to label schizophrenia patients and health controls. Based on the
result, the highest accuracy is achieved by the random forest model with an accuracy of
68.6% followed by the multinomial naive Bayes with an accuracy of 66.9%. Then, the
XGBoost accuracy score is 66.3% and the support vector machine shows an accuracy of
58.2%. Most of the machine learning algorithms show promising levels of performance in
predicting schizophrenia patients and healthy controls.

The support vector machine, which is a machine learning model, has been implemented to
classify schizophrenia patients [14]. The data set is obtained from the 20 schizophrenia
patients and 20 healthy controls. Then, the support vector machine algorithm is used for
classification with the help of functional magnetic resonance imaging and single nucleotide
polymorphism. After the classification, an accuracy of 0.82 is achieved with the functional
magnetic resonance imaging. For the single nucleotide polymorphism, an accuracy of 74% is
obtained.

Srinivasagopalan et al. [15] used a deep learning model to diagnose schizophrenia. The
National Institute of Health provides the data set for the experiments. The accuracy of each
machine learning algorithm is obtained and recorded. The results obtained from the
experiment show that deep learning showed the highest accuracy with 94.44%. The random
forest recorded an accuracy of 83.33% followed by logistic regression with an accuracy of
82.77%. Then, the support vector machine showed an accuracy of 82.68% in this experiment.

In another study conducted by Pla¨schke et al., the schizophrenia patients were distinguished
from the matched health controls based on the resting-state functional connectivity [16].
Resting-state functional connectivity could be used as a spot of functional dysregulation in
specific networks that are affected in schizophrenia. The authors have used support vector
machine classification and achieved 68% accuracy.

Pinaya et al. applied the deep belief network to interpret features from neuromorphometry
data that consist of 83 healthy controls and 143 schizophrenia patients [17]. The model can
achieve an accuracy of 73.6%; meanwhile, the support vector machine obtains an accuracy of
68.1%. The model can detect the massive difference between classes involving cerebrum
components. In 2018, Pinaya et al. proposed a practical approach to examine the brain-based
disorders that do not require a variety of cases [18]. The authors used a deep autoencoder and
can produce different values and patterns of neuroanatomical deviations.

A machine learning algorithm is developed to predict the clinical remission from a 12-week
course of citalopram [19]. Data are collected from the 1949 patients that experience
depression of level 1. A total of 25 variables from the data set are selected to make a better
prediction outcome. Then, the gradient boosting method is being deployed for the prediction
because of its characteristics that combine the weak predictive models when built. An
accuracy of 64.6% is obtained by using the gradient boosting method.

In order to identify depression and anxiety at an early age, a model has been proposed by
Ahmed et al. [20]. The model involves psychological testing, and machine learning
algorithms such as convolutional neural network, support vector machine, linear discriminant
analysis, and K-nearest neighbour have been used to classify the intensity level of the anxiety
and depression, which consists of two data sets. Based on the results obtained, the
convolutional neural network achieved the highest accuracy of 96% for anxiety and 96.8%
for depression. The support vector machine showed a great result and was able to obtain an
accuracy of 95% for anxiety and 95.8% for depression. Besides that, the linear discriminant
analysis reached the accuracy of 93% for anxiety and 87.9% for depression. Meanwhile, the
K-nearest neighbour obtained the lowest accuracy among the models with 70.96% for anxiety
and 81.82% for depression. Hence the convolutional neural network can be a helpful model
to assist psychologists and counsellors for making the treatments efficient.
CHAPTER 3

EXISTING TECHNIQUES
ML falls under the larger canvas of Artificial Intelligence. ML seeks to build intelligent
systems or machines that can automatically learn and train themselves through experience,
without being explicitly programmed or requiring any human intervention. In this sense, ML
is a continuously evolving activity. It aims to understand the data structure of the dataset at
hand and accommodate the data into ML models that can be used by companies and
organizations. Following are the benefits of ML.

 Enhanced decision-making: ML uses advanced algorithms to improve the decision-


making process capacity. It facilitates innovative models and business services
simultaneously. It provides a deep understanding of the variations and types of data
patterns. You can determine which step to take next based on the variations and data
patterns.
 Increases business productivity: It improves the business process and productivity,
contributing to business growth. It helps you to adapt to the changing situations at
workplaces quickly. The data continue to be updated daily. So, the work environment,
too, keeps on changing quickly. ML reduces the chances of error occurrence by half.
Hence, it boosts business productivity. This aspect is important to consider when
carrying out deep learning vs neural network.
 Removes manual data entry: One of the most common concerns in many
organizations is the usage of duplicate records. ML algorithms use predictive models
that significantly avoid any errors caused by manual data entry. The corresponding
programs use the discovered data to enhance these processes. Hence, the employees
can save time to focus on other important business tasks.
 Guarantees customer satisfaction: The ML algorithms are uniquely designed to
continue attaining experience with time. They are accurate and efficient. These
algorithms improve the machines’ decision-making skills. ML can anyhow find a way
to make accurate decisions or predictions, although the data is overwhelming and
ever-increasing. It benefits businesses with the latest market opportunities related to
revenue. As a result, it can satisfy the customers’ expectations and boost your
business’ sales in less time. Moreover, it can quickly recognize threats in the market.
You can compare deep learning vs neural networks based on this aspect to have a
clear judgment.
 Provides product recommendation: Unsupervised research assists in the development
of suggestion systems depending on goods. Currently, most e-commerce platforms
use ML to provide product recommendations. ML algorithms use the consumers’
purchasing experience to balance it with the assets’ huge inventory. This helps in
detecting secret trends and connects identical products. Finally, these goods are
recommended to the consumers.
 Detects spam: ML is widely used for spam detection. It uses spam filters to identify
spam and phishing communications.
 Improves network security: ML improves an organization’s security. It helps
organizations to develop new systems capable of quickly and efficiently recognizing
unknown threats. It can track abnormalities present in network activity and
automatically execute relevant actions. When the ML algorithm is used for self-
training, it removes manual research and analysis. So, it enhances the organization’s
network security. Many deep learning neural networks are also used for this purpose.
 Simplifies business analysis: ML is used in business analysis that involves huge
volumes of precise and quantitative historical data. It is widely used for algorithmic
trading, portfolio management, fraud detection, and lending in finance. The future ML
applications for finance will entail Chatbots and a few other interfaces for improving
customer service, security, and sentiment analysis. Many neural networks and deep
learning algorithms are also used to streamline finance analysis.

3.1 DISADVANATGES

 ML Model makes decisions based on what it has learnt from the data. As a result,
while ML models may learn from data, they may need some human interaction in the
early stages.
 Moreover, its performance is poor with large dataset.
CHAPTER 4

PROPOSED METHODOLOGY

4.1 Overview

An "Innovative System for Monitoring Emotional Health to Identify Individuals at Risk of


Psychological Disturbances" is a conceptual framework or technological solution designed to
address the critical issue of mental health monitoring and early identification of individuals
who may be at risk of psychological disturbances. The primary objective of this innovative
system is to proactively monitor the emotional well-being of individuals and identify signs or
patterns that suggest they may be at risk of psychological disturbances or mental health
issues. It aims to provide timely support and intervention to those in need.

Figure 4.1: Overall design of proposed system.

Below are the main components and features:


 Chatbot Interface: The system often utilizes a chatbot as its user interface. Users can
interact with the chatbot through text-based messages, providing them with a
comfortable and non-judgmental platform to express their feelings and emotions.
 Data Collection: The system collects and analyses user data, specifically their text-
based input. This data can include conversations, responses to predefined prompts, or
free-form text input. The key is to gather textual information that reflects the user's
emotional state.
 Natural Language Processing (NLP): The system employs NLP techniques to
understand and interpret the user's text input. This involves sentiment analysis,
emotion recognition, and context understanding to gauge the user's emotional state
and identify potential concerns.

4.2 Data Preprocessing

Data pre-processing is a process of preparing the raw data and making it suitable for a
machine learning model. It is the first and crucial step while creating a machine learning
model. When creating a machine learning project, it is not always a case that we come across
the clean and formatted data. And while doing any operation with data, it is mandatory to
clean it and put in a formatted way. So, for this, we use data pre-processing task. A real-world
data generally contains noises, missing values, and maybe in an unusable format which
cannot be directly used for machine learning models. Data pre-processing is required tasks
for cleaning the data and making it suitable for a machine learning model which also
increases the accuracy and efficiency of a machine learning model.

 Getting the dataset


 Importing libraries
 Importing datasets
 Finding Missing Data
 Encoding Categorical Data
 Splitting dataset into training and test set

Importing Libraries: To perform data preprocessing using Python, we need to import some
predefined Python libraries. These libraries are used to perform some specific jobs. There are
three specific libraries that we will use for data preprocessing, which are:
Numpy: Numpy Python library is used for including any type of mathematical operation in
the code. It is the fundamental package for scientific calculation in Python. It also supports to
add large, multidimensional arrays and matrices. So, in Python, we can import it as:

import numpy as nm

Here we have used nm, which is a short name for Numpy, and it will be used in the whole
program.

Matplotlib: The second library is matplotlib, which is a Python 2D plotting library, and with
this library, we need to import a sub-library pyplot. This library is used to plot any type of
charts in Python for the code. It will be imported as below:

import matplotlib.pyplot as mpt

Here we have used mpt as a short name for this library.

Pandas: The last library is the Pandas library, which is one of the most famous Python
libraries and used for importing and managing the datasets. It is an open-source data
manipulation and analysis library. Here, we have used pd as a short name for this library.
Consider the below image:

Handling Missing data: The next step of data preprocessing is to handle missing data in the
datasets. If our dataset contains some missing data, then it may create a huge problem for our
machine learning model. Hence it is necessary to handle missing values present in the dataset.
There are mainly two ways to handle missing data, which are:

 By deleting the particular row: The first way is used to commonly deal with null
values. In this way, we just delete the specific row or column which consists of null
values. But this way is not so efficient and removing data may lead to loss of
information which will not give the accurate output.

 By calculating the mean: In this way, we will calculate the mean of that column or
row which contains any missing value and will put it on the place of missing value.
This strategy is useful for the features which have numeric data such as age, salary,
year, etc.

Encoding Categorical data: Categorical data is data which has some categories such as, in
our dataset; there are two categorical variables, Country, and Purchased. Since machine
learning model completely works on mathematics and numbers, but if our dataset would have
a categorical variable, then it may create trouble while building the model. So, it is necessary
to encode these categorical variables into numbers.

Feature Scaling: Feature scaling is the final step of data preprocessing in machine learning.
It is a technique to standardize the independent variables of the dataset in a specific range. In
feature scaling, we put our variables in the same range and in the same scale so that no
variable dominates the other variable. A machine learning model is based on Euclidean
distance, and if we do not scale the variable, then it will cause some issue in our machine
learning model. Euclidean distance is given as:

Figure 4.2: Feature scaling

If we compute any two values from age and salary, then salary values will dominate the age
values, and it will produce an incorrect result. So, to remove this issue, we need to perform
feature scaling for machine learning.

4.3 Splitting the Dataset

In machine learning data preprocessing, we divide our dataset into a training set and test set.
This is one of the crucial steps of data preprocessing as by doing this, we can enhance the
performance of our machine learning model. Suppose if we have given training to our
machine learning model by a dataset and we test it by a completely different dataset. Then, it
will create difficulties for our model to understand the correlations between the models. If we
train our model very well and its training accuracy is also very high, but we provide a new
dataset to it, then it will decrease the performance. So we always try to make a machine
learning model which performs well with the training set and also with the test dataset. Here,
we can define these datasets as:

Figure 4.3: Splitting the dataset.

Training Set: A subset of dataset to train the machine learning model, and we already know
the output.

Test set: A subset of dataset to test the machine learning model, and by using the test set,
model predicts the output.

For splitting the dataset, we will use the below lines of code:

from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 0.2, random_state=0)

Explanation

 In the above code, the first line is used for splitting arrays of the dataset into random
train and test subsets.

 In the second line, we have used four variables for our output that are

 x_train: features for the training data

 x_test: features for testing data

 y_train: Dependent variables for training data

 y_test: Independent variable for testing data


 In train_test_split() function, we have passed four parameters in which first two are
for arrays of data, and test_size is for specifying the size of the test set. The test_size
maybe .5, .3, or .2, which tells the dividing ratio of training and testing sets.

 The last parameter random_state is used to set a seed for a random generator so that
you always get the same result, and the most used value for this is 42.

4.4 TF-IDF Feature Extraction

TF-IDF, short for Term Frequency-Inverse Document Frequency, is a commonly used


technique in NLP to determine the significance of words in a document or corpus. To give
some background context, a survey conducted in 2015 showed that 83% of text-based
recommender systems in digital libraries use TF-IDF for extracting textual features. That’s
how popular the technique is. Essentially, it measures the importance of a word by comparing
its frequency within a specific document with the frequency to its frequency in the entire
corpus. The underlying assumption is that a word that occurs more frequently within a
document but rarely in the corpus is particularly important in that document.

4.4.1 Mathematical formula for calculating TF-IDF

TF (Term Frequency) is determined by calculating the frequency of a word in a document


and dividing it by the total number of words in the document.

 TF = (Number of times the word appears in the document) / (Total number of words
in the document)
 IDF (Inverse Document Frequency), on the other hand, measures the importance of a
word within the corpus as a whole. It is calculated as:
 IDF = log((Total number of documents in the corpus) / (Number of documents
containing the word))

The tf-idf value increases in proportion to the number of times a word appears in the
document but is often offset by the frequency of the word in the corpus, which helps to adjust
with respect to the fact that some words appear more frequently in general. TF-IDF use two
statistical methods, first is Term Frequency and the other is Inverse Document Frequency.
Term frequency refers to the total number of times a given term t appears in the document
doc against (per) the total number of all words in the document and The inverse document
frequency measure of how much information the word provides. It measures the weight of a
given word in the entire document. IDF show how common or rare a given word is across all
documents. TF-IDF can be computed as tf * idf

Fig. 4.4: TF-IDF block diagram.

TF-IDF do not convert directly raw data into useful features. Firstly, it converts raw strings or
dataset into vectors and each word has its own vector. Then we’ll use a particular technique
for retrieving the feature like Cosine Similarity which works on vectors, etc.

Terminology

t — term (word)

d — document (set of words)

N — count of corpus

corpus — the total document set

Step 1: Term Frequency (TF): Suppose we have a set of English text documents and wish
to rank which document is most relevant to the query, “Data Science is awesome!” A simple
way to start out is by eliminating documents that do not contain all three words “Data” is”,
“Science”, and “awesome”, but this still leaves many documents. To further distinguish them,
we might count the number of times each term occurs in each document; the number of times
a term occurs in a document is called its term frequency. The weight of a term that occurs in a
document is simply proportional to the term frequency.

tf (t , d )=count of t∈d /number of words∈d

Step 2: Document Frequency: This measures the importance of document in whole set of
corpora, this is very similar to TF. The only difference is that TF is frequency counter for a
term t in document d, whereas DF is the count of occurrences of term t in the document set N.
In other words, DF is the number of documents in which the word is present. We consider
one occurrence if the term consists in the document at least once, we do not need to know the
number of times the term is present.

df (t)=occurrence of t∈documents

Step 3: Inverse Document Frequency (IDF): While computing TF, all terms are considered
equally important. However, it is known that certain terms, such as “is”, “of”, and “that”, may
appear a lot of times but have little importance. Thus, we need to weigh down the frequent
terms while scale up the rare ones, by computing IDF, an inverse document frequency factor
is incorporated which diminishes the weight of terms that occur very frequently in the
document set and increases the weight of terms that occur rarely. The IDF is the inverse of
the document frequency which measures the informativeness of term t. When we calculate
IDF, it will be very low for the most occurring words such as stop words (because stop words
such as “is” is present in almost all of the documents, and N/df will give a very low value to
that word). This finally gives what we want, a relative weightage.

idf (t)=N /df

Now there are few other problems with the IDF, in case of a large corpus, say 100,000,000,
the IDF value explodes, to avoid the effect we take the log of idf . During the query time,
when a word which is not in vocab occurs, the df will be 0. As we cannot divide by 0, we
smoothen the value by adding 1 to the denominator.

idf (t)=log(N /(df +1))

The TF-IDF now is at the right measure to evaluate how important a word is to a document in
a collection or corpus. Here are many different variations of TF-IDF but for now let us
concentrate on this basic version.

tf −idf (t , d )=tf (t , d )∗log ( N /(df + 1))

Step 4: Implementing TF-IDF: To make TF-IDF from scratch in python, let’s imagine those
two sentences from different document:

first sentence: “Data Science is the sexiest job of the 21st century”.

second sentence: “machine learning is the key for data science”.


4.5 LSTM Model

Deep learning is a new research direction in the field of artificial intelligence. It is developed
on the basis of shallow neural networks with the improvement of computer hardware levels
and the explosive growth of the current data volume. Deep learning and shallow neural
network structure are both layered. Each layer will process the data input to the model and
combine low-level features into potential high-level features by learning data rules.
Compared with shallow models, deep learning can express complex high dimensionality such
as high-variable functions and find the true relationships within the original data better. In the
1980s, artificial neural network back propagation algorithm was born. This method can
automatically learn data rules from a large amount of training data without manual
intervention. At present, deep learning is the most concerned research direction in the field of
artificial intelligence, which completely subverts the shallow model in traditional machine,
proposes a deep learning network model, and elevates it to a new height from theory to
application. CNN (convolutional neural network) and RNN are two types of classical deep
learning network structures now.

Fig. 4.5: LSTM model structure.

Because there are connections between neurons in the RNN layer, the network can learn the
change law of sequence data before and after, and the internal sequence rules of data is easy
to be mined. Thus, RNN is widely used in the field of sequence data processing such as
speech recognition and machine translation. However, this structure also has some problems.
When data is transmitted backward, the problem of gradient disappearance or gradient
explosion is unavoidable, which limits its processing of long-term dependencies. The LSTM
network changes the way of gradient transmission during backpropagation by adding
multiple special computing nodes in the hidden layer of RNN, which effectively slows the
problem of gradient disappearance or gradient explosion. Its model structure is shown in
Figure 4.5.

Where ht−1 represents the output of the previous cell, and x t represents the input of the current
cell. σ represents the sigmoid function. The difference between LSTM and RNN is that it
adds a ‘‘processor’’ to the algorithm to determine the usefulness of the information. The
structure of this processor is called a cell. Three gates are placed in a cell, which are called
Input gate, Forget gate, and Output gate. A piece of information enters the LSTM network,
and it can be judged whether it is useful according to the rules. Only the information that
meets the algorithm authentication will be left, and the non-conforming information will be
forgotten through the Forget gate.

FORGET GATE

The first step for data entering the LSTM is to decide what information should be lost and
what retained. This decision is made by the Forget gate, which reads h and x and outputs a
value between 0 and 1, where 1 means ‘‘complete reserved’’, 0 means ‘‘completely
discarded’’. Forget gate is calculated as:

In the formula, ft is the calculation result of the Forget gate which is mainly used to control
the retention of the information transmitted from the unit state at the previous moment to the
unit state at the current moment. [ ] indicates that the two vectors are spliced, h t−1 is the output
of the unit at the previous moment, and are the weight and bias of Forget gate, W f and bf are
Sigmoid activation functions.

INPUT GATE

Input gate determines the addition of new information, and its operation process includes
sigmoid layer and tanh layer. The sigmoid layer determines the information that needs to be
updated. The calculation formula is:
In the formula, it is the calculation result of the input gate, and the input gate also has
independent weight and bias. The role of the tanh layer is to generate a vector of candidate
update information. Its calculation formula is:

~
Ct is the unit state of the current input, the unit state of the current moment is C t, and its
calculation formula is:

OUTPUT GATE

Output gate is roughly the same as the Input gate, and its operation flow includes sigmoid
layer and tanh layer. The sigmoid layer determines the output part of the information, and the
calculation formula is:

Finally get the output of the current moment ht:

The forward propagation of LSTM calculates the cell state C t and ht the output of the current
moment and completes the forward propagation calculation of the network. The
backpropagation of LSTM is like the back-propagation principle of RNN. Finally, the
weights and biases of all parts of the network are updated to complete the model training.

4.5.1 RNN

Deep neural networks are a network with automatic adjustment of network parameters, which
can iteratively calculate data according to the set coordinates and models. The training
process of deep learning model is actually a process of constantly tuning the ownership
values of nodes which are all used as tools to describe data features. The key to whether the
model can describe the features of things lies on the final training results of each weight. The
deep neural network takes the neural network as the carrier and focuses on the depth. It can
be said to be a general term, including the recurrent neural network with multiple hidden
layers, the all-connected network and the convolutional neural network. Recurrent neural
networks are mainly used for sequence data processing and have a certain memory effect.
The long-term and short-term memory networks derived from them are better at processing
long-term dependencies. Convolutional neural networks focus on spatial mapping. And image
data is particularly suitable for feature extraction of various networks. When the input data is
dependent and sequential, the results of CNN are generally not good. There is no correlation
between the previous input of CNN and the next input. The RNN network appeared in the
1980s. It is designed a different number of hidden layers. Each hidden layer stores
information and selectively forgets some information. In this way, the data characteristics of
the sequence changes of the data can be extracted. RNN has not only achieved many results
in the fields of text processing and speech processing, but also been widely used in the fields
of speech recognition, machine translation, text generation, sentiment analysis, and video
behavior recognition. RNN is good at processing time series data and can describe the
context of the data on the time axis. The RNN structure is shown in the Fig. 4.6.

Fig. 4.6: RNN structure overview.

As can be seen from the figure above, the RNN structure is relatively simple. It
mainly consists of an Input Layer, a Hidden Layer, an Output Layer, and an arrow in the
Hidden Layer represents the cyclic update of data, which is the method to realize the time
memory function. The input levels of this paper were: age, BMI, marital status, education
level, family income, alcohol consumption, smoking, exposure to high temperature, noise,
shift work. The 10-dimensional data were normalized and input into the RNN model. After
the extraction of hidden layer depth features, the output layer output the sequence of lipid
health status, in which 1 represented normal lipid status and 0 represented abnormal lipid
status.

FORWARD PROPAGATION OF RNN

Figure 4.7 shows the hierarchical expansion of the Hidden Layer. T −1, t, t +1 represent the
time series. X represents the input sample. St represents the memory of the sample at time t.
W represents the weight of the input. U indicates the weight of the input sample at this
moment, and V indicates the weight of the output sample.

Fig. 4.7: Hierarchical expansion of hidden layers.

At time t = 1, generally initialize the input, randomly initialize W, U, V, and perform the
following formula calculation:

Among them, f and g are activation functions, where f can be activation functions such as
tanh, ReLU, sigmoid. G is usually a SoftMax function. Time advancing, the state s1 as the
memory state of time 1 will participate in the prediction activity of the next time, that is:
And so on, the final output value can be obtained as:

Here, W, U, and V are equal at every moment which is weight sharing.

Fig. 4.8: RNN training process.

BACK PROPAGATION OF RNN

The back propagation process of RNN is the updating process of weight parameters W, U,
and V. Each output value ot will produce an error value Et, tanh the total error value can be
expressed as: Since the output of each step depends on not only the network of the current
step but also the state of the previous steps, the Backpropagation Through Time (BPTT)
algorithm is used to pass the error value at the output back, and the gradient descent method
is used to perform the weight update.
The model training process of RNN is shown in Fig. 4.8.
CHAPTER 5

UML DIAGRAMS
UML stands for Unified Modeling Language. UML is a standardized general-purpose
modeling language in the field of object-oriented software engineering. The standard is
managed, and was created by, the Object Management Group. The goal is for UML to
become a common language for creating models of object-oriented computer software. In its
current form UML is comprised of two major components: a Meta-model and a notation. In
the future, some form of method or process may also be added to; or associated with, UML.

The Unified Modeling Language is a standard language for specifying, Visualization,


Constructing and documenting the artifacts of software system, as well as for business
modeling and other non-software systems. The UML represents a collection of best
engineering practices that have proven successful in the modeling of large and complex
systems. The UML is a very important part of developing objects-oriented software and the
software development process. The UML uses mostly graphical notations to express the
design of software projects.

GOALS: The Primary goals in the design of the UML are as follows:

 Provide users a ready-to-use, expressive visual modeling Language so that they can
develop and exchange meaningful models.
 Provide extendibility and specialization mechanisms to extend the core concepts.
 Be independent of particular programming languages and development process.
 Provide a formal basis for understanding the modeling language.
 Encourage the growth of OO tools market.
 Support higher level development concepts such as collaborations, frameworks,
patterns and components.
 Integrate best practices.

Class Diagram

The class diagram is used to refine the use case diagram and define a detailed design of the
system. The class diagram classifies the actors defined in the use case diagram into a set of
interrelated classes. The relationship or association between the classes can be either an “is-a”
or “has-a” relationship. Each class in the class diagram may be capable of providing certain
functionalities. These functionalities provided by the class are termed “methods” of the class.
Apart from this, each class may have certain “attributes” that uniquely identify the class.

Use case diagram

A use case diagram in the Unified Modeling Language (UML) is a type of behavioral
diagram defined by and created from a Use-case analysis. Its purpose is to present a graphical
overview of the functionality provided by a system in terms of actors, their goals (represented
as use cases), and any dependencies between those use cases. The main purpose of a use case
diagram is to show what system functions are performed for which actor. Roles of the actors
in the system can be depicted.
Data Flow Diagram

A data flow diagram (DFD) is a graphical or visual representation using a standardized set of
symbols and notations to describe a business’s operations through data movement.

Sequence Diagram

A sequence diagram in Unified Modeling Language (UML) 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, as parallel vertical lines (“lifelines”),
different processes or objects that live simultaneously, and as horizontal arrows, the messages
exchanged between them, in the order in which they occur. This allows the specification of
simple runtime scenarios in a graphical manner.
Activity diagram: Activity diagram is another important diagram in UML to describe the
dynamic aspects of the system.
Deployment diagram

A deployment diagram in the Unified Modeling Language models the physical deployment of
artifacts on nodes. To describe a web site, for example, a deployment diagram would show
what hardware components (“nodes”) exist (e.g., a web server, an application server, and a
database server), what software components (“artifacts”) run on each node (e.g., web
application, database), and how the different pieces are connected (e.g., JDBC, REST, RMI).
The nodes appear as boxes, and the artifacts allocated to each node appear as rectangles
within the boxes. Nodes may have sub nodes, which appear as nested boxes. A single node in
a deployment diagram may conceptually represent multiple physical nodes, such as a cluster
of database servers.

Component diagram: Component diagram describes the organization and wiring of the
physical components in a system.
CHAPTER 6

SOFTWARE ENVIRONMENT

What is Python?

Below are some facts about Python.

 Python is currently the most widely used multi-purpose, high-level programming


language.
 Python allows programming in Object-Oriented and Procedural paradigms. Python
programs generally are smaller than other programming languages like Java.
 Programmers have to type relatively less and indentation requirement of the language,
makes them readable all the time.
 Python language is being used by almost all tech-giant companies like – Google,
Amazon, Facebook, Instagram, Dropbox, Uber… etc.

The biggest strength of Python is huge collection of standard library which can be used for
the following –

 Machine Learning
 GUI Applications (like Kivy, Tkinter, PyQt etc. )
 Web frameworks like Django (used by YouTube, Instagram, Dropbox)
 Image processing (like Opencv, Pillow)
 Web scraping (like Scrapy, BeautifulSoup, Selenium)
 Test frameworks
 Multimedia

Advantages of Python

Let’s see how Python dominates over other languages.

10. Extensive Libraries

Python downloads with an extensive library and it contain code for various purposes like
regular expressions, documentation-generation, unit-testing, web browsers, threading,
databases, CGI, email, image manipulation, and more. So, we don’t have to write the
complete code for that manually.
2. Extensible

As we have seen earlier, Python can be extended to other languages. You can write some of
your code in languages like C++ or C. This comes in handy, especially in projects.

3. Embeddable

Complimentary to extensibility, Python is embeddable as well. You can put your Python code
in your source code of a different language, like C++. This lets us add scripting capabilities to
our code in the other language.

4. Improved Productivity

The language’s simplicity and extensive libraries render programmers more productive than
languages like Java and C++ do. Also, the fact that you need to write less and get more things
done.

5. IOT Opportunities

Since Python forms the basis of new platforms like Raspberry Pi, it finds the future bright for
the Internet Of Things. This is a way to connect the language with the real world.

6. Simple and Easy

When working with Java, you may have to create a class to print ‘Hello World’. But in
Python, just a print statement will do. It is also quite easy to learn, understand, and code. This
is why when people pick up Python, they have a hard time adjusting to other more verbose
languages like Java.

7. Readable

Because it is not such a verbose language, reading Python is much like reading English. This
is the reason why it is so easy to learn, understand, and code. It also does not need curly
braces to define blocks, and indentation is mandatory. This further aids the readability of the
code.

8. Object-Oriented

This language supports both the procedural and object-oriented programming paradigms.
While functions help us with code reusability, classes and objects let us model the real world.
A class allows the encapsulation of data and functions into one.
9. Free and Open-Source

Like we said earlier, Python is freely available. But not only can you download Python for
free, but you can also download its source code, make changes to it, and even distribute it. It
downloads with an extensive collection of libraries to help you with your tasks.

10. Portable

When you code your project in a language like C++, you may need to make some changes to
it if you want to run it on another platform. But it isn’t the same with Python. Here, you need
to code only once, and you can run it anywhere. This is called Write Once Run Anywhere
(WORA). However, you need to be careful enough not to include any system-dependent
features.

11. Interpreted

Lastly, we will say that it is an interpreted language. Since statements are executed one by
one, debugging is easier than in compiled languages.

Any doubts till now in the advantages of Python? Mention in the comment section.

Advantages of Python Over Other Languages

10. Less Coding

Almost all of the tasks done in Python requires less coding when the same task is done in
other languages. Python also has an awesome standard library support, so you don’t have to
search for any third-party libraries to get your job done. This is the reason that many people
suggest learning Python to beginners.

2. Affordable

Python is free therefore individuals, small companies or big organizations can leverage the
free available resources to build applications. Python is popular and widely used so it gives
you better community support.

The 2019 Github annual survey showed us that Python has overtaken Java in the most
popular programming language category.
3. Python is for Everyone

Python code can run on any machine whether it is Linux, Mac or Windows. Programmers
need to learn different languages for different jobs but with Python, you can professionally
build web apps, perform data analysis and machine learning, automate things, do web
scraping and also build games and powerful visualizations. It is an all-rounder programming
language.

Disadvantages of Python

So far, we’ve seen why Python is a great choice for your project. But if you choose it, you
should be aware of its consequences as well. Let’s now see the downsides of choosing Python
over another language.

10. Speed Limitations

We have seen that Python code is executed line by line. But since Python is interpreted, it
often results in slow execution. This, however, isn’t a problem unless speed is a focal point
for the project. In other words, unless high speed is a requirement, the benefits offered by
Python are enough to distract us from its speed limitations.

2. Weak in Mobile Computing and Browsers

While it serves as an excellent server-side language, Python is much rarely seen on the client-
side. Besides that, it is rarely ever used to implement smartphone-based applications. One
such application is called Carbonnelle.

The reason it is not so famous despite the existence of Brython is that it isn’t that secure.

3. Design Restrictions

As you know, Python is dynamically typed. This means that you don’t need to declare the
type of variable while writing the code. It uses duck-typing. But wait, what’s that? Well, it
just means that if it looks like a duck, it must be a duck. While this is easy on the
programmers during coding, it can raise run-time errors.

4. Underdeveloped Database Access Layers


Compared to more widely used technologies like JDBC (Java DataBase Connectivity) and
ODBC (Open DataBase Connectivity), Python’s database access layers are a bit
underdeveloped. Consequently, it is less often applied in huge enterprises.

5. Simple

No, we’re not kidding. Python’s simplicity can indeed be a problem. Take my example. I
don’t do Java, I’m more of a Python person. To me, its syntax is so simple that the verbosity
of Java code seems unnecessary.

This was all about the Advantages and Disadvantages of Python Programming Language.

Modules Used in Project

NumPy

NumPy is a general-purpose array-processing package. It provides a high-performance


multidimensional array object, and tools for working with these arrays.

It is the fundamental package for scientific computing with Python. It contains various
features including these important ones:

 A powerful N-dimensional array object


 Sophisticated (broadcasting) functions
 Tools for integrating C/C++ and Fortran code
 Useful linear algebra, Fourier transform, and random number capabilities

Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional
container of generic data. Arbitrary datatypes can be defined using NumPy which allows
NumPy to seamlessly and speedily integrate with a wide variety of databases.

Pandas

Pandas is an open-source Python Library providing high-performance data manipulation and


analysis tool using its powerful data structures. Python was majorly used for data munging
and preparation. It had very little contribution towards data analysis. Pandas solved this
problem. Using Pandas, we can accomplish five typical steps in the processing and analysis
of data, regardless of the origin of data load, prepare, manipulate, model, and analyze. Python
with Pandas is used in a wide range of fields including academic and commercial domains
including finance, economics, Statistics, analytics, etc.
Matplotlib

Matplotlib is a Python 2D plotting library which produces publication quality figures in a


variety of hardcopy formats and interactive environments across platforms. Matplotlib can be
used in Python scripts, the Python and Ipython shells, the Jupyter Notebook, web application
servers, and four graphical user interface toolkits. Matplotlib tries to make easy things easy
and hard things possible. You can generate plots, histograms, power spectra, bar charts, error
charts, scatter plots, etc., with just a few lines of code. For examples, see the sample plots and
thumbnail gallery.

For simple plotting the pyplot module provides a MATLAB-like interface, particularly when
combined with Ipython. For the power user, you have full control of line styles, font
properties, axes properties, etc, via an object oriented interface or via a set of functions
familiar to MATLAB users.

Scikit – learn

Scikit-learn provides a range of supervised and unsupervised learning algorithms via a


consistent interface in Python. It is licensed under a permissive simplified BSD license and is
distributed under many Linux distributions, encouraging academic and commercial use.
Python

Install Python Step-by-Step in Windows and Mac

Python a versatile programming language doesn’t come pre-installed on your computer


devices. Python was first released in the year 1991 and until today it is a very popular high-
level programming language. Its style philosophy emphasizes code readability with its
notable use of great whitespace.

The object-oriented approach and language construct provided by Python enables


programmers to write both clear and logical code for projects. This software does not come
pre-packaged with Windows.

How to Install Python on Windows and Mac

There have been several updates in the Python version over the years. The question is how to
install Python? It might be confusing for the beginner who is willing to start learning Python
but this tutorial will solve your query. The latest or the newest version of Python is version
3.7.4 or in other words, it is Python 3.
Note: The python version 3.7.4 cannot be used on Windows XP or earlier devices.

Before you start with the installation process of Python. First, you need to know about your
System Requirements. Based on your system type i.e. operating system and based processor,
you must download the python version. My system type is a Windows 64-bit operating
system. So the steps below are to install python version 3.7.4 on Windows 7 device or to
install Python 3. Download the Python Cheatsheet here.The steps on how to install Python on
Windows 10, 8 and 7 are divided into 4 parts to help understand better.

Download the Correct version into the system

Step 1: Go to the official site to download and install python using Google Chrome or any
other web browser. OR Click on the following link: https://www.python.org

Now, check for the latest and the correct version for your operating system.

Step 2: Click on the Download Tab.


Step 3: You can either select the Download Python for windows 3.7.4 button in Yellow Color
or you can scroll further down and click on download with respective to their version. Here,
we are downloading the most recent python version for windows 3.7.4

Step 4: Scroll down the page until you find the Files option.

Step 5: Here you see a different version of python along with the operating system.
 To download Windows 32-bit python, you can select any one from the three options:
Windows x86 embeddable zip file, Windows x86 executable installer or Windows x86
web-based installer.
 To download Windows 64-bit python, you can select any one from the three options:
Windows x86-64 embeddable zip file, Windows x86-64 executable installer or
Windows x86-64 web-based installer.

Here we will install Windows x86-64 web-based installer. Here your first part regarding
which version of python is to be downloaded is completed. Now we move ahead with the
second part in installing python i.e. Installation

Note: To know the changes or updates that are made in the version you can click on the
Release Note Option.

Installation of Python

Step 1: Go to Download and Open the downloaded python version to carry out the
installation process.
Step 2: Before you click on Install Now, Make sure to put a tick on Add Python 3.7 to PATH.

Step 3: Click on Install NOW After the installation is successful. Click on Close.
With these above three steps on python installation, you have successfully and correctly
installed Python. Now is the time to verify the installation.

Note: The installation process might take a couple of minutes.

Verify the Python Installation

Step 1: Click on Start

Step 2: In the Windows Run Command, type “cmd”.

Step 3: Open the Command prompt option.

Step 4: Let us test whether the python is correctly installed. Type python –V and press Enter.

Step 5: You will get the answer as 3.7.4


Note: If you have any of the earlier versions of Python already installed. You must first
uninstall the earlier version and then install the new one.

Check how the Python IDLE works

Step 1: Click on Start

Step 2: In the Windows Run command, type “python idle”.

Step 3: Click on IDLE (Python 3.7 64-bit) and launch the program

Step 4: To go ahead with working in IDLE you must first save the file. Click on File > Click
on Save

Step 5: Name the file and save as type should be Python files. Click on SAVE. Here I have
named the files as Hey World.

Step 6: Now for e.g. enter print (“Hey World”) and Press Enter.
You will see that the command given is launched. With this, we end our tutorial on how to
install Python. You have learned how to download python for windows into your respective
operating system.

Note: Unlike Java, Python does not need semicolons at the end of the statements otherwise it
won’t work.

CHAPTER 7

SYSTEM REQUIREMENTS

Software Requirements

The functional requirements or the overall description documents include the product
perspective and features, operating system and operating environment, graphics requirements,
design constraints and user documentation.

The appropriation of requirements and implementation constraints gives the general overview
of the project in regard to what the areas of strength and deficit are and how to tackle them.

 Python IDLE 3.7 version (or)


 Anaconda 3.7 (or)
 Jupiter (or)
 Google colab
Hardware Requirements

Minimum hardware requirements are very dependent on the particular software being
developed by a given Enthought Python / Canopy / VS Code user. Applications that need to
store large arrays/objects in memory will require more RAM, whereas applications that need
to perform numerous calculations or tasks more quickly will require a faster processor.

 Operating system : Windows, Linux


 Processor : minimum intel i3
 Ram : minimum 4 GB
 Hard disk : minimum 250GB

CHAPTER 8

FUNCTIONAL REQUIREMENTS

Output Design

Outputs from computer systems are required primarily to communicate the results of
processing to users. They are also used to provides a permanent copy of the results for later
consultation. The various types of outputs in general are:

 External Outputs, whose destination is outside the organization


 Internal Outputs whose destination is within organization and they are the
 User’s main interface with the computer.
 Operational outputs whose use is purely within the computer department.
 Interface outputs, which involve the user in communicating directly.

Output Definition
The outputs should be defined in terms of the following points:

 Type of the output


 Content of the output
 Format of the output
 Location of the output
 Frequency of the output
 Volume of the output
 Sequence of the output

It is not always desirable to print or display data as it is held on a computer. It should be


decided as which form of the output is the most suitable.

Input Design

Input design is a part of overall system design. The main objective during the input design is
as given below:

 To produce a cost-effective method of input.


 To achieve the highest possible level of accuracy.
 To ensure that the input is acceptable and understood by the user.

Input Stages

The main input stages can be listed as below:

 Data recording
 Data transcription
 Data conversion
 Data verification
 Data control
 Data transmission
 Data validation
 Data correction

Input Types

It is necessary to determine the various types of inputs. Inputs can be categorized as follows:

 External inputs, which are prime inputs for the system.


 Internal inputs, which are user communications with the system.
 Operational, which are computer department’s communications to the system?
 Interactive, which are inputs entered during a dialogue.

Input Media

At this stage choice has to be made about the input media. To conclude about the input media
consideration has to be given to;

 Type of input
 Flexibility of format
 Speed
 Accuracy
 Verification methods
 Rejection rates
 Ease of correction
 Storage and handling requirements
 Security
 Easy to use
 Portability

Keeping in view the above description of the input types and input media, it can be said that
most of the inputs are of the form of internal and interactive. As

Input data is to be the directly keyed in by the user, the keyboard can be considered to be the
most suitable input device.

Error Avoidance

At this stage care is to be taken to ensure that input data remains accurate form the stage at
which it is recorded up to the stage in which the data is accepted by the system. This can be
achieved only by means of careful control each time the data is handled.

Error Detection

Even though every effort is make to avoid the occurrence of errors, still a small proportion of
errors is always likely to occur, these types of errors can be discovered by using validations to
check the input data.

Data Validation
Procedures are designed to detect errors in data at a lower level of detail. Data validations
have been included in the system in almost every area where there is a possibility for the user
to commit errors. The system will not accept invalid data. Whenever an invalid data is keyed
in, the system immediately prompts the user and the user has to again key in the data and the
system will accept the data only if the data is correct. Validations have been included where
necessary.

The system is designed to be a user friendly one. In other words the system has been
designed to communicate effectively with the user. The system has been designed with
popup menus.

User Interface Design

It is essential to consult the system users and discuss their needs while designing the user
interface:

User Interface Systems Can Be Broadly Clasified As:

 User initiated interface the user is in charge, controlling the progress of the
user/computer dialogue. In the computer-initiated interface, the computer selects the
next stage in the interaction.
 Computer initiated interfaces

In the computer-initiated interfaces the computer guides the progress of the user/computer
dialogue. Information is displayed and the user response of the computer takes action or
displays further information.

User Initiated Interfaces

User initiated interfaces fall into two approximate classes:

 Command driven interfaces: In this type of interface the user inputs commands or
queries which are interpreted by the computer.
 Forms oriented interface: The user calls up an image of the form to his/her screen and
fills in the form. The forms-oriented interface is chosen because it is the best choice.

Computer-Initiated Interfaces

The following computer – initiated interfaces were used:


 The menu system for the user is presented with a list of alternatives and the user
chooses one; of alternatives.
 Questions – answer type dialog system where the computer asks question and takes
action based on the basis of the users reply.

Right from the start the system is going to be menu driven, the opening menu displays the
available options. Choosing one option gives another popup menu with more options. In this
way every option leads the users to data entry form where the user can key in the data.

Error Message Design

The design of error messages is an important part of the user interface design. As user is
bound to commit some errors or other while designing a system the system should be
designed to be helpful by providing the user with information regarding the error he/she has
committed.

This application must be able to produce output at different modules for different inputs.

Performance Requirements

Performance is measured in terms of the output provided by the application. Requirement


specification plays an important part in the analysis of a system. Only when the requirement
specifications are properly given, it is possible to design a system, which will fit into required
environment. It rests largely in the part of the users of the existing system to give the
requirement specifications because they are the people who finally use the system. This is
because the requirements have to be known during the initial stages so that the system can be
designed according to those requirements. It is very difficult to change the system once it has
been designed and on the other hand designing a system, which does not cater to the
requirements of the user, is of no use.

The requirement specification for any system can be broadly stated as given below:

 The system should be able to interface with the existing system


 The system should be accurate
 The system should be better than the existing system
 The existing system is completely dependent on the user to perform all the duties.
CHAPTER 9

SOURCE CODE

#An Innovative System for Monitoring Emotional Health to Identify Individuals at Risk of
Psychological Disturbances

import numpy as np

import pandas as pd

import warnings

warnings.filterwarnings('ignore')

import json

with open('intents.json', 'r') as f:


data = json.load(f)

df = pd.DataFrame(data['intents'])

df

dic = {"tag":[], "patterns":[], "responses":[]}

for i in range(len(df)):

ptrns = df[df.index == i]['patterns'].values[0]

rspns = df[df.index == i]['responses'].values[0]

tag = df[df.index == i]['tag'].values[0]

for j in range(len(ptrns)):

dic['tag'].append(tag)

dic['patterns'].append(ptrns[j])

dic['responses'].append(rspns)

df = pd.DataFrame.from_dict(dic)

df

df['tag'].unique()

from tensorflow.keras.preprocessing.text import Tokenizer

tokenizer = Tokenizer(lower=True, split=' ')

tokenizer.fit_on_texts(df['patterns'])

tokenizer.get_config()

vacab_size = len(tokenizer.word_index)

print('number of unique words = ', vacab_size)


from tensorflow.keras.preprocessing.sequence import pad_sequences

from sklearn.preprocessing import LabelEncoder

ptrn2seq = tokenizer.texts_to_sequences(df['patterns'])

X = pad_sequences(ptrn2seq, padding='post')

print('X shape = ', X.shape)

lbl_enc = LabelEncoder()

y = lbl_enc.fit_transform(df['tag'])

print('y shape = ', y.shape)

print('num of classes = ', len(np.unique(y)))

import tensorflow

from tensorflow import keras

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Input, Embedding, LSTM, LayerNormalization, Dense,


Dropout

from tensorflow.keras.utils import plot_model

model = Sequential()

model.add(Input(shape=(X.shape[1])))

model.add(Embedding(input_dim=vacab_size+1, output_dim=100, mask_zero=True))

model.add(LSTM(32, return_sequences=True))

model.add(LayerNormalization())

model.add(LSTM(32, return_sequences=True))

model.add(LayerNormalization())
model.add(LSTM(32))

model.add(LayerNormalization())

model.add(Dense(128, activation="relu"))

model.add(LayerNormalization())

model.add(Dropout(0.2))

model.add(Dense(128, activation="relu"))

model.add(LayerNormalization())

model.add(Dropout(0.2))

model.add(Dense(len(np.unique(y)), activation="softmax"))

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

model.summary()

plot_model(model, show_shapes=True)

model_history = model.fit(x=X,

y=y,

batch_size=10,

callbacks=[tensorflow.keras.callbacks.EarlyStopping(monitor='accuracy',
patience=3)],

epochs=50)

import re

import random

def generate_answer(pattern):

text = []
txt = re.sub('[^a-zA-Z\']', ' ', pattern)

txt = txt.lower()

txt = txt.split()

txt = " ".join(txt)

text.append(txt)

x_test = tokenizer.texts_to_sequences(text)

x_test = np.array(x_test).squeeze()

x_test = pad_sequences([x_test], padding='post', maxlen=X.shape[1])

y_pred = model.predict(x_test)

y_pred = y_pred.argmax()

tag = lbl_enc.inverse_transform([y_pred])[0]

responses = df[df['tag'] == tag]['responses'].values[0]

print("you: {}".format(pattern))

print("model: {}".format(random.choice(responses)))

generate_answer('Hi! How are you?')

generate_answer('Maybe I just didn\'t want to be born :)')

generate_answer('help me:')

generate_answer(':')

def chatbot():

print("Chatbot: Hi! I'm your friendly chatbot. How can I assist you today?")

while True:
user_input = input("You: ")

if user_input.lower() in ['quit', 'exit', 'q', 'bye']:

print("Chatbot: Goodbye!")

break

generate_answer(user_input)

if __name__ == "__main__":

chatbot()

CHAPTER 10

RESULTS AND DISCUSSION

10.1 Implementation description

This project implements a chatbot system using deep learning techniques to understand and
generate responses to user input. In summary, this loads a dataset of intents, trains a chatbot
model using a sequential neural network with LSTM layers, and allows users to interact with
the chatbot in a simple text-based conversation. The chatbot responds to user input based on
patterns learned during training. Let's break down the implementation step by step:

 Libraries and Imports:

The code starts by importing necessary libraries, including numpy, pandas,


warnings, and json.

It also sets up a filter to suppress warnings.

The json library is used to read data from a file named 'intents.json.'
 Loading Data:

It opens and reads the 'intents.json' file, which presumably contains a dataset for training the
chatbot.

 Data Preparation:

The code extracts the 'intents' data from the JSON file and converts it into a pandas
DataFrame named 'df.'

It creates a dictionary 'dic' to store 'tag,' 'patterns,' and 'responses' data separately.

 Data Transformation:

The code loops through the DataFrame 'df' and extracts 'patterns,' 'responses,' and 'tag' for
each intent.

It then appends this data to the 'dic' dictionary.

 DataFrame Reconstruction:

A new DataFrame 'df' is created from the 'dic' dictionary, combining 'tag,' 'patterns,' and
'responses.'

 Tokenization:

The code imports the Tokenizer class from the Keras library and tokenizes the
'patterns' data in 'df.'

It computes the vocabulary size and prints it.

 Sequence Padding:

The code uses the pad_sequences function to pad the tokenized sequences to
the same length, making them suitable for training.

 Label Encoding:

The labels ('tag') are encoded using sklearn's LabelEncoder, and the encoded
values are stored in 'y.'

 Model Definition:

A sequential Keras model is defined.


The model includes layers for embedding, LSTM (Long Short-Term Memory)
networks, layer normalization, dense layers, and dropout layers.

It ends with a softmax activation layer with the number of classes equal to the
unique tags in the dataset.

The model is compiled with the Adam optimizer and sparse categorical cross-
entropy loss.

 Model Summary:

The model summary is printed, showing the architecture and the number of
parameters.

 Model Training:

The model is trained on the tokenized and padded input data 'X' and the
encoded labels 'y.'

The training includes early stopping based on accuracy and runs for 50
epochs.

 Response Generation Function:

A function 'generate_answer' is defined to generate responses to user input.

It preprocesses the input text, tokenizes it, and uses the trained model to
predict the tag.

It retrieves random responses from the dataset based on the predicted tag and
prints them.

 User Interactions:

A simple chatbot interaction loop is defined in the 'chatbot' function.

The chatbot greets the user and waits for input.

Users can type 'quit,' 'exit,' 'q,' or 'bye' to exit the chatbot loop.

Otherwise, the 'generate_answer' function is called to provide responses based


on user input.

 Main Execution:
The 'chatbot' function is executed if the script is run directly.

10.2 Dataset description

 Tag: The "tag" column represents a categorical label or tag associated with a specific
intent or category of user input. In the context of a chatbot or NLP model, these tags
typically correspond to different topics, commands, or purposes that the chatbot is
designed to recognize and respond to. For example, tags include "greeting,"
"farewell," "information request," "emotions," etc.
 Patterns: The "patterns" column contains textual patterns or user input examples that
are associated with each tag. These patterns serve as training data for the chatbot or
NLP model to learn how to recognize the user's intent or request. Patterns can be in
the form of sentences, phrases, or keywords. Each pattern is used to teach the model
what kind of user input corresponds to a particular tag.
 Responses: The "responses" column includes predefined responses or messages that
the chatbot should provide when it recognizes a specific tag or user intent. These
responses are the chatbot's way of interacting with the user and providing relevant
information or assistance based on the detected intent. Responses can vary depending
on the tag and may include greetings, answers to questions, instructions, or any other
appropriate text.

10.3 Results description

Figure 1(a) displays a portion of the original dataset used for training the chatbot. It shows
examples of intents or patterns along with their corresponding tags and responses. Figure 1(b)
shows how the original dataset has been structured after converting it into a panda
DataFrame. It focuses on the 'patterns' and 'tags' columns. The 'patterns' column contains the
input text or user queries. The 'tags' column contains labels or categories associated with the
input patterns.
(a)

(b)

Figure 1: Display of the sample dataset. (a) original dataset. (b) dataset after converting into a
data frame with patterns and tags.

Figure 2 displays a summary of the unique values found in the 'tag' column of the DataFrame.
It shows the different categories or tags that the chatbot has been trained to recognize. It
provides an overview of the classes or intents that the chatbot can identify.
Figure 2: Presents the unique values of column tag.

Figure 3 is a representation of the architecture of the LSTM (Long Short-Term Memory)


model used in the chatbot. It shows a detailed summary of the model's layers, including input
dimensions, layer types (e.g., embedding, LSTM), the number of units or neurons in each
layer, activation functions, and the total number of trainable parameters.

Figure 3: Model summary of LSTM.


Figure 4: Training performance of LSTM model with accuracy, and loss for 232 epochs.

Figure 5: Sample predicted conversation between patient and proposed model for monitoring
emotional health.

Figure 4 displays the training performance metrics of the LSTM model over a series of
epochs. This shows how the accuracy of the model changes with each training epoch. The
proposed model obtained an accuracy of 99.57%. It also shows the training loss, which
measures how well the model’s predictions match the actual target values during training.
Lower values indicate better performance. The proposed model achieves 0.0347 of loss.
Figure 5 illustrates a sample conversation between a patient or user and the chatbot model
designed to monitor emotional health. It showcases how the chatbot responds to user input,
providing an example of a simulated interaction. The conversation includes user queries and
the chatbot's generated responses, demonstrating the chatbot's functionality.

CHAPTER 11
CONCLUSIONS AND FUTURE SCOPE
In conclusion, the implementation of an LSTM-based chatbot designed to monitor emotional
health and identify individuals at risk of psychological disturbances represents a significant
step forward in the utilization of technology for mental health support. This chatbot
showcases its ability to effectively engage in conversations with users and provide responses
based on patterns learned from the 'intents.json' dataset. This highlights the potential of
natural language processing (NLP) techniques to comprehend and address user emotions and
concerns, offering a unique avenue for mental health assistance. One of the standout features
of this chatbot is its capability to detect individuals at risk of psychological disturbances. By
analyzing user input, it can promptly identify potential issues, enabling timely intervention
and support. This proactive approach holds the promise of early intervention, which is crucial
for preventing the escalation of mental health challenges and ensuring individuals receive the
necessary assistance when they need it most.

Moreover, the accessibility offered by chatbots is a key advantage. Users can comfortably
express their emotions and seek help through this platform, which can alleviate some of the
barriers and stigma associated with discussing mental health concerns. This accessibility
aspect is especially valuable in reaching individuals who may be hesitant to seek help through
traditional channels. Additionally, the chatbot system has the potential to amass a substantial
dataset of user interactions. Analyzing this data can yield valuable insights into user behavior,
common mental health issues, and the effectiveness of various interventions. Such data-
driven insights can inform the ongoing development and refinement of mental health support
systems.

Future Scope

Looking ahead, there are several avenues for enhancing and expanding the capabilities of this
chatbot system. Advanced NLP techniques, including sentiment analysis and emotion
recognition, can be integrated to enable the chatbot to better understand and respond to the
subtle nuances of human emotions. Multimodal support, encompassing audio and visual
inputs, can provide a more comprehensive understanding of a user's emotional state.
Personalization is another critical aspect of future development. By tailoring responses and
interventions based on a user's historical data and preferences, the chatbot can offer more
effective and empathetic support. Integration with mental health professionals or crisis
hotlines can be explored to ensure that cases requiring immediate human intervention are
promptly addressed.
REFERENCES
[1] G. Miner, L. Miner, M. Goldstein et al., Practical Predictive Analytics and Decisioning
Systems for Medicine: Informatics Accuracy and Cost-Effectiveness for Healthcare
Administration and Delivery Including Medical Research, Academic Press, Inc.,
Cambridge, MA, USA, 1st edition, 2016.
[2] M. Hamilton, “Development of a rating scale for primary depressive illness,” British
Journal of Social and Clinical Psychology, vol. 6, no. 4, pp. 278–296, 1967.
[3] American Psychiatric Association, Diagnostic and Statistical Manual of Mental
Disorders, American Psychiatric Association, Reston, VA, USA, 2013.
[4] M. I. Jordan and T. M. Mitchell, “Machine learning: trends, perspectives, and
prospects,” Science, vol. 349, no. 6245, pp. 255–260, 2015.
[5] F. Dabek and J. J. Caban, “A neural network-based model for predicting psychological
conditions,” in Brain Informatics and Health, pp. 252–261, Springer International
Publishing, Berlin, Germany, 2015.
[6] G. Cho, J. Yim, Y. Choi, J. Ko, and S.-H. Lee, “Review of machine learning algorithms
for diagnosing mental illness,” Psychiatry Investigation, vol. 16, no. 4, pp. 262–269,
2019.
[7] E. G. Pintelas, T. Kotsilieris, I. E. Livieris, and P. Pintelas, “A review of machine
learning prediction methods for anxiety disorders,” in Proceedings of the 8th
International Conference on Software Development and Technologies for Enhancing
Accessibility and Fighting Info-Exclusion—DSAI 2018, The-ssaloniki, Greece, 2018.
[8] R. B. Rutledge, A. M. Chekroud, and Q. J. Huys, “Machine learning and big data in
psychiatry: toward clinical applications,” Current Opinion in Neurobiology, vol. 55, pp.
152–159, 2019.
[9] 130 Executive Board, “Global burden of mental disorders and the need for a
comprehensive, coordinated response from health and social workers at the country
level,” 2012, https:// apps.who.int/iris/handle/10665/23741.
[10] M. Hadzic, M. Chen, and T. S. Dillon, “Towards the mental health ontology,” in
Proceedings of the 2008 IEEE International Conference on Bioinformatics and
Biomedicine, Philadelphia, PA, USA, 2008.
[11] J. Diederich, A. Al-Ajmi, and P. Yellowlees, “Ex-ray: data mining and mental health,”
Applied Soft Computing, vol. 7, no. 3, pp. 923–928, 2007.
[12] D. Greenstein, J. D. Malley, B. Weisinger, L. Clasen, and N. Gogtay, “Using
multivariate machine learning methods and structural MRI to classify childhood onset
schizophrenia and healthy controls,” Frontiers in Psychiatry, vol. 3, 2012.
[13] Y. T. Jo, S. W. Joo, S. H. Shon, H. Kim, Y. Kim, and J. Lee, “Diagnosing
schizophrenia with network analysis and a machine learning method,” International
Journal of Methods in Psychiatric Research, vol. 29, no. 1, 2020.
[14] H. Yang, J. Liu, J. Sui, G. Pearlson, and V. D. Calhoun, “A hybrid machine learning
method for fusing fMRI and genetic data: combining both improves classification of
schizophrenia,” Frontiers in Human Neuroscience, vol. 4, 2010.
[15] S. Srinivasagopalan, J. Barry, V. Gurupur, and S. Thankachan, “A deep learning
approach for diagnosing schizophrenic patients,” Journal of Experimental & Aeoretical
Artificial Intelligence, vol. 31, no. 6, pp. 803–816, 2019.
[16] R. N. Plaschke, E. C. Cieslik, V. I. M¨uller et al., “On the ¨ integrity of functional
brain networks in schizophrenia, Parkinson’s disease, and advanced age: evidence from
connectivity-based single-subject classification,” Human Brain Mapping, vol. 38, no.
12, pp. 5845–5858, 2017.
[17] W. H. L. Pinaya, A. Gadelha, O. M. Doyle et al., “Using deep belief network
modelling to characterize differences in brain morphometry in schizophrenia,”
Scientific Reports, vol. 6, no. 1, 2016.
[18] W. H. L. Pinaya, A. Mechelli, and J. R. Sato, “Using deep autoencoders to identify
abnormal brain structural patterns in neuropsychiatric disorders: a large-scale multi-
sample study,” Human Brain Mapping, vol. 40, no. 3, pp. 944–954, 2018.
[19] A. M. Chekroud, R. J. Zotti, Z. Shehzad et al., “Cross-trial prediction of treatment
outcome in depression: a machine learning approach,” Ae Lancet Psychiatry, vol. 3, no.
3, pp. 243–250, 2016.
[20] A. Ahmed, R. Sultana, M. T. R. Ullas, M. Begom, M. M. I. Rahi, and M. A. Alam, “A
machine learning approach to detect depression and anxiety using supervised learning,”
in Proceedings of the 2020 IEEE Asia-Pacific Conference on Computer Science and
Data Engineering (CSDE), Gold Coast, Australia, 2019.

You might also like