Spam Mail Detection Using Data Mining
Spam Mail Detection Using Data Mining
Vikas Pareek
Department of Computer Science of Banasthali University, Banasthali, India
E-mail: er_pareekvikas@[Link]
Abstract — As web is expanding day by day and people user. These kind of unwanted mails are better known as
generally rely on web for communication so e-mails are Spam Mails. Spam email is the practice of frequently
the fastest way to send information from one place to sending unwanted data or bulk data in a large quantity to
another. Now a day’s all the transactions all the some email accounts. Spam Mail is a subset of
communication whether general or of business taking electronic spam involving nearly identical messages sent
place through e-mails. E-mail is an effective tool for to various recipients by email. Spam mails also include
communication as it saves a lot of time and cost. But e- malware as scripts or other executable file attachment.
mails are also affected by attacks which include Spam There are two main types of spam and they have
Mails. Spam is the use of electronic messaging systems different affects on Internet users. Cancellable Usenet
to send bulk data. Spam is flooding the Internet with spam is a single message sent to 20 or more Usenet
many copies of the same message, in an attempt to force groups. Usenet spams aims at “lurkers”, people who
the message on people who would not otherwise choose read newsgroups but rarely or never post and give their
to receive it. In this study, we analyze various data address away. Usenet spam subverts the ability of
mining approach to spam dataset in order to find out the system administrator to manage the topics they accept
best classifier for email classification. In this paper we on their systems. Another type of Email spam targets
analyze the performance of various classifiers with individual users with direct mail messages. Email spam
feature selection algorithm and without feature selection list are created by scanning Usenet postings, stealing
algorithm. Initially we experiment with the entire dataset Internet mailing list. Email spam is any email that meets
without selecting the features and apply classifiers one the following three criteria:
by one and check the results. Then we apply Best-First 1) Anonymity: The address and identity of the sender
feature selection algorithm in order to select the desired are concealed.
features and then apply various classifiers for 2) Mass Mailing: The email is sent to large group of
classification. In this study it has been found that results people.
are improved in terms of accuracy when we embed 3) Unsolicited: The email is not requested by
feature selection process in the experiment. Finally we recipients.
found Random Tree as best classifier for spam mail Spam Mail has become an increasing problem in
classification with accuracy = 99.72%. Still none of the recent years. It has been estimated that around 70% of
algorithm achieves 100% accuracy in classifying spam all emails are spam. As the usage of web expanding,
emails but Random Tree is very nearby to that. problem of spam mails are also expanding. According to
[1] it has been found that on an average 10 days per year
Index Terms — Classifier, Feature Selection, E-mails, waste on dealing with spam mails only. Spam is an
Spam Mails. expensive problem that costs billion of dollars per year
to service providers for lost of bandwidth. Spam is a
major problem that attacks the existence of electronic
I. INTRODUCTION messages. So it is very essential to distinguish emails
E-Mail is an effective way of communication as it from spam mails, many methods have been proposed for
saves a lot of time and money this makes it as a classification of email messages as spam mail or
favourite means of communication in personal as well as legitimate mail and it has been found that machine
in professional communication. E-mails provide a way learning algorithm success ratio for classification is very
for internet users to easily transfer information globally. high [2].
But there is also a case when your e-mails are affected Several algorithms are used for classification of spam
by attacks whether active or passive. Sometimes we mails which are extensively utilize and analyze out of
receive e-mail from unknown source and also e-mail which support vector machine, Naïve Bayes, Decision
comprised of contents which is of no importance to the Tree, Neural network classifiers are well known
classifiers. In this paper we experiment our data set with
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39
32 Spam Mail Detection through Data Mining – A Comparative Performance Analysis
these given algorithms: Naïve Bayes, Bayes Net, 2) Clusters: Data items are placed in a group
Support vector machine (SVM), function Tree (FT), J48, according to logical relationships. For example, data can
Random Forest and Random Tree. Initially we be mined to identify market segments.
experiment on entire data set which consists of total 58 3) Associations: Data mining is applied to data set to
attributes and total number of instances is 4601. We find out the associations.
apply above mentioned algorithm one by one on the data 4) Sequential Patterns: Data is mined to anticipate
set and check the result and it is retrieved from the study behavior patterns and trends.
that out of all these classifiers Random Forest and Basically Data mining involves listed five elements:
Random Tree works well and gives accuracy better than
1) Extract, transform, and load data on data
other classifiers in detection of spam mails. In order to
warehouse system.
compare the result that classifiers works well with some
2) Store and manage data in multidimensional
attributes selected or not, then we apply Feature
database system.
selection algorithm on the same dataset (the algorithm
3) Provide data access in an easier manner to business
we used here is Best First Search algorithm) and apply
analyst and technical professionals.
the same classifiers with features selected. Out of 58
4) Analyze data by existing tool/application software.
features only 15 features are selected and apply the same
5) Make data in format which is useful to concerned
above mentioned algorithm on this reduced dataset.
user such as graph or tables.
From this study it is found that all classifier’s accuracy
improved when we select features through Best-First Sometimes we treat data mining as a synonym for
algorithm. Again when compared with all classifiers another known term, Knowledge discovery from
which we experimented on this reduced data set Random databases (KDD), because data mining is necessary step
Tree shows better results in context of accuracy. in the process of knowledge discovery from the database.
This paper is organized as follows: Section 2 Knowledge discovery is a combination of all these steps
comprised of Background study, Section 3 presents shown in fig.1.
related work, Section 4 presents the Experimental work
and results, Section 5 presents Experimental Results and Steps of knowledge discovery
Section 6 presents conclusion and future work.
II. BACKGROUND STUDY Data Data Data Data Data Pattern Knowledge
Cleaning Integration Selection Transformation Mining Evaluation Presentation
This section presents an overview of what is Data
Mining, different algorithm of data mining, explains
Figure. 1: Knowledge Discovery steps
Feature selection and most of the terms that we used in
this paper. Data mining involves many different algorithms to
A. Data Mining achieve the desired tasks. All of these algorithms try to
fit a model, the algorithm examine the data and find out
Data Mining is basically the discovery of knowledge
the model that is closest to the characteristics of the data
from the large database. It is a technique that attempts to
being examined. Data mining algorithms characterized
find out new patterns in huge data sets. It is mixture of
based on the purpose of the algorithm to fit a model to
various fields like Artificial Intelligence, Machine
the data, based on Preference, and all algorithms require
Learning, statistics, and Database systems. The main
some approach for searching. Fig.2 shows the model
objective of data mining approach is to extract
than can be either predictive or descriptive.
information from a data set and transform it into and
understandable form for further use. The actual data
mining task is the automatic or semi-automatic analysis Data Mining
of large quantities of data to extract previously
undetermined interesting patterns. Data Mining is the
process of analyzing data from different perspective and
summarizing it into useful information and this
information can be used to increase revenue, cut costs, Predictive Descriptive
for classification, prediction etc. It is the process of
finding correlations in large relational databases. While
large-scale information technology has been evolving Classification Sequence
Time Series Association
separate transactions and analytical systems, data mining Rules Discovery
Analysis
provides the link between the two approaches. Data
mining software analyzes relationships in stored data Regression
based on end user queries. In general these 4 types of Prediction
Summarization Clustering
relationships are sought:
1) Classes: Class is used to place the data in Figure. 2: Data Mining Models and tasks
predetermined groups.
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39
Spam Mail Detection through Data Mining – A Comparative Performance Analysis 33
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39
34 Spam Mail Detection through Data Mining – A Comparative Performance Analysis
the terms occurring in the training set and using only this
subset as features in classification. It serves two main Training Data Classification
Algorithm
purposes: First, it makes training and applying a
classifier more efficient by decreasing the size of data
set. Second, feature selection enhances accuracy of
classifier by eliminating extra features from the data set.
A Feature selection algorithm is a computational Classification rules
solution which is motivated by certain rules of relevance. If age = “31---40” and
An irrelevant feature is not useful for induction, but it income = high then
also not essential that all relevant features are used for credit rating = excellent
induction [5]. Feature Selection algorithm can be
classified according to the kind of output they produce:
(1) algorithms that produce a linear order of features and Name Age Income Credit rating
(2) algorithms that produce a subset of original features. Sandy <=30 low fair
In the study [6, 7, 8] characterization of Feature
Bill <=30 low excellent
selection algorithm is described. In this context it is
possible to describe this characterization as a search Susan >40 medium fair
problem as follows:
Figure. 3: Learning and Training of classifier
1) Search Organization. This technique is related to
the portion of hypothesis investigated with respect to In the second step as shown in fig. 4, the model is
their total number. used for classification. First the predictive accuracy of
2) Generation of Successors. This technique defines the model is estimated. The accuracy of a model on a
by which possible variants of the current hypothesis are given test data set is the percentage of test set samples
proposed. that are correctly classified by the model. For each test
3) Evaluation Measure. Method, by which variants or sample the known class label is compared with the
successor candidates are evaluated, allowing to compare learned model’s class prediction for that sample.
different hypothesis to supervise the search process.
In Feature Selection Algorithm we select a subset of
features. Subset selection evaluates a subset of features Classification Rules
and these algorithms can be broken into Wrappers,
filters and Embedded. Wrappers use a search algorithm
to find out the space of possible features. Wrappers are
Test Data New Data
computationally expensive and have a risk of over fitting
the model. Filters are same as Wrappers in context of
search space, but instead of evaluating against a model,
a simpler filter is evaluated. Embedded approach is (John,31…40,high,credit rating?)
embedded in and specific to a model.
Following are some extensively used Feature selection
algorithms: (1) Best First (2) Simulated Annealing (3) Excellent
Genetic algorithm (4) Scatter Search and (5) Greedy
forward selection etc. Name Age Income Credit rating
Frank > 40 high fair
2.2.5 Classification and Prediction
Crest <=30 low fair
Classification is the separation of objects into classes. Annee 31…40 high excellent
If the classes are created without looking at the data then
the classification is known as apriori classification. If Figure. 4: Classification
classes are created by looking at the data then the
classification method is known as posterior classification. Prediction can be viewed as the construction and use
On classification it is assumed that the classes have been of a model to assess the class of an unlabeled sample, or
deemed apriori and classification then consists of to assess the value ranges of an attribute that a given
training the system so that when a new object is sample is likely to have. In this context classification
introduced to the trained system it is able to assign the and regression are the two major types of prediction
object to one of the existing classes. This approach is problems, where classification is used to predict discrete
better known as supervised learning. Data Classification or nominal values, while regression is used to predict
is a two step process as shown in fig. 3. In the first step, continuous or ordered values.
model is built describing a predetermined set of data
classes. The model is constructed by analyzing database
III. RELATED WORK
tuples described by the attributes. Each tuple is assumed
to belong to one of the existing class, as determined by Spam Mails are one of the major problematic areas in
the class label attribute. The data tuples analyzed to the Internet world which can bring financial loss to
build the model collectively form the training set. organizations and also bring damage to individual users
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39
Spam Mail Detection through Data Mining – A Comparative Performance Analysis 35
as well. Email spam also known as junk mails which are help of existing machine learning techniques. According
sent to a group of recipients who have not requested it. to the study [15] clusters of spam emails are created with
Spam is a serious problem that threatens the existence of the help of criterion function. Criterion function is
e-mail services. As it involves no cost so it is quiet defined as the maximization of similarity between
cheap to send bulk e-mail to a group of users. It messages in clusters and this similarity is calculated
consumes a lot of time to delete or sort these spam using k-nearest neighbour algorithm.
emails and also introduces a risk of deleting normal Symbiotic Data Mining is a distributed data mining
mails by mistake. In the study [9] Rambow et al. approach which unifies content based filtering with
applied machine learning techniques for email collaborative filtering is described in [16]. The main
summarization. In this study, RIPPER classifier is used objective is to make use of local filters again in order to
for the determination of sentences which should be improve personalized filtering in context of privacy. In
included in a summary. Learning model use features study [17] email classifiers based on the approach of
such as Linguistic feature, email features, and threading feed forward back propagation neural network and
structure. This approach requires positive examples in Bayesian classifiers are evaluated. From this study it is
huge quantity and it is also found that summaries are not found that feed forward back propagation neural
produced for varying length based on user interest. network classifier provides very high accuracy as
There are so many existing techniques for detection of compared to other existing classifiers. In the paper [18]
these spam emails. These approaches come mainly from Bayesian approach is applied for the problem of
the area of Artificial Intelligence, Data Mining, or classification and clustering using model based on the
Machine Learning. Machine learning techniques are assumptions like: population, subject, latent variable,
more varied and used extensively for spam mail and sampling scheme.
classification. Decision tree classify spam mails using According to [19] content filtering was one of the first
previous data [10]. But it is costly to calculate and types of anti spam filter. These types of filters make use
recalculate as spammers change technique. In the study of hard coded rules which has an associated score and is
[11] Bayesian networks found as the very popular updated periodically. One main example of such type of
technique for spam mail detection. But with this filter is Spam Assassin [20] which works by scanning
approach it is quiet difficult to scale up on many features the text document of the e-mail against each rule and
to come out with the judgement. add score for all matching rules. According to the study
In [12] fuzzy clustering approach is used. In this paper [21] if total score of the e-mail exceeds some set
author evaluated the use of fuzzy clustering and text threshold score then that message falls into spam mail
mining for spam filtering. Fuzzy clustering is scalable category. In order to generate these score a single
and easy to update approach. This study deals with the perceptron is used where the inputs to the perceptron
examination of use of fuzzy clustering algorithm to build indicate whether a rule was matched and the weight for
a spam filter. Classifier has been tested on different data the corresponding input indicates the score for each rule.
sets and after testing Fuzzy C-Means using In the paper [22] spam is detected using artificial
Heterogeneous Value Difference Metric with variable neural network. In this paper author designed the
percentages of spam and used a standard model of artificial neural network spam detector using the
assessment for the problem of spam mail classification. perceptron learning rule. Perceptron employs a
This paper makes use of text mining and fuzzy stochastic gradient method for training, where the true
clustering as an anti-spam technique. If each email that gradient is evaluated on a single training example and
comes in is used as part of the data pool to make the weights are adjusted accordingly until a stopping
decisions about future emails, spam trends will be criterion is met. At each iteration an error weight
detected. It is found that there is not large cost of adjustment value are computed by comparing the actual
calculation and recalculation that would occur with output value with the expected output value. Testing
decision tree, or with some rule-based filters. phase was done by subjecting the Artificial Neural
We all were aware about the fact that Spam mails Network to messages that were not used in training
create a lot of problem in today’s world. So various without adjusting the weights.
approaches are developed to stop spam mails. The main
objective in spam filtering is to rule out the unwanted
emails automatically from user inbox. These unwanted
are root cause for the problems like filling mailboxes, IV. PROPOSED WORK
engulfing important personal mail, wasting a lot of In this study we detect spam mails using various
network bandwidth also causes congestion problem, classifiers. The whole experiment comprised of two
time and energy loss to the users while sorting these parts. First we will apply various classifiers for spam
unwanted mails [13]. In the study [14] two methods are mail classification and check the results in terms of
described for classification. First is done with some rules accuracy for each classifier. Here we use the entire data
that are defined manually, like rule based expert system. set and apply algorithm one by one without selecting
This technique of classification is applied when classes any feature. In the second part we detect spam mails by
are static, and their components are easily separated in not using the entire data set instead we apply feature
accordance with the features. Second is done with the selection algorithm first, the algorithm which we use
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39
36 Spam Mail Detection through Data Mining – A Comparative Performance Analysis
here is Best-First Feature Selection algorithm then on (RMSE), Relative Absolute Error (RAE), and Root
the reduced data set with selected features we will apply Relative Squared Error (RRSE) for all the classifiers and
all the classifiers one by one and check the results. It is compare the results based on all these statistics. Same
found that classifier’s accuracy improved when we characteristics are also compared for all classifiers when
embed feature selection algorithm in the process. These we use feature selection in the process.
are some of the classifiers that we use in this study: (1) The dataset which we use is from UCI Machine
Naïve Bayes (2) Bayesian Net (3) Support Vector Learning Repository [23] which consists of 58 attributes
Machine (SVM) (4) Function Tree (FT) (5) J48 (6) where 57 continuous attribute and 1 nominal class label
Random Forest (7) Random Tree and (8) Simple Cart. attribute and total number of instances is 4601. Table I
We find out accuracy, Kappa statistics (KS), Mean presents the entire dataset with attribute description.
Absolute Error (MAE), Root Mean Squared Error
The overall design of the proposed system is depicted tasks like data cleaning, data integration, data
in Fig.5 for classification of e-mail as spam without transformation, or data reduction. Before applying any
taken into consideration the feature selection approach data mining techniques to the data set we first normalize
and Fig.6 for classification of e-mail as spam with taken the entire data set in order to yield good results. Up to
into consideration the Feature Selection Approach. this step both the proposed system works similarly then
Below shown (Fig. 5 and Fig.6) is the overall after as per architecture I shown in fig.5 we apply
architecture of proposed system. In this architecture first classifiers one by one to the entire data set and evaluate
we train the spam data set which comprised of 58 the performance of classifier. Then test the data using
attributes with total 4601 instances. Then we apply the classifiers and classify mails as spam and non spam.
Preprocessing, as we all know that real world data As per proposed architecture II shown in Fig. 6 after the
contains missing values or noisy values so in order to pre-processing step we first apply Feature selection
produce good results from the data set we need to mine algorithm, the algorithm which we deploy here is Best-
data. As quality decision depends on good quality data, First Feature Selection algorithm. Table II reflects the
pre-processing is crucial step before applying any view of selected features after applying the algorithm to
classifier to the data set. Pre-Processing involves the the data set.
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39
Spam Mail Detection through Data Mining – A Comparative Performance Analysis 37
Training Spam
Preprocessin
Data set
g Test spam
data Best Classifier
Class Label
A. Experiment I
Performance Evaluation
In order to validate the proposed scheme for spam
mail detection, we conduct several experiments. The
main objective is to find out the best classifier whose
accuracy is better than the rest of the classifiers. The
Test spam dataset which we use is Spambase dataset consisting of
data Best Classifier
57 attributes with one target attribute in discrete format.
Following classification are applied one by one on the
dataset: (1) Naïve Bayes (2) Bayesian Net (3) Support
Vector Machine (SVM) (4) Function Tree (FT) (5) J48
(6) Random Forest (7) Random Tree and (8) Simple
Class Label Cart. And it is found form this study that out of all
classifiers investigated on the given data set Random
forest achieves highest accuracy that is 94.82%. Table
III presented the result of entire classifiers in terms of
accuracy, Kappa statistics (KS), Mean Absolute Error
Figure. 5: Overall architecture of proposed system (MAE), Root Mean Squared Error (RMSE), Relative
Absolute Error (RAE), and Root Relative Squared Error
(RRSE). We computed all these listed statistics and
prepare this comparative table from the result. After
analyzing the data presented in table III , Random Forest
is found to be the best classifier for spam mail
classification with accuracy= 94.82%, then second
highest accuracy is achieved by FT whose accuracy is
93.34% and so on. So from this study it is found that tree
like classifier performs well in case of classification of
spam mails.
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39
38 Spam Mail Detection through Data Mining – A Comparative Performance Analysis
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39
Spam Mail Detection through Data Mining – A Comparative Performance Analysis 39
conference on machine learning and applications, [18] Erosheva E A and Fienberg S E. Bayesian mixed
Miami, FL, USA,2009, 517-522. membership models for soft clustering and
[3] Vapnik V N. Statistical learning theory [M]. John classification [J]. Proceedings of National
W iley &Sons, NewYork, N Y, 1998. Academy of Sciences, 2004, 97(22):11885-11892.
[4] Ian H, Witten and Eibe [Link] Mining: [19] Crawford E, Kay J, McCreath E. Automatic
Practical machine learning tools and techniques”, induction of rules for e-mail classification [C]. In
2nd Edition. San Fransisco: Morgan Kaufmann; 6th Australian Document Computing symposium,
2005. Coffs Harbour, Australia, 2001, 13-20.
[5] Caruana R.A. and Freitag D. How useful is [20] Spam Assassin. The Apache Spam Assassin
Relevance? Technical Report [A]. AAAI Project. [Link]
Symposium on Relevance, New Orleans, 1994. [21] Stern H. Fast Spam Assassin Score Learning tool
[6] Blum A.L. and Langley P. Selection of Relevant [Link]
Features and Examples in Machine Learning [C]. ssin 3.0.3/masses/[Link],2004.
In International Symposium on Artificial [22] Kufandirimbwa O, Gotora R. Spam detection using
Intelligence on Relevance, 1997, 245-271. Artificial Neural Networks [J]. In Online Journal of
[7] Doak J. An Evaluation of Feature Selection Physical and Environmental Science Research,
Methods and their Application to computer 2012, 1:22-29.
Security [R]. Technical Report CSE-92-18, Davis, [23] UCI – Machine Learning Repository – Spambase
Ca: University of California, Department of [Link]://[Link]/ml/datasets/Spam
computer Science, 1992. base.
[8] Liu H and Motoda H, and Dash M. A Monotonic
Measure for Optimal Feature Selection [C]. In Proc.
Of the European Conf. on Machine Learning,
Springer Verlag, 1998, 101-106.
Authors’ Profiles
[9] Ducheneaut N and Bellotti V. E-mail as habitat: an
exploration of embedded personal information Megha Rathi: She is Assistant
management [A]. Interactions ACM, 2001, 8: 30- Professor (Grade II) at Jaypee
38. Institute of Information Technology,
[10] Carreras X, and Marquez L. Boosting trees for anti India. She holds a Masters of
spam filtering [C]. In International conference on Technology and a Bachelor of
Recent Advances in Natural Language Processing. , Engineering degree in Computer
2001 160-167. Science and Engineering. Currently
[11] Sahami M, Dumasi S, Heckerman D, and Horvitz she is pursuing her PhD in Computer Science and
E. A Bayesian approach to filtering junk e-mail: In Engineering. Her areas of interest are Database systems,
Learning for text categorization [A]. Papers from Software Engineering, Software Testing and Artificial
the 1998 Workshop, Madison, Wisconsin, 1998. Intelligence.
[12] Mohammad N.T.A Fuzzy clustering approach to
filter spam E-mail [A].Proceedings of World Vikas Pareek: He is Associate
Congress on Engineering, vol. 3, WCE-2011. Professor at Banasthali University,
[13] Ahmed K. An overview of content-based spam Rajasthan, India. He obtained his
filtering techniques [A]. Informatica, 2007, 31(3): Doctorate in the area of Cryptography.
269-277. He also holds a Bachelor of
[14] Biro I, Szabo J, Benczur A, and Siklosi D. Linked Engineering degree in Computer
Latent Dirichlet Allocation in Web Spam Filtering Science and Engineering. His areas of
[A].In Proceedings of the 4th International interest are Cryptography, Algorithms, Data Structures,
Workshop on Adversarial Information Retrieval on and Electronic Commerce. He has many publications in
the Web (AIR Web), Madrid, Spain, 2009. international journals and conferences to his credit.
[15] Perkins A. The classification of search engine spam.
[Link] [Link]/white
papers/spam classification, 2001.
[16] Paulo C, Clotilde L, Pedro S. Symniotic data
mining for personalized spam filtering [C]. In the
Proceedings of the International Conference on
Web Intelligence and Intelligent Agent Technology,
2009, 149-156.
[17] Rasim M A, Ramiz M A, and Saadat A N.
Classification of Textual E-mail spam using Data
Mining Techniques [J]. In the Journal of Applied
Computational Intelligence and Soft Computing,
2011.
Copyright © 2013 MECS I.J. Modern Education and Computer Science, 2013, 12, 31-39