0% found this document useful (0 votes)
491 views98 pages

Cyberbullying A17 Major Project

This document discusses detecting cyberbullying on Twitter using machine learning. It proposes building a machine learning model to detect and prevent bullying tweets. Two classifiers, Support Vector Machine (SVM) and Naive Bayes, are trained on a dataset of social media content. SVM achieved 52.70% accuracy in detecting true positives, outperforming Naive Bayes which achieved 71.21% accuracy on the same dataset. The Twitter API is also used to fetch tweets which are then passed to the model to detect if they contain bullying or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
491 views98 pages

Cyberbullying A17 Major Project

This document discusses detecting cyberbullying on Twitter using machine learning. It proposes building a machine learning model to detect and prevent bullying tweets. Two classifiers, Support Vector Machine (SVM) and Naive Bayes, are trained on a dataset of social media content. SVM achieved 52.70% accuracy in detecting true positives, outperforming Naive Bayes which achieved 71.21% accuracy on the same dataset. The Twitter API is also used to fetch tweets which are then passed to the model to detect if they contain bullying or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 98

DETECTING A TWITTER CYBERBULLYING

USING MACHINE LEARNING

A Major Project thesis submitted to the JAWAHARLAL NEHRU


TECHNOLOGICAL UNIVERSITY in partial fulfilment of the
requirement for the award of the degree of

BACHELOR OF TECHNOLOGY
In
Computer Science & Engineering
Submitted by
G. AKHILA (19D31A0536)
G. AKANKSHA (19D31A0534)
G. SHIVA (19D31A0539)

Under the Guidance of


Mr CH. Gopi Krishna
Asst. Professor, Dept. of CSE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


INDUR INSTITUTE OF ENGINEERING AND TECHNOLOGY
(Affiliated to J.N.T.U.H, Hyderabad)
Ponnala (Vil), Siddipet (Dist.), Telangana State – 502 277.
June, 2023

i
Date: / /2023

CERTIFICATE

This is to certify that the thesis ‘Detecting A Twitter Cyberbullying


Using Machine Learning’ being submitted by

G. AKHILA (19D31A0536)
G. AKANKSHA (19D31A0534)
G. SHIVA (19D31A0539)

In partial fulfilment for the award of “BACHELOR OF TECHNOLOGY” in


the Department of “COMPUTER SCIENCE & ENGINEERING”. (B. Tech) to the
“JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY” is a record of
bonafide Major Project Work carried out by them under my guidance and supervision.
The results embodied in this thesis have not been submitted to any other
University or Institute for the award of any degree or diploma.

Mr CH. Gopi Krishna Mr. RITESH THAKUR


PROJECT GUIDE HOD
Asst. Professor, Dept. of CSE Assoc. Prof &
Head Dept. of CSE

EXTERNAL EXAMINER

ii
ACKNOWLEDGEMENT

We are thankful to Mr CH. Gopi Krishna, Project Guide, Asst. Prof., Dept.
of CSE who guided us a lot by his favourable suggestions to complete our project. he
is the research-oriented personality with higher end technical exposure.

We are thankful to Mr. Ritesh Thakur, Head, Dept. of CSE, Indur Institute
of Engineering & Technology, for extending his help in the department academic
activities in the course duration. He the personality of dynamic, enthusiastic in the
academic activities.

We extend our thanks to Dr. V.P. Raju Principal, Indur Institute of


Engineering & Technology, Siddipet for extending his help throughout the
duration of this project.

We sincerely acknowledge to all the lecturers of the Dept. of CSE for their
motivation during our B. Tech course.

We would like to say thanks to all of our friends for their timely help and
encouragement.

G. AKHILA (19D31A0536)
G. AKANKSHA (19D31A0534)
G. SHIVA (19D31A0539)

iii
DECLARATION

We hereby declare that the project work entitled ‘DETECTING A TWITTER


CYBERBULYING USING MACHINE LEARNING. Submitted to the
university, is a record of an original work done by us under the guidance of
MRS.CHAITHANYA, Associate Prof, Department Of Computer Science &
Engineering INDUR INSTITUTE OF ENGINEERING & TECHNOLOGY, and this
project work has not formed the basis for the award of any degree or diploma
associateship fellowship and other similar titles if any.

G. AKHILA (19D31A0536)

G. AKANKSHA (19D31A0534)

G. SHIVA (19D31A0539)

iv
ABSTRACT
Social media is a platform where many young people are getting bullied. As social
networking sites are increasing, cyberbullying is increasing day by day. To identify
word similarities in the tweets made by bullies and make use of machine learning
and can develop an ML model automatically detect social media bullying
actions. However, many social media bullying detection techniques have been
implemented, but many of them were textual based. The goal of this paper is to
show the implementation of software that will detect bullied posts, tweets etc.
A machine learning model is proposed to detect and prevent bullying on Twitter.
Two classifiers i.e., SVM and Navie Bayes are used for training and the social
media bullying content. Both Navie Bayes and SVM (Support Vector Machine)
were able to detect the true positives with 71.21% and 52.70% accuracy
respectively. But SVM outperforms Navie Bayes of similar work on the same
dataset. Also, Twitter API is used to fetch tweets and tweets are passed to the
model to detect whether the tweets are bullying or not.

v
CONTENT
1.INTRODUCTION 2

1.1 Literacy Survey 3


1.1.1 Social Media Cyberbullying Detection using Machine Learning 3
1.1.2 Using Machine Learning to Detect Cyberbullying
1.1.3 Content-based Cybercrime Detection 4
1.1.4 Social media bullying detection using machine learning on Bangla text 4

2.SYSTEM ANALYSIS

2.1 Existing System 8


2.2 proposed system 8
2.3 System Environment 10
2.3.1 Python 10
2.3.2 Django 30

2.4 System Study 44


2.5 Requirement Analysis 46
2.6 System specification 47
2.6.1 Hardware requirements 47
2.6.2 Software requirements 48

3.SYSTEM DESIGN 50

3.1 System Architecture 50


3.2 Data flow diagram 51
3.3 UML diagram 52
3.3.1 Usecase diagram 53
3.3.2 Class diagram 54

vi
3.3.3 Sequence diagram 55
3.3.4 Activity diagram 56

4.IMPLEMENTATION 59

Modules 59

5.RESULTS 70
6.SYSTEM TESTING 79
6.1 Types Of Tests 79
6.1.1 Unit testing 79
6.1.2 Integration testing 79
6.1.3 Functional testing 80
6.1.4 System testing 80
6.1.5 Whitebox testing 81
6.1.6 Blackbox testing 81
6.2 Sample Test Cases 84

7.CONCLUSION & FURTHER ENHANCEMENTS 86

7.1 Conclusion 86
7.2 Further enhancements 86

8.BIBLIOGRAPHY 88

vii
LIST OF FIGURES

2.3.1 Django architecture 30


2.3.1 MVT architecture 31
3.1 System architecture 50
3.2 Data flow diagram 51
3.3.1 Use case diagram 53
3.3.2 Class diagram 54
3.3.3 Sequence diagram 56
3.3.4 Activity diagram 57
5.1 Home page 72
5.2 User Registration form 73
5.3 Admin login 73
5.4 User Details 74
5.5 User login 74
5.6 User Home 75
5.7 View data set 75
5.8 ML results 76
5.9 Predict result true 77
5.10 Predict result false 77

LIST OF TABLES

6.2 Sample test cases 83

viii
CHAPTER 1

1
INTRODUCTION
Nowadays technology has become a very important part of our lives and most people
can't livewithout it. The Internet provides a platform to share their ideas. Many people are
spending a large amount of time on social media. Communicating with people is no
exception, as technology has changed the way people interact with a broader manner and
has given a new dimension to communication. Many people are illegally using these
communities. Many youngsters are getting bullied these days. Bullies use various services
like Twitter, Facebook, Email to bully people. Studies show that about 37% of children in
India are involved in cyberbullying and nearly 14% of bullying occurs regularly.
Cyberbullying affects the victim both ways emotionally and psychologically. Social media
also allows bullies to harness the anonymity which satisfies their unkind deeds. Things also
get more serious when bullying occurs more repeatedly over time. So, preventing it from
happening will help the victim.

2
1.1 LITERATURE SURVEY
1.1.1 Social Media Cyberbullying Detection using Machine Learning
AUTHORS: John Hani Mounir, Mohamed Nashaat, Mostafa Ahmed,
Zeyad Emad, Eslam Amer, Ammar Mohammed
With the exponential increase of social media users, cyberbullying has been emerged
as a form of bullying through electronic messages. Social networks provides a rich
environment for bullies to uses these networks as vulnerable to attacks against victims.
Given the consequences of cyberbullying on victims, it is necessary to find suitable
actions to detect and prevent it. Machine learning can be helpful to detect language
patterns of the bullies and hence can generate a model to automatically detect
cyberbullying actions. This paper proposes a supervised machine learning approach for
detecting and preventing cyberbullying. Several classifiers are used to train and
recognize bullying actions. The evaluation of the proposed approach on cyberbullying
dataset shows that Neural Network performs better and achieves accuracy of 92.8%
and SVM achieves 90.3. Also, NN outperforms other classifiers of similar work on the
same dataset.

1.1.2 Using Machine Learning to Detect Cyberbullying


AUTHORS: Kelly Reynolds, April Kontostathis, Lynne
Edwards
Cyber bullying is the use of technology as a medium to bully someone. Although it has
been an issue for many years, the recognition of its impact on young people has recently
increased. Social networking sites provide a fertile medium for bullies, and teens and
young adults who use these sites are vulnerable to attacks. Through machine learning, we
can detect language patterns used by bullies and their victims, and develop rules to
automatically detect cyber bullying content. The data we used for our project was collected
from the website Formspring.me, a question-and-answerformatted website that contains a
high percentage of bullying content. The data was labeled usinga web service, Amazon's
3
Mechanical Turk. We used the labeled data, in conjunction with machine learning
techniques provided by the Weka tool kit, to train a computer to recognize bullying
content. Both a C4.5 decision tree learner and an instance-based learner were able to
identify the true positives with 78.5% accuracy.

1.1.3 Content-based Cybercrime Detection


AUTHORS: Amanpreet Singh, Manider
In recent years, content-based cybercrime detection has become a topic of attraction
among researchers. Cybercrime has emerged as a money-driven industry with malicious
intent towards online social networks. Cyber-criminals aim to manipulate vulnerable
areas in cyberspace by playing on human understanding and making a profit. They
threaten minors, especially adolescents, who are not adequately overseen while online.
To address this issue, there is an urgent need for a robust content-based cybercrime
detection framework. The aim of this research work isto explore possible combinations
of various preprocessing, feature selection and classification methodologies using the
cuckoo search metaheuristic approach. This approach seeks to improve the performance
of content-based cybercrime detection system. For the purpose of this research, four
publicly available datasets for cyberbullying detection have been utilized for evaluating
the effectiveness of the proposed algorithm. The algorithm was then further compared
with three recent cyberbullying detection models based on various evaluation
parameters. These parametersincluded precision, recall and f-measure. The experimental
results demonstrate the effectiveness of the proposed approach. This approach
outperformed other recent techniques on all the datasets, giving high predictive recall
value via tenfold cross-validation.

1.1.4 Social media bullying detection using machine learning on Bangla text

AUTHORS: Abdhullah-Al-Mamun, Shahin Akhter


with the popularity of Unicode system and growing use of Internet, the use of Bangla
over social media is increasing. However, very few works have been done on Bangla
4
text for social media activity monitoring due to a lack of a large number of annotated
corpora, named dictionaries and morphological analyzer, which demands in-depth
analysis on Bangladesh's perspective. Moreover,solving the issue by applying available
techniques is very content specific, which means that falsedetection can occur if contents
changed from formal English to verbal abuse or sarcasm. Also, performance may
varydue to linguistic differences between English and non-English contents andthe socio-
emotional behaviour of the study population. To combat such issues, this paper proposes
the use of machine learning algorithms and the inclusion of user information for cyber
bullying detection on Bangla text. For this purpose, a set of Bangla text has been
collected from available social media platforms and labelled as either bullied or not
bullied for training different machine learning based classification models. Cross-
validation results of the models indicate that a supportvector machine based algorithm
achieves superior performance on Bangla text with a detection accuracy of 97%. Besides,
the impact of user specific information such as location, age and gender can further
improve the classification accuracy of Bangla cyber bullying detection system.

1.1.5 Cyberbullying detectionusing time series modeling

AUTHORS: NektariaPotha and ManolisMaragoudakis.

Cyber bullying is a new phenomenon resulting from the advance of new communication
technologies including the Internet, cell phones and Personal Digital Assistants. It is a
challenging bullying problem occurring in a new territory. Online bullying can be
particularly damaging and upsetting because it's usually anonymous or hard to trace. In
this paper, the proposed method is utilizing a dataset of real world conversations (i.e.
Pairs of questions and answers between cyber predator and the victim), in which each
predator question is manually annotated in terms of severityusing a numeric label. We
approach the issue as a sequential data modelling approach, in which the predator's
questions are formulated using a Singular Value Decomposition representation. The
motivation of this procedure is to study the accuracy of predicting the level of cyber

5
bullying attack using classification methods and also to examine potential patterns
between the lingustic style of each predator. More specifically, unlike previous
approaches that consider a fixed window of a cyber-predator's questions within a
dialogue, we exploit the whole question set and model it as a signal, whose magnitude
depends on the degree of bullying content. Using feature weighting and dimensionality
reduction techniques, each signal is straightforwardly parsed by a neural network that
forecasts the level of insult within a question given a window between two and three
previous questions. Throughout the time series modeling experiments, an interesting
discovery was made. By applying SVD on the time series data and taking into account
the second dimension (since thefirst is usually modeling trivial dependencies between
instances and attributes) we observed that its plot was very similar to the plot of the class
attribute. By applying a Dynamic Time Warping algorithm, the similarity of the
aforementioned signals was proved to exist, providing an immediate indicator for the
severity of cyber bullying within a give…..

6
CHAPTER 2

7
SYSTEM ANALYSIS
2.1 EXISTING SYSTEM:
Cyber bullying is the use of technology as a medium to bully someone. Although it
has been an issue for many years, the recognition of its impact on young people has
recently increased. Socialnetworking sites provide a fertile medium for bullies, and teens
and young adults who use these sites are vulnerable to attacks. Through machine learning,
we can detect language patterns used bybullies and their victims, and develop rules to
automatically detect cyber bullying content.

2.1.1 DISADVANTAGES OF EXISTING SYSTEM:

Hence the results of producing with such kind of results are not satisfying.

Datasets are not sufficient to predict better results.

Algorithms: KNN.

2.2 PROPOSED SYSTEM:

In this paper, a solution is proposed to detect twitter cyberbullying. The main


difference with previous research is that we not only developed a machine learning model
to detect cyberbullyingcontent but also implemented it on particular locations real-time
tweets using Twitter API. The entire approach to detect and prevent Twitter cyberbullying
isdivided into 2 major stages: developing the model and experimental setup. The Natural
Language Toolkit (NLTK) is used for the preprocessing of data. NLTK is used for
tokenization of text patterns, to remove stop words from the text, etc. The entire model is
divided into 3 major steps: Preprocessing, the algorithm, and feature extraction.

The first step in the solution is to collect the tweets from Twitter usingTwitter API. In
the next twosteps are data preprocessing and feature extraction is performed over the
tweets. And after performing preprocessing and feature extraction tweets are passed to
the SVM model for classification to predict whether the tweet is Bullying or Non-
8
Bullying. The second step In this step, the proposed model has transformed the data in a
suitable form which is passed to the machinelearning algorithms. The TFDIF vectorizer
[1] is used to extract the features of the given data. Features of the data are extracted and
put them in a list of features. Also, the polarity (i.e. the text is Bullying or Non-Bullying)
of each text is extracted and stored in the list of features. The third step To detect social
media bullying automatically, supervised Binary classification machine learning
algorithms like SVM with linear kernel and Naive Bayes is used. The reason behind this
is both SVM and Naive Bayes calculate the probabilities for each class (i.e. probabilities
of Bullying and Non-Bullying tweets). Both SVM and NB algorithms are used for the
classificationof the two-cluster.

2.2.1 ADVANTAGES OF PROPOSED SYSTEM:

Naive Bayes models are used recommendation systems, sentiment analysis, and
spam filtering. Naive Bayes algorithms are very easy to implement.
After performing preprocessing and feature extraction on the dataset, for training
and testing, and divided the dataset into ratios 0.45 and 0.55 respectively. Both
SVM and NaiveBayes are evaluated to calculate the accuracy, recall, f-score, and
precision. Interestingly SVM outperformed Naive Bayes in every aspect.
the accuracies of both the Naive Bayes and SVM. The Support Vector Machine
achieved the highest accuracy i.e. 71.25%, while Naive Bayes achieved 52.70%
accuracy.

Algorithms: machine learning; classifiers; Naive Bayes; support vector machine


(SVM); Twitter API.

9
2.3 SYSTEM ENVIRONMENT:

2.3.1 Python:
Python is a general-purpose interpreted, interactive, object-oriented, and high- level
programming language. An interpreted language, Python has a design philosoph that
code readability (notably using whitespace indentation to delimit code blocks rather
than curly brackets or keywords), and a syntax that allows programmers to express
concepts in fewer lines of code than might be usedin languages such as C++or Java. It
provides constructs that enable clear programming on both small and large scales. Python
interpreters are available for many operating systems. CPython, the reference
implementation of Python, is open source software and has a community-based
development model, as do nearly all of its variant implementations. CPython is
managed by the non- profit Python Software Foundation. Python features a dynamic
type system and automatic memory management. It supports multiple programming
paradigms, including object-oriented, imperative, functional and procedural, and has a
large and comprehensive standard library.

Interactive Mode Programming

Invoking the interpreter without passing a script file as a parameter brings up the
following prompt –

$ python

Python 2.4.3 (#1, Nov 11 2010, 13:34:43)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

10
>>>

Type the following text at the Python prompt and press the Enter −

>>> print "Hello, Python!"

If you are running new version of Python, then you would need to use print statement
with parenthesis as in print ("Hello, Python!");. However in Python version 2.4.3, this
produces the following result −

Hello, Python!

Script Mode Programming

Invoking the interpreter with a script parameter begins execution of the script and
continues until the script is finished. When the script is finished, the interpreter is no
longer active.

Let us write a simple Python program in a script. Python files have extension .py. Type
the following source code in a test.py file –
Live Demo

print "Hello, Python!"

We assume that you have Python interpreter set in PATH variable. Now, try to runthis
program as follows −

$ python test.py

This produces the following


result −Hello, Python!
Let us try another way to execute a Python script. Here is the modified test.py file
11

Live
Demo
#!/usr/bin/p
ython
print "Hello, Python!"

We assume that you have Python interpreter available in /usr/bin directory. Now,try to
run this program as follows −

$ chmod +x test.py # This is to make file executable

$./test.py

This produces the following


result −Hello, Python!

Python Identifiers

A Python identifier is a name used to identify a variable, function, class, module orother
object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by
zero or more letters, underscores and digits (0 to 9).

Python does not allow punctuation characters such as @, $, and % within identifiers.
Python is a case sensitive programming language. Thus, Manpower andmanpower are
two different identifiers in Python.

Here are naming conventions for Python identifiers −

12
Class names start with an uppercase letter. All other identifiers start with alowercase
letter.

Starting an identifier with a single leading underscore indicates that the identifier is
private.

Starting an identifier with two leading underscores indicates a strongly private


identifier.

If the identifier also ends with two trailing underscores, the identifier is a language-
defined special name.

Reserved Words

The following list shows the Python keywords. These are reserved words and you cannot
use them as constant or variable or any other identifier names. All the Python keywords
contain lowercase letters only.

and exec not


assert finally or
break for pass
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield

13
Lines and Indentation

Python provides no braces to indicate blocks of code for class and function definitions or
flow control. Blocks of code are denoted by line indentation, which is rigidly enforced.

The number of spaces in the indentation is variable, but all statements within theblock
must be indented the same amount. For example −

if True:
print
“True”
else:
print "False"

However, the following block generates an error –

if True:
print
"Answe
r"print
"True"
else:
print
"Answer
"print
"False"
Thus, in Python all the continuous lines indented with same number of spaces
would form a block. The following example has various statement blocks −

14
Note − Do not try to understand the logic at this point of time. Just make sure you
understood various blocks even if they are without braces.
#!/usr/bin/p
ython
import sys
try:

# open file stream

file =
open(file_name, "w")
except IOError:
print "There was an error writing to", file_name
sys.exit()
print "Enter '",
file_finish,print "'
When finished"
while file_text != file_finish:

file_text = raw_input("Enter
text: ")if file_text ==
file_finish:
# close
the file
file.clo
se
break

file.write(file_text)
file.write
("\n")
15
file.close
()
file_name = raw_input("Enter filename:
")if len(file_name) == 0:
print "Next time please enter
something"sys.exit()

try:

file =
open(file_name, "r")
except IOError:
print "There was an error reading
file"sys.exit()
file_text =
file.read()
file.close()
print file_text

Multi-Line Statements

Statements in Python typically end with a new line. Python does, however, allow the use
of the line continuation character (\) to denote that the line shouldcontinue. For example

total =
item_one + \
item_two + \
item_three
16
Statements contained within the [], {}, or () brackets do not need to use the line
continuation character. For example −

days = ['Monday', 'Tuesday',


'Wednesday','Thursday', 'Friday']
Quotation in Python

Python accepts single ('), double (") and triple (''' or """) quotes to denote string
literals, as long as the same type of quote starts and ends the string.

The triple quotes are used to span the string across multiple lines. For example, allthe
following are legal −

word = 'word'

sentence = "This is a sentence."


paragraph = """This is a paragraph.
It is
made up of multiple lines and
sentences."""Comments in Python
A hash sign (#) that is not inside a string literal begins a comment. All characters after
the # and up to the end of the physical line are part of the comment and the Python
interpreter ignores them.

17
total =
item_one + \
item_two + \
item_three

Statements contained within the [], {}, or () brackets do not need to use the line
continuation character. For example −

days = ['Monday', 'Tuesday',


'Wednesday','Thursday', 'Friday']
Quotation in Python

Python accepts single ('), double (") and triple (''' or """) quotes to denote string
literals, as long as the same type of quote starts and ends the string.

The triple quotes are used to span the string across multiple lines. For example, allthe
following are legal −

word = 'word'

sentence = "This is a sentence."


paragraph = """This is a paragraph.
It is
made up of multiple lines and
sentences."""Comments in Python
A hash sign (#) that is not inside a string literal begins a comment. All characters after
the # and up to the end of the physical line are part of the comment and the Python
interpreter ignores them.

Live Demo
#!/usr/bin/py
thon# First
comment
18
print "Hello, Python!" # second
commentThis produces the following
result − Hello, Python!
You can type a comment on the same line after a statement or expression −name =
"Madisetti" # This is again comment
You can comment multiple lines as
follows −# This is a comment.
# This is a
comment, too. #
This is a comment,
too. # I said that
already.
Following triple-quoted string is also ignored by Python interpreter and can be usedas a
multiline comments:

'''

This is a
multiline
comment.
'''

Using Blank Lines

A line containing only whitespace, possibly with a comment, is known as a blankline


and Python totally ignores it.

In an interactive interpreter session, you must enter an empty physical line to


terminate a multiline statement.

Waiting for the User

The following line of the program displays the prompt, the statement saying “Pressthe
19
enter key to exit”, and waits for the user to take action −

#!/usr/bin/python

raw_input("\n\nPress the enter key to exit.")

Here, "\n\n" is used to create two new lines before displaying the actual line. Oncethe user
presses the key, the program ends. This is a nice trick to keep a console window open
until the user is done with an application.

Multiple Statements on a Single Line

The semicolon ( ; ) allows multiple statements on the single line given that neither
statement starts a new code block. Here is a sample snip using the semicolon.

import sys; x = 'foo'; sys.stdout.write(x + '\n')


Multiple Statement Groups as Suites
A group of individual statements, which make a single code block are called suites in
Python. Compound or complex statements, such as if, while, def, and class require a
header line and a suite.

Header lines begin the statement (with the keyword) and terminate with a colon (

: ) and are followed by one or more lines which make up the suite. For example −if
expression :
suite

elif expression :
suite

Command Line Arguments

Many programs can be run to provide you with some basic information about howthey

20
should be run. Python enables you to do this with -h −

$ python -h

usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... Options
and arguments (and corresponding environment variables):
-c cmd : program passed in as string (terminates option list)

-d : debug output from parser (also PYTHONDEBUG=x)

-E : ignore environment variables (such as PYTHONPATH)

-h : print this help message and exit


You can also program your script in such a way that it should accept various options.
Command Line Arguments is an advanced topic and should be studied a bit later once
you have gone through rest of the Python concepts.

Python Lists
The list is a most versatile datatype available in Python which can be written as a list of
comma-separated values (items) between square brackets. Important thing about a list is
that items in a list need not be of the same type.

Creating a list is as simple as putting different comma-separated values between square


brackets. For example −

list1 = ['physics', 'chemistry', 1997, 2000];

list2 = [1, 2, 3, 4, 5 ];

list3 = ["a", "b", "c", "d"]

Similar to string indices, list indices start at 0, and lists can be sliced, concatenated and
so on.

21
A tuple is a sequence of immutable Python objects. Tuples are sequences, just likelists.
The differences between tuples and lists are, the tuples cannot be changed unlike lists
and tuples use parentheses, whereas lists use square brackets.

Creating a tuple is as simple as putting different comma-separated values. Optionally


you can put these comma-separated values between parentheses also.For example −

tup1 = ('physics', 'chemistry', 1997, 2000);

tup2 = (1, 2, 3, 4, 5 );
tup3 = "a", "b", "c", "d";

The empty tuple is written as two parentheses containing nothing −tup1


= ();
To write a tuple containing a single value you have to include a comma, even thoughthere
is only one value −

tup1 = (50,);

Like string indices, tuple indices start at 0, and they can be sliced, concatenated,and so
on.

Accessing Values in Tuples

To access values in tuple, use the square brackets for slicing along with the index or
indices to obtain value available at that index. For example −

Live
Demo
#!/usr/bin/p
ython
tup1 = ('physics', 'chemistry', 1997, 2000);

tup2 = (1, 2, 3, 4, 5, 6, 7 );
22
Updating Tuples

Accessing Values in Dictionary

To access dictionary elements, you can use the familiar square brackets along withthe
key to obtain its value. Following is a simple example −

Live
Demo
#!/usr/bin/p
ython
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}

print "dict['Name']: ", dict['Name']

print "dict['Age']: ", dict['Age']

When the above code is executed, it produces the following result −


dict['Name']: Zara
dict['Age']: 7

If we attempt to access a data item with a key, which is not part of the dictionary,we get
an error as follows −

Live Demo
#!/usr/bin/p
ython
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}

print "dict['Alice']: ", dict['Alice']

When the above code is executed, it produces the following result −

23
dict['Alice']:

Traceback (most recent call last):

File "test.py", line 4, in


<module> print
"dict['Alice']: ", dict['Alice'];
KeyError: 'Alice'

Updating Dictionary

You can update a dictionary by adding a new entry or a key-value pair, modifying an
existing entry, or deleting an existing entry as shown below in the simple example

Live
Demo
#!/usr/bin/p
ython
dict = {'Name': 'Zara', 'Age': 7, 'Class':
'First'}dict['Age'] = 8; # update existing
entry
dict['School'] = "DPS School"; # Add new
entryprint "dict['Age']: ", dict['Age']
print "dict['School']: ", dict['School']

When the above code is executed, it produces the following result −

24
dict['Age']: 8

dict['School']: DPS
School Delete
Dictionary Elements
You can either remove individual dictionary elements or clear the entire contentsof a
dictionary. You can also delete entire dictionary in a single operation.

To explicitly remove an entire dictionary, just use the del statement. Following is a
simple example −

Live
Demo
#!/usr/bin/p
ython
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}

del dict['Name']; # remove entry with key


'Name'dict.clear(); # remove all entries in dict
del dict ; # delete entire
dictionaryprint "dict['Age']: ",
dict['Age']
print "dict['School']: ", dict['School']

This produces the following result. Note that an exception is raised because afterdel
dict dictionary does not exist any more −

25
dict['Age']:

Traceback (most recent call last):

File "test.py", line 8, in


<module>print
"dict['Age']: ", dict['Age'];
TypeError: 'type' object is unsubscriptable

Note − del() method is discussed in subsequent section.

Properties of Dictionary Keys

Dictionary values have no restrictions. They can be any arbitrary Python object, either
standard objects or user-defined objects. However, same is not true for thekeys.

There are two important points to remember about dictionary keys −

(a) More than one entry per key not allowed. Which means no duplicate key is allowed.
When duplicate keys encountered during assignment, the last assignment wins. For
example −

Live Demo
#!/usr/bin/p
ython
dict = {'Name': 'Zara', 'Age': 7, 'Name': 'Manni'}

print "dict['Name']: ", dict['Name']


26
When the above code is executed, it produces the following result −
['Name']: Manni
(b) Keys must be immutable. Which means you can use strings, numbers or tuplesas
dictionary keys but something like ['key'] is not allowed. Following is a simple example

Live Demo
#!/usr/bin/p
ython
dict = {['Name']: 'Zara', 'Age': 7}

print "dict['Name']: ", dict['Name']

When the above code is executed, it produces the following result −


Traceback (most recent call last):
File "test.py", line 3, in
<module>dict = {['Name']:
'Zara', 'Age': 7};
TypeError: unhashable type: 'list'

Tuples are immutable which means you cannot update or change the values of tuple
elements. You are able to take portions of existing tuples to create new tuples as the
following example demonstrates −

Live Demo
#!/usr/bin/p
ythontup1 =
(12, 34.56);

27
tup2 = ('abc', 'xyz');

# Following action is not valid for


tuples# tup1[0] = 100;
# So let's create a new tuple as
followstup3 = tup1 + tup2;
print tup3;

When the above code is executed, it produces the following result –(12,
34.56, 'abc', 'xyz')
Delete Tuple Elements

Removing individual tuple elements is not possible. There is, of course, nothing
wrong with putting together another tuple with the undesired elements discarded.

To explicitly remove an entire tuple, just use the del statement. For example −

Live
Demo
#!/usr/bin/p
ython
tup = ('physics', 'chemistry', 1997,
2000);print tup;
del tup;

print "After deleting


tup : ";print tup;

28
This produces the following result. Note an exception raised, this is because afterdel
tup tuple does not exist any more −

('physics', 'chemistry', 1997,


2000)After deleting tup :
Traceback (most recent call last):

File "test.py", line 9, in


<module>print tup;
NameError: name 'tup' is not defined

29
2.3.2 DJANGO

Django is a high-level Python Web framework that encourages rapid


development and clean, pragmatic design. Built by experienced developers, it takescare of
much of the hassle of Web development, so you can focus on writing your app without
needing to reinvent the wheel. It’s free and open source.

Django's primary goal is to ease the creation of complex, database-driven websites.


Django emphasizes reusabilityand "pluggability" of components, rapid development, and
the principle of don't repeat yourself. Python is used throughout,even for settings files and
data models.

30
Django also provides an optional administrative create, read, update and delete
interface that is generated dynamically through introspection and configured via admin
models

Create a Project

Whether you are on Windows or Linux, just get a terminal or a cmd prompt and
navigate to the place you want your project to be created, then use this code −

$ django-admin startproject myproject

This will create a "myproject" folder with the following structure −


myproject/
manage.py
myproject/

init .py
settings.
31
py
urls.py
wsgi.py

The Project Structure

The “myproject” folder is just your project container, it actually contains two elements

manage.py − This file is kind of your project local django-admin for interacting withyour
project via command line (start the development server, sync db...)

The “myproject” subfolder − This folder is the actual python package of your project. It
contains four files −

init .py − Just for python, treat this folder as

package.settings.py − As the name indicates, your project


settings.

urls.py − All links of your project and the function to call. A kind
of ToC of yourproject.

wsgi.py − If you need to deploy your project over WSGI.


Setting Up Your Project

32
The Project Structure

The “myproject” folder is just your project container, it actually contains two elements

manage.py − This file is kind of your project local django-admin for interacting withyour
project via command line (start the development server, sync db...). To get a full list of
command accessible via manage.py you can use the code −

$ python manage.py help

The “myproject” subfolder − This folder is the actual python package of your project. It
contains four files −

init .py − Just for python, treat this folder as


package.settings.py − As the name indicates, your project
settings.
urls.py − All links of your project and the function to call. A kind of ToC of your
project.

wsgi.py − If you need to deploy your project over WSGI.


Setting Up Your Project
Your project is set up in the subfolder myproject/settings.py. Following are some
important options you might need to set −

DEBUG = True

This option lets you set if your project is in debug mode or not. Debug mode letsyou
get more information about your project's error. Never set it to ‘True’ for a live
project. However, this has to be set to ‘True’ if you want the Django light server to
serve static files. Do it only in the development mode.

33
DATABASES = {

'default': {

'ENGINE':
'django.db.backends.sqlite3',
'NAME': 'database.sql',
'USER': '',

'PASSWORD': '',

'HOST': '',

'PORT': '',

Database is set in the ‘Database’ dictionary. The example above is for SQLite engine.As
stated earlier, Django also supports −

MySQL (django.db.backends.mysql)

PostGreSQL
(django.db.backends.postgresql_psycopg2)Oracle
(django.db.backends.oracle) and NoSQL DB
MongoDB (django_mongodb_engine)

Before setting any new engine, make sure you have the correct db driver installed.You
can also set others options like: TIME_ZONE, LANGUAGE_CODE, TEMPLATE…

34
Now that your project is created and configured make sure it's working −

$ python manage.py runserver

You will get something like the following on running the above code −Validating
models...
0 errors found

September 03, 2015 - 11:41:50

Django version 1.6.11, using settings 'myproject.settings'


Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

A project is a sum of many applications. Every application has an objective and canbe
reused into another project, like the contact form on a website can be an application, and
can be reused for others. See it as a module of your project.

Create an Application

We assume you are in your project folder. In our main “myproject” folder, the samefolder
then manage.py −

$ python manage.py startapp myapp

You just created myapp application and like project, Django create a “myapp” folderwith
the application structure −

35
myapp/

init .pyadmin.py models.py tests.py


views.py

init .py − Just to make sure python handles this folder as a package.

admin.py − This file helps you make the app modifiable in the admin interface.
models.py − This is where all the application models are stored.
tests.py − This is where your unit tests are.

views.py − This is where your application views


are.Get the Project to Know About Your
Application
At this stage we have our "myapp" application, now we need to register it with ourDjango
project "myproject". To do so, update INSTALLED_APPS tuple in the settings.py file
of your project (add your app name) −

INSTALLED_APPS = (

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contentty
pes',
'django.contrib.sessions',

36
'django.contrib.messa
ges',
'django.contrib.staticf
iles','myapp',
)

Creating forms in Django, is really similar to creating a model. Here again, we just need
to inherit from Django class and the class attributes will be the form fields. Let's add a
forms.py file in myapp folder to contain our app forms. We will create alogin form.

myapp/forms.py

#-*- coding: utf-8 -*-

from django import forms

class LoginForm(forms.Form):

user = forms.CharField(max_length = 100)

password = forms.CharField(widget = forms.PasswordInput())

As seen above, the field type can take "widget" argument for html rendering; in ourcase,
we want the password to be hidden, not displayed. Many others widget are present in
Django: DateInput for dates, CheckboxInput for checkboxes, etc.

Using Form in a View

There are two kinds of HTTP requests, GET and POST. In Django, the request object
passed as parameter to your view has an attribute called "method"

37
where the type of the request is set, and all data passed via POST can be accessedvia the
request.POST dictionary.

Let's create a login view in our myapp/views.py


−#-*- coding: utf-8 -*-
from myapp.forms import
LoginFormdef login(request):
username = "not logged in"

if request.method == "POST":

#Get the posted form

MyLoginForm =
LoginForm(request.POST)if
MyLoginForm.is_valid():
username = MyLoginForm.cleaned_data['username']
else:
MyLoginForm = Loginform()

return render(request, 'loggedin.html', {"username" : username})

The view will display the result of the login form posted through the loggedin.html.To
test it, we will first need the login form template. Let's call it login.html.

<html>

<body>

<form name = "form" action = "{% url "myapp.views.login" %}"

38
method = "POST" >{% csrf_token %}

<div style = "max-width:470px;">

<center>

<input type = "text" style = "margin-left:20%;"

placeholder = "Identifiant" name = "username" />

</center>

</div>

<br>

<div style = "max-width:470px;">

<center>

<input type = "password" style = "margin-


left:20%;"placeholder = "password" name =
"password" />
</center>

</div>

<br>

<div style = "max-width:470px;">

39
<center>

<button style = "border:0px; background-color:#4285F4; margin-top:8%;


height:35px; width:80%;margin-left:19%;" type = "submit"
value = "Login" >

<strong>Login</strong>

</button>

</center>

</div>

</form>

</body>

</html>

The template will display a login form and post the result to our login view above. You
have probably noticed the tag in the template, which is just to prevent Cross- site Request
Forgery (CSRF) attack on your site.

{% csrf_token %}

Once we have the login template, we need the loggedin.html template that will be
rendered after form treatment.

<html>

<body>
40
You are : <strong>{{username}}</strong>

</body>
</html>

Now, we just need our pair of URLs to get started: myapp/urls.py

from django.conf.urls import patterns, url

from django.views.generic import


TemplateViewurlpatterns =
patterns('myapp.views',
url(r'^connection/',TemplateView.as_view(template_name = 'login.html')),url(r'^login/',
'login', name = 'login'))
When accessing "/myapp/connection", we will get the following login.htmltemplate
rendered −

Setting Up Sessions

In Django, enabling session is done in your project settings.py, by adding some linesto the
MIDDLEWARE_CLASSES and the INSTALLED_APPS options. This should be done
while creating the project, but it's always good to know, so MIDDLEWARE_CLASSES
should have −

'django.contrib.sessions.middleware.SessionMiddleware'
And INSTALLED_APPS should have −
'django.contrib.sessions'

41
By default, Django saves session information in database (django_session table or
collection), but you can configure the engine to store information using other wayslike:
in file or in cache.

When session is enabled, every request (first argument of any view in Django) hasa
session (dict) attribute.

Let's create a simple sample to see how to create and save sessions. We have builta simple
login system before (see Django form processing chapter and Django Cookies Handling
chapter). Let us save the username in a cookie so, if not signed out, when accessing our
login page you won’t see the login form. Basically, let's make our login system we used
in Django Cookies handling more secure, by savingcookies server side.

For this, first lets change our login view to save our username cookie server side −def
login(request):
username = 'not logged in'

42
Let's create a simple sample to see how to create and save sessions. We have builta simple
login system before (see Django form processing chapter and Django Cookies Handling
chapter). Let us save the username in a cookie so, if not signed out, when accessing our
login page you won’t see the login form. Basically, let's make our login system we used
in Django Cookies handling more secure, by savingcookies server side.

For this, first lets change our login view to save our username cookie server side −def
login(request):
username = 'not logged in'

if request.method == 'POST':

MyLoginForm =
LoginForm(request.POST)if
MyLoginForm.is_valid():
username = MyLoginForm.cleaned_data['username']
request.session['username'] = username
else:

MyLoginForm = LoginForm()

return render(request, 'loggedin.html', {"username" : username}

Then let us create formView view for the login form, where we won’t display the form
if cookie is set −

def formView(request):

if request.session.has_key('username'):

43
username = request.session['username']

return render(request, 'loggedin.html', {"username" : username})else:


return render(request, 'login.html', {})

Now let us change the url.py file to change the url so it pairs with our new view −from
django.conf.urls import patterns, url
from django.views.generic import
TemplateViewurlpatterns =
patterns('myapp.views',
url(r'^connection/','formView', name = 'loginform'),
url(r'^login/', 'login', name = 'login'))
When accessing /myapp/connection, you will get to see the following page

2.4 SYSTEM STUDY:

FEASIBILITY STUDY:

The feasibility of the project is analyzed in this phase and business proposalis
put forth with a very general plan for the project and some cost estimates.
During system analysis the feasibility study of the proposed system is to be carried
out. This is to ensure that the proposed system is not a burden to thecompany. For
feasibility analysis, some understanding of the major
requirements for the system is essential.

44
Three key considerations involved in the feasibility analysis are,

 ECONOMICAL FEASIBILITY

 TECHNICAL FEASIBILITY

 SOCIAL
FEASIBILITY
ECONOMICAL
FEASIBILITY
This study is carried out to check the economic impact that the system willhave
on the organization. The amount of fund that the company can pour into theresearch and
development of the system is limited. The expenditures must be justified. Thus the
developed system as well within the budget and this wasachieved because most of the
technologies used are freely available. Only the customized products had to be
purchased.

TECHNICAL FEASIBILITY

This study is carried out to check the technical feasibility, that is, the
technical requirements of the system. Any system developed must not have a highdemand
on the available technical resources. This will lead to high demands on the available
technical resources. This will lead to high demands being placed on the client. The
developed system must have a modest requirement, as only minimal ornull changes are
required for implementing this system.

SOCIAL FEASIBILITY

The aspect of study is to check the level of acceptance of the system by the user.
This includes the process of training the user to use the system efficiently. Theuser must
not feel threatened by the system, instead must accept it as a necessity.

45
The level of acceptance by the users solely depends on the methods that are employed
to educate the user about the system and to make him familiar with it. His level of
confidence must be raised so that he is also able to make some constructive criticism,
which is welcomed, as he is the final user of the system.

2.5 REQUIREMENT ANALYSIS

The project involved analyzing the design of few applications so as to make the
application more users friendly. To do so, it was really important to keep the navigations
from one screen to the other well ordered and at the same time reducing the amount of
typing the user needs to do. In order to make the application more accessible, the browser
version had to be chosen so that it is compatible with most of the Browsers.

REQUIREMENT SPECIFICATION

Functional Requirements

 Graphical User interface with the User.

Software Requirements

For developing the application the following are the Software Requirements:

1. Python

2. Django

Operating Systems supported

1. Windows 10 64 bit OS

46
Technologies and Languages used to Develop
1. Python

Debugger and Emulator

 Any Browser (Particularly Chrome)

Hardware Requirements

For developing the application the following are the Hardware Requirements:

 Processor: Intel i9

 RAM: 32 GB

 Space on Hard Disk: minimum 1 TB

2.6 SYSTEM SPECIFICATION:

2.6.1 HARDWARE REQUIREMENTS:

 System : Intel i3

 Hard Disk : 1 TB.

 Monitor : 14’ Colour Monitor.

 Mouse : Optical Mouse.

 Ram : 4GB.
47
2.6.2 SOFTWARE REQUIREMENTS:

 Operating system : Windows 10.

 Coding Language : Python.

 Front-End : Html. CSS

 Designing : Html,css,javascript.

 Data Base : SQLite.

48
CHAPTER 3

49
SYSTEM DESIGN

3.1 SYSTEM ARCHITECTURE

50
3.2 DATA FLOW DIAGRAM:

The DFD is also called as bubble chart. It is a simple graphical formalism thatcan be used
to represent a system in terms of input data to the system, variousprocessing carried out
on this data, and the output data is generated by this system.
1. The data flow diagram (DFD) is one of the most important modeling tools. Itis
used to model the system components. These components are the system process,
the data used by the process, an external entity that interacts with thesystem and
the information flows in the system.
2. DFD shows how the information moves through the system and how it is
modified by a series of transformations. It is a graphical technique that depicts
information flow and the transformations that are applied as data moves from
input to output.
3. DFD is also known as bubble chart. A DFD may be used to represent a systemat
any level of abstraction. DFD may be partitioned into levels that represent
increasing information flow and functional detail.

51
3.3 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 methodor 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 toexpress
the design of software projects.

GOALS:

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

4. Provide users a ready-to-use, expressive visual modeling Language so that


they can develop and exchange meaningful models.
5. Provide extendibility and specialization mechanisms to extend the core
concepts.
6. Be independent of particular programming languages and developmentprocess.
7. Provide a formal basis for understanding the modeling language.

8. Encourage the growth of OO tools market.

9. Support higher level development concepts such as


collaborations,frameworks, patterns and components.
10. Integrate best practices.
52
3.3.1 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 thoseuse cases. The
main purpose of a use case diagram is to show what system functionsare performed for
which actor. Roles of the actors in the system can be depicted.

53
3.3.2 CLASS DIAGRAM:

In software engineering, a class diagram in the Unified Modeling Language (UML)is a


type of static structure diagram that describes the structure of a system by showing the
system's classes, their attributes, operations (or methods), and the relationships among
the classes. It explains which class contains information.

54
3.3.3 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 isa
construct of a Message Sequence Chart. Sequence diagrams are sometimes calledevent
diagrams, event scenarios, and timing diagrams.

55
56
3.3.4 ACTIVITY DIAGRAM:

Activity diagrams are graphical representations of workflows of stepwise activitiesand


actions with support for choice, iteration and concurrency. In the Unified Modeling
Language, activity diagrams can be used to describe the business and operational step-
by-step workflows of components in a system. An activity diagramshows the overall flow
of control.

57
CHAPTER 4

58
IMPLEMENTATION:

4.1 MODULES:

 User

 Admin

 Data Preprocessing

 Machine Learning

MODULES DESCRIPTION:

4.1.1 User:

The User can register first. While registering he required a valid user email and mobile
for further communications. Once the user register then admin can activatethe user. Once
admin activated the user then user can login into our system. User can upload the dataset
based on our dataset column matched. For algorithm execution data must be in int
or float format. Here we took Adacel Technologies Limited dataset for testing
purpose. User can also add the new data for existing dataset based on our Django
application. User can click the Data Preparations in the web page so that the data cleaning
process will be starts. The cleaned data and its required graph will be displayed.

4.1.2 Admin:

Admin can login with his login details. Admin can activate the registered users. Oncehe
activate then only the user can login into our system.
Admin can view Users and he can view overall data in the browser and he load thedata.
Admin can view the training data list and test data list. Admin can load the data and view
forecast results.

59
4.1.3 Data Processing:

A dataset can be viewed as a collection of data objects, which are often also calledas a
Sentiment tweets like positive, negative and neutral. Data objects are describedby a number
of features that capture the basic characteristics of an object, such asthe mass of a physical
object or the time at which an event occurred, etc. Featuresare often called as variables,
characteristics, fields, attributes, or dimensions. The study is based on a pipeline that
involves preprocessing, sentiment analysis, topic modeling, natural language processing
and statistical analysis of Twitter data extracted in the form of tweets. We use Tweets
and Sentiment amount of data.

4.1.4 Machine Learning:

Based on the split criterion, the cleaned data is split into 80% training and 20% test,then
the dataset is subjected to one machine learning classifier such as Natural Language
Process(NLP). Sentiment analysis by fine tuning auto encoding models like BERT and
ALBERT to achieve a comprehensive understanding of public sentiment. Thus, we have
analyzed the results of our experiment and methodologyusing the contextual information
and verified the insights.

4.2 Source Code:

User side views:

from ast import alias

from concurrent.futures import


processfrom django.shortcuts import
render
# Create your views here.

from django.shortcuts import render, HttpResponsefrom


django.contrib import messages
import twitter

from .forms import UserRegistrationForm


60
from .models import
UserRegistrationModelfrom django.conf
import settings
import pandas as pd

# Create your views here.

def
UserRegisterActions(reque
st):if request.method ==
'POST':
form =
UserRegistrationForm(request.POST)if
form.is_valid():
print('Data is
Valid')
form.save()
messages.success(request, 'You have been successfully registered')form =
UserRegistrationForm()

return render(request, 'UserRegistrations.html', {'form': form})else:


messages.success(request, 'Email or Mobile Already Existed')
print("Invalid form")
else:

form = UserRegistrationForm()

return render(request, 'UserRegistrations.html', {'form': form})


def UserLoginCheck(request):
if request.method == "POST":

loginid =
request.POST.get('loginid')pswd
= request.POST.get('pswd')
61
print("Login ID = ", loginid, ' Password = ',
pswd)try:
check =
UserRegistrationModel.objects.get(
loginid=loginid, password=pswd)
status = check.status

print('Status is = ',
status)if status ==
"activated":
request.session['id'] = check.id

request.session['loggeduser'] =
check.namerequest.session['loginid'] =
loginid
request.session['email'] = check.email
print("User id At", check.id, status)

return render(request, 'users/UserHomePage.html', {})


else:
messages.success(request, 'Your Account Not at activated')
return render(request, 'UserLogin.html')
except Exception as e:

print('Exception is ',
str(e))pass
messages.success(request, 'Invalid Login id and password')
return render(request, 'UserLogin.html', {})
def UserHome(request):

return render(request, 'users/UserHomePage.html', {})


def DatasetView(request):
path = settings.MEDIA_ROOT + "//" +
'twitter.csv'df = pd.read_csv(path, nrows=100)
62
df = df.to_html

return render(request, 'users/viewdataset.html', {'data': df})def


usrtwitterFNDML(request):
from .utility import twitterMLEDA

svm_acc, svm_report =
twitterMLEDA.process_SVM() svm_report =
pd.DataFrame(svm_report).transpose() svm_report =
pd.DataFrame(svm_report)
nb_acc, nb_report = twitterMLEDA.process_naiveBayes()
nb_report = pd.DataFrame(nb_report).transpose()
nb_report = pd.DataFrame(nb_report)
return render(request, 'users/twitterMl.html',

'svm_report': svm_report.to_html, 'svm_acc': svm_acc,


'nb_report': nb_report.to_html, 'nb_acc': nb_acc,
})

def
predictTrustWorthy(reques
t):if request.method ==
'POST':
test_user_data =
request.POST.get('news')
print(test_user_data)
from .utility import twitterMLEDA

result = twitterMLEDA.fake_news_det(test_user_data)

return render(request, 'users/testform.html', {'msg': result})else:


return render(request, 'users/testform.html', {})

63
Base.html

{% load static %}

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Detecting A Twitter Cyberbullying Using Machine Learning</title>

<meta content="width=device-width, initial-scale=1.0" name="viewport">

<meta content="Free Website Template" name="keywords">

<meta content="Free Website Template" name="description">

<link href="{% static 'img/favicon.ico' %}" rel="icon">

<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;
700;800&display=swap" rel="stylesheet">

<link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css "
rel="stylesheet">

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/5.10.0/css/all.min.css" rel="stylesheet">

<link href="{% static 'lib/animate/animate.min.css' %}" rel="stylesheet">

<link href="{% static 'lib/owlcarousel/owl.carousel.min.css' %}"

64
rel="stylesheet">

<link href="{% static 'lib/lightbox/css/lightbox.min.css' %}" rel="stylesheet">

<link href="{% static 'css/style.css' %}" rel="stylesheet">

</head>

<body>

<div class=" navbar navbar-expand-lg bg-dark navbar-dark ">

<div class="container-fluid">

<a href="index.html" class="navbar-brand"> <span style="color:rgb(172,37,


42);">Detecting A Twitter</span></a>

<button type="button" class="navbar-toggler" data-toggle="collapse"


data-target="#navbarCollapse">

<span class="navbar-toggler-icon"></span>

</button>

<div class="collapse navbar-collapse justify-content-between"


id="navbarCollapse">

<div class="navbar-nav ml-auto">

<a href="{% url 'index' %}" class="nav-item nav-link"


style="color:rgba(210, 62, 9, 0.733);">Home</a>

<a href="{% url 'UserLogin' %}" class="nav-item nav-link"


style="color:rgba(68, 16, 200, 0.844);">User</a>

<a href="{% url 'AdminLogin' %}" class="nav-item nav-link"


style="color:rgb(204, 11, 11);">Admin</a>

<a href="{% url 'UserRegister' %}" class="nav-item nav-link"


style="color:rgb(233, 23, 191);">Registration</a>
65
</div>

</div>

</div>

</div>

{%block contents%}

{%end
block%
}

<!-- <div class="container copyright">

<div class="row">

<div class="col-md-6">

</div>

<div class="col-md-6">

</div>

</div>

</div>

</div>
-->

<!-- Footer End -->

<!-- <a href="#" class="back-to-top"><i class="fa fa-chevron-up"></i></a> -->

<!-- JavaScript Libraries -->

<!-- <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

66
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.mi
n.js"></script>

<script src="{% static 'lib/easing/easing.min.js' %}"></script>

<script src="{% static 'lib/owlcarousel/owl.carousel.min.js' %}"></script>

<script src="{% static 'lib/isotope/isotope.pkgd.min.js' %}"></script>

<script src="{% static 'lib/lightbox/js/lightbox.min.js' %}"></script> -->

<!-- Contact Javascript File -->

<!-- <script src="{% static 'mail/jqBootstrapValidation.min.js' %}"></script>

<script src="{% static 'mail/contact.js' %}"></script> -->

<!-- Template Javascript -->


<!-- <script src="{% static 'js/main.js' %}"></script> -->

</body>

</html>

Admin side views:

from django.shortcuts import


render from django.contrib import
messages
from users.forms import UserRegistrationForm
from users.models import UserRegistrationModel
# Create your views here.
def
AdminLoginCheck(requ
est):if request.method
== 'POST':
usrid =
67
request.POST.get('loginid')
pswd =
request.POST.get('pswd')
print("User ID is = ", usrid)
if usrid == 'admin' and pswd == 'admin':

return render(request, 'admins/AdminHome.html')


else:
messages.success(request, 'Please Check Your Login Details')
return render(request, 'AdminLogin.html', {})
def AdminHome(request):

return render(request, 'admins/AdminHome.html',{})


def RegisterUsersView(request):
data = UserRegistrationModel.objects.all()

return render(request,'admins/viewregisterusers.html',{'data':data})
def ActivaUsers(request):

if request.method ==
'GET': id =
request.GET.get('uid
')status = 'activated'
print("PID = ", id,
status)
UserRegistrationModel.objects.filter(id=id).update(status=status)data =
UserRegistrationModel.objects.all()
return render(request,'admins/viewregisterusers.html',{'data':data})

68
CHAPTER 5

69
RESULTS

Input Design:

The input design is the link between the information system and the user.
It comprises the developing specification and procedures for data preparation and those
steps are necessary to put transaction data in to a usable form for processing can be
achieved by inspectingthe computer to read data from a written or printed document or
it can occur by having people keying the data directly into the system. The design of
input focuses on controlling the amount ofinput required, controlling the errors, avoiding
delay, avoiding extra steps and keeping the processsimple. The input is designed in such
a way so that it provides security and ease of use with retaining the privacy. Input Design
considered the following things:

 What data should be given as input?


 How the data should be arranged or coded?
 The dialog to guide the operating personnel in providing input.
 Methods for preparing input validations and steps to follow when error occur.

Objectives:

1. Input Design is the process of converting a user-oriented description of the


input intoa computer-based system. This design is important to avoid errors in the data
input process and show the correct direction to the management for getting correct
information from the computerized system.

2. It is achieved by creating user-friendly screens for the data entry to handle


large volume of data. The goal of designing input is to make data entry easier and to be
free from errors. The data entry screen is designed in such a way that all the data
manipulates can be performed. Italso provides record viewing facilities.

3. When the data is entered it will check for its validity. Data can be entered

70
with the help of screens. Appropriate messages are provided as when needed so that the
user will not be inmaize of instant. Thus the objective of input design is to create an input
layout that is easy to follow

Output Design:

A quality output is one, which meets the requirements of the end user and
presents the information clearly. In any system results of processing are communicated
to the users and toother system through outputs. In output design it is determined how
the information is to be displaced for immediate need and also the hard copy output. It
is the most important and direct source information to the user. Efficient and intelligent
output design improves the system’s relationship to help user decision-making.

1. Designing computer output should proceed in an organized, well


thought out manner; the right output must be developed while ensuring that each output
element is designed so that people will find the system can use easily and effectively.
When analysis design computeroutput, they should Identify the specific output that is
needed to meet the requirements.

2.Select methods for presenting information.

3.Create document, report, or other formats that contain information


produced by the
system.

The output form of an information system should accomplish one or


more of the
following objectives.

 Convey information about past activities, current status or projections of the


 Future.
 Signal important events, opportunities, problems, or warnings.

71
 Trigger an action.
 Confirm an action.

5.1 Screenshots:

5.1 Home Page:

72
5.2 User register:

5.3 Admin login:

73
5.4 User details:

5.5 User login:

74
5.6 User home:

5.7 View dataset:

75
5.8 Ml results:

76
5.9 Predict results true:

5.10 predict results false:

77
CHAPTER 6

78
System Testing

The purpose of testing is to discover errors. Testing is the process of trying to


discover every conceivable fault or weakness in a work product. It provides a way to
check the functionality of components, sub assemblies, assemblies and/or a finished
product It is the process of exercising software with the intent of ensuring that the
Software system meets its requirements and user expectations and does not fail in an
unacceptable manner. There are various types of test. Each testtype addresses a specific
testing requirement.

6.1 TYPES OF TESTS

6.1.1 Unit testing

Unit testing involves the design of test cases that validate that the internal
program logic is functioning properly, and that program inputs produce valid outputs. All
decision branches and internal code flow should be validated. It is the testing of
individual software units of the application .it is done after the completion of an
individual unit before integration. This is a structural testing, that relies on knowledge of
its construction and is invasive. Unit tests perform basic tests at component level and test
a specific business process, application, and/or system configuration. Unit tests ensure
that each unique path of a business process performs accurately to the documented
specifications and contains clearly defined inputs and expected results.

6.1.2 Integration testing


Integration tests are designed to test integrated software components to determine if they
actually run as one program. Testing is event driven and is more concerned with the basic
outcome of screens or fields. Integration tests demonstrate that although the components
were individually satisfaction, as shown by successfully unit testing, the combination of
components iscorrect and consistent. Integration testing is specifically aimed at exposing
the problems that arisefrom the combination of components

79
6.1.3 Functional Testing

Functional tests provide systematic demonstrations that functions tested are


available as specified by the business and technical requirements, system documentation,
and usermanuals.
Functional testing is centered on the following items:

Valid Input : identified classes of valid input must be


accepted. Invalid Input : identified classes of invalid
input must be rejected.Functions : identified
functions must be exercised.
Output : identified classes of application outputs must be
exercised.Systems/Procedures : interfacing systems
or procedures must be invoked.
Organization and preparation of functional tests is focused on requirements,
keyfunctions, or special test cases. In addition, systematic coverage pertaining to identify
Business process flows; data fields, predefined processes, and successive processes must
be considered for testing. Before functional testing is complete, additional tests are
identified and the effective valueof current tests is determined.

6.1.4 System Testing

System testing ensures that the entire integrated software system meets
requirements. It tests a configuration to ensure known and predictable results. An
example of system testing is theconfiguration oriented system integration test. System
testing is based on process descriptions andflows, emphasizing pre-driven process links
and integration points.

80
6.1.5 White Box Testing

White Box Testing is a testing in which in which the software tester has knowledge
of the inner workings, structure and language of the software, or at least its purpose. It is
purpose.It is used to test areas that cannot be reached from a black box level.

6.1.6 Black Box Testing

Black Box Testing is testing the software without any knowledge of the inner
workings, structure or language of the module being tested. Black box tests, as most other
kinds of tests, mustbe written from a definitive source document, such as specification or
requirements document, such as specification or requirements document. It is a testing in
which the software under test is treated, as a black box .you cannot “see” into it. The test
provides inputs and responds to outputs without considering how the software works.

6.1.7 Unit Testing

Unit testing is usually conducted as part of a combined code and unit test phase of
the software lifecycle, although it is not uncommon for coding and unit testing to be
conducted astwo distinct phases.

Test strategy and approach

Field testing will be performed manually and functional tests will be written in
detail.
Test objectives
 All field entries must work properly.

 Pages must be activated from the identified link.


The entry screen, messages and responses must not be delayed.

Features to be tested
 Verify that the entries are of the correct format

 No duplicate entries should be allowed


81
 All links should take the user to the correct page.

Integration Testing

Software integration testing is the incremental integration testing of two or


more integrated software components on a single platform to produce failures caused by
interface defects.

The task of the integration test is to check that components or software applications, e.g.
components in a software system or – one step up – software applications at the company
level – interact without error.

Test Results: All the test cases mentioned above passed successfully. No defects
encountered.

6.1.8 Acceptance Testing

User Acceptance Testing is a critical phase of any project and requires significant
participation bythe end user. It also ensures that the system meets the functional
requirements.

Test Results: All the test cases mentioned above passed successfully. No defects
encountered.

82
6.2 Sample Test Cases

Remarks(IF
S.no Test Case Excepted Result Result
Fails)
If already user
1 User Register If User registration successfully. Pass email exist
thenit
fails.
Un
If Username and password is
2 User Login Pass Register
correct then it will getting
Users will
valid page.
not
logged in.
The request
The request will be accepted by will be not
svm
3 thesvm Pass accepted by
the svm
otherwise its
failed
The request
The request will be accepted by will be
4 Naive Bayes theNaive Bayes Pass accepted by the
Naive Bayes
otherwise its
failed
View dataset by Results not true
5 Data set will be displayed by the Pass
user user failed

Results not
6 User Display reviews with true results Pass
truefailed
classification

83
Calculate macro avg and
macro avg and weighted
7 accuracy Pass weighted avg
avg calculated
macro avg and not displayed
weighted avg failed
Result will be cyberbulling or not
8 prediction pass Otherwise fail
cyberbulling
Admin can login with his login Invalid login
9 Admin login credential. If success he get his Pass details will
homepage not allowed
here
Admin can If user id
10 activate the Admin can activate the register user Pass not found
register users id then it
won’t login.

84
CHAPTER 7

85
CONCLUSION & FUTURE ENHANCEMENT

7.1 CONCLUSION

An approach is proposed for detecting and preventing Twitter cyberbullying using


Supervised Binary classification Machine Learning algorithms. Our model is evaluated
on both Support Vector Machine and Naive Bayes, also for feature extraction, used the
TFIDF vectorizer. As the results show us that the accuracy for detecting cyberbullying
content has also been great for Support Vector Machine of around 71.25% which is better
than Naive Bayes. Our model will help people from the attacks of social media bullies.

7.2 FUTURE ENHANCEMENT:

Further research on this topic to improve and design better models to improve
accuracy andgenerate reviews.

86
CHAPTER 8

87
BIBLIOGRAPHY

[1] John Hani Mounir, Mohamed Nashaat, Mostafa Ahmed, Zeyad Emad, Eslam Amer,
Ammar Mohammed, “Social Media Cyberbullying Detection using Machine Learning”,
(IJACSA) International Journal of Advanced Computer Science and Applications Vol.
10, pages 703-707, 2019.

[2] Kelly Reynolds, April Kontostathis, Lynne Edwards, "Using Machine Learning to
Detect Cyberbullying”, 2011 10th International Conference on Machine Learning and
Applications volume 2, pages 241–244. IEEE, 2011

[3] Amanpreet Singh, Maninder Kaur, "Content-based Cybercrime Detection: A Concise


Review”, International Journal of Innovative Technology and Exploring Engineering
(IJITEE) ISSN: 2278-3075, Volume-8 Issue-8, pages 1193-1207, 2019

[4] Abdhullah-Al-Mamun, Shahin Akhter, "Social media bullying detection using


machine learning on Bangla text”, 10th International Conference on Electrical and
Computer Engineering,pages 385-388, IEEE Xplore, 2018

[5]NektariaPotha and ManolisMaragoudakis. “Cyberbullying detectionusing


time seriesmodeling”, In 2014IEEE International Conference on, pages
373– 382. IEEE, 2014.

[6] Ying Chen, Yilu Zhou, Sencun Zhu, and Heng Xu. “Detecting offensive language in
social media to protect adolescent online safety”. In Privacy, Security, Risk and Trust
(PASSAT), 2012 International Conference on and 2012 International Conference on
Social Computing (SocialCom), pages 71– 80. IEEE, 2012

[7] Vikas S Chavan, SS Shylaja. “Machine learning approach for detection of cyber-
aggressive comments by peers on social media network". In Advances in computing,
communications, and informatics (ICACCI), 2015 International Conference on, pages
2354–2358. IEEE,2015

[8] Walisa Romsaiyud, Kodchakorn na Nakornphanom, Pimpaka Prasertsilp, Piyaporn


Nurarak, and Pirom Konglerd, “Automated cyberbullying detection using clustering

88
appearance patterns”, In Knowledge and Smart Technology (KST), 2017 9th
International Conference on, pages 242–
247. IEEE, 2017

[9] https://muthu.co/understanding-the-classification-report-in-sklearn/

[10] https://developer.twitter.com/en/apps

[11] https://text-processing.com/demo/tokenize/

[12] https://towardsdatascience.com/support-vector-machine-introduction-
tomachine-learning- algorithms-934a444fca47

[13] https://towardsdatascience.com/naive-bayes-classifier-81d512f50a7c

89
90

You might also like