Module 3 DM
Module 3 DM
4
ISSUE REGARDING CLASSIFICATION & PREDICTION
The major issue is preparing the data for Classification and Prediction.
Preparing the data involves the following activities −
• Data Cleaning − Data cleaning involves removing the noise and
treatment of missing values. The noise is removed by applying
smoothing techniques and the problem of missing values is solved by
replacing a missing value with most commonly occurring value for
that attribute.
• Relevance Analysis − Database may also have the irrelevant
attributes. Correlation analysis is used to know whether any two
given attributes are related.
• Data Transformation and reduction − The data can be transformed by
any of the following methods.
• Normalization − The data is transformed using normalization.
Normalization involves scaling all values for given attribute in
order to make them fall within a small specified range.
Normalization is used when in the learning step, the neural
networks or the methods involving measurements are used.
• Generalization − The data can also be transformed by
generalizing it to the higher concept. For this purpose we can
use the concept hierarchies.
Classification—A Two-Step Process
❖ With the help of the bank loan application that we have discussed above, let us understand the
working of classification. The Data Classification process includes two steps −
➢ Building the Classifier or Model
➢ Using Classifier for Classification
❖ Building the Classifier or Model
➢ This step is the learning step or the learning phase.
➢ In this step the classification algorithms build the classifier.
➢ The classifier is built from the training set made up of database tuples and their
associated class labels.
➢ Each tuple that constitutes the training set is referred to as a category or class. These
tuples can also be referred to as sample, object or data points.
7
Learning: Training data are analyzed by a classification [Link],the class label attribute is
loan decision, and the learned model or classifier is represented in the form of classification rules.
In this step, the classifier is used for classification. Here the test data is used to estimate
the accuracy of classification rules. The classification rules can be applied to the new
data tuples if the accuracy is considered acceptable.
Decision Tree Induction: An Example
age income student credit_rating buys_computer
<=30 high no fair no
Training data set: Buys_computer <=30 high no excellent no
The data set follows an example of 31…40 high no fair yes
>40 medium no fair yes
Quinlan’s ID3 (Playing Tennis) >40 low yes fair yes
Resulting tree: >40 low yes excellent no
31…40 low yes excellent yes
age? <=30 medium no fair no
<=30 low yes fair yes
>40 medium yes fair yes
<=30 medium yes excellent yes
<=30 overcast
31..40 >40 31…40 medium no excellent yes
31…40 high yes fair yes
>40 medium no excellent no
no fair excellent
yes
no yes no yes
10
Algorithm for Decision Tree Induction
• Basic algorithm (a greedy algorithm)
• Tree is constructed in a top-down recursive divide-and-conquer
manner
• At start, all the training examples are at the root
• Attributes are categorical (if continuous-valued, they are
discretized in advance)
• Examples are partitioned recursively based on selected
attributes
• Test attributes are selected on the basis of a heuristic or
statistical measure (e.g., information gain)
• Conditions for stopping partitioning
• All samples for a given node belong to the same class
• There are no remaining attributes for further partitioning –
majority voting is employed for classifying the leaf
• There are no samples left
11
Algorithm: Generate decision tree. Generate a decision tree from the training tuples of data partition, D.
create a node N;
if tuples in D are all of the same class, C, then
return N as a leaf node labeled with the class C;
if attribute list is empty then
return N as a leaf node labeled with the majority class in D; // majority voting
apply Attribute selection method(D, attribute list) to find the “best” splitting criterion;
label node N with splitting criterion;
if splitting attribute is discrete-valued and
multiway splits allowed then // not restricted to binary trees
attribute list attribute list - splitting attribute; // remove splitting attribute
for each outcome j of splitting criterion
// partition the tuples and grow subtrees for each partition
let Dj be the set of data tuples in D satisfying outcome j; // a partition
if Dj is empty then
attach a leaf labeled with the majority class in D to node N;
else attach the node returned by Generate decision tree(Dj , attribute list) to node N;
endfor
return N;
Attribute Selection Measure:
Information Gain (ID3/C4.5)
Select the attribute with the highest information gain
Let pi be the probability that an arbitrary tuple in D belongs to
class Ci, estimated by |Ci, D|/|D|
Expected information (entropy) needed to classify a tuple in D:
m
Info(D) pi log 2 ( pi )
i1
Information needed (after using A to split D into v partitions) to
classify D: v | D |
Info A (D) j
Info(D j )
j 1 | D |
Information gained by branching on attribute A
Gain(income) 0.029
>40 low yes excellent no
31…40 low yes excellent yes
<=30 medium no fair no
<=30
>40
low
medium
yes
yes
fair
fair
yes
yes
Gain(student) 0.151
Gain(credit _ rating) 0.048
<=30 medium yes excellent yes
31…40 medium no excellent yes
14 31…40 high yes fair yes
>40 medium no excellent no
Computing Information-Gain for
Continuous-Valued Attributes
• Let attribute A be a continuous-valued attribute
• Must determine the best split point for A
• Sort the value A in increasing order
• Typically, the midpoint between each pair of adjacent values is
considered as a possible split point
• (ai+ai+1)/2 is the midpoint between the values of ai and ai+1
• The point with the minimum expected information
requirement for A is selected as the split-point for A
• Split:
• D1 is the set of tuples in D satisfying A ≤ split-point, and D2 is
the set of tuples in D satisfying A > split-point
15
Gain Ratio for Attribute Selection
• Information gain measure is biased towards attributes with a
large number of values
• C4.5 (a successor of ID3) uses gain ratio to overcome the
problem (normalization to information gain)
v | Dj | | Dj |
SplitInfo A(D) log 2 ( )
j 1 |D| |D|
• GainRatio(A) = Gain(A)/SplitInfo(A)
• Ex.
17
Computation of Gini Index
• Ex. D has 9 tuples in buys_computer = “yes” and 5 in “no”
9 5
2 2
gini(D) 1 0.459
14 14
• Suppose the attribute income partitions D into 10 in D1: {low,
medium} and 4 in D 2 giniincome{low,medium} (D) 10 Gini(D1) 4 Gini(D 2 )
14 14
• C-SEP: performs better than info. gain and gini index in certain cases
• G-statistic: has a close approximation to χ2 distribution
• MDL (Minimal Description Length) principle (i.e., the simplest solution is
preferred):
• The best tree as the one that requires the fewest # of bits to both (1) encode
the tree, and (2) encode the exceptions to the tree
20
Enhancements to Basic Decision Tree Induction
22
Scalability Framework for RainForest
"Random Forest is a classifier that contains a number of decision
trees on various subsets of the given dataset and takes the
average to improve the predictive accuracy of that dataset."
• Separates the scalability aspects from the criteria that determine the
quality of the tree
26
Visual Mining for Decision Tree Induction
Interactive Visual Mining by Perception-Based Classification (PBC)
27
Data Mining: Concepts and Techniques
Naïve Bayes Classifier
• A probabilistic framework for solving classification problems
• Let D be a training set of tuples and their associated class labels,
and each tuple is represented by an n-D attribute vector X = (x1,
x2, …, xn)
• Suppose there are m classes C1, C2, …, Cm.
• Classification is to derive the maximum posteriori, i.e., the
maximal P(Ci|X)
• This can be derived from Bayes’ theorem P(X|C )P(C )
i i
P(Ci | X)
P(X)
and P(xk|Ci) is e
2
32
Naïve Bayes Classifier: Comments
• Advantages
• Easy to implement
• Good results obtained in most of the cases
• Disadvantages
• Assumption: class conditional independence, therefore loss of
accuracy
• Practically, dependencies exist among variables
• E.g., hospitals: patients: Profile: age, family history, etc.
Symptoms: fever, cough etc., Disease: lung cancer,
diabetes, etc.
• Dependencies among these cannot be modeled by Naïve Bayes
Classifier
33
Association Analysis
• Association mining aims to extract interesting correlations, frequent patterns, associations or casual structures
among sets of items or objects in transaction databases, relational database or other data repositories.
Examples:
Buys (X, “Computer”) ->Buys (X, “Software”) [Support =40%, confidence= 50%]
Association rule:
• Given: (1) database of transaction
(2) each transaction is a list of items (purchased by a customer in visit)
• Find: all rules that correlate the presence of one set of items with that of another set of items.
Example 1: 98% of people who purchase tires and auto accessories also get done.
Example 2: Market Basket Analysis process analyzes customer buying habits by finding associations
between the different items that customers place in their “Shopping Baskets”. The discovery of
such associations can help retailers develop marketing strategies by gaining insight into which
items are frequently purchased together by customer.
Application of Association Rule Mining
• Market basket analysis: Helps retailers understand customer purchasing patterns,
such as which products are often bought together.
• Customer segmentation: Groups customers based on their purchasing habits.
• Fraud detection: Finds patterns in transactions that may indicate fraudulent
activity.
• Recommendation systems: Suggests items to customers based on their browsing
history or past purchases.
• Product clustering and store layout: Groups products together based on
common attributes to help retailers optimize store layout.
• Catalog design: Uses customer purchase history to inform how products are
presented and where they are placed in catalogs.
• Healthcare and research: Helps identify correlations between drug interactions
or different symptoms in medical research.
Association Rule:
• An association rule is an implication
expression of the form X->Y, where X
and Y are disjoint itemsets, i.e., X ∩ Y
= ∅. The strength of an association
rule can be measured in terms of its
support and confidence. Support
determines how often a rule is
applicable to a given data set, while
confidence determines how frequently
items in Y appear in transactions that
contain X. The formal definition of
these metrics are,
• Support, s(X->Y) = (𝑋∪Y)
𝑁
• Confidence, c(X->Y) = (𝑋∪Y)
𝜎(𝑋)
• Support is an important measure because a rule that has very low support
may occur simply by chance. A low support rule is also likely to be
uninteresting from a business perspective because it may not be profitable
to promote items that customers seldom buy together. For these reasons,
support is often used to eliminate uninteresting rules.
• Confidence, on the other hand, measures the reliability of the inference
made by a [Link] a given rule (𝑋∪Y), the higher the confidence, the more
likely it is for Y to be present in transactions that contain X. Confidence also
provides an estimate of the conditional probability of Y given X.
• Therefore, a common strategy adopted by many association rule mining
algorithms is to decompose the problem into two major subtasks:
1. Frequent Itemset Generation, whose objective is to find all the item- sets
that satisfy the minsupthreshold. These itemsets are called frequent
itemsets.
2. Rule Generation, whose objective is to extract all the high-confidence
rules from the frequent itemsets found in the previous step. These rules
are called strong rules.
Frequent Itemset Generation:
• A lattice structure can be used to enumerate the list of all possible
itemsets. Above Figure shows an itemset lattice for I = {a, b, c, d, e}.
In general, a data set that contains k items can potentially generate up
to 2k − 1 frequent itemsets, excluding the null set. Because k can be
very large in many practical applications, the search space of itemsets
that need to be explored is exponentially large.
• To find frequent itemsets we have two algorithms,
a) Apriori Algorithm
b) FP-Growth
Apriori Algorithm:
• Apriori is a seminal algorithm proposed by R. Agrawal and R. Srikant in
1994 for mining frequent itemsets for Boolean association rules. The name
of the algorithm is based on the fact that the algorithm uses prior knowledge
of frequent itemset properties. Apriori employs an iterative approach known
as a level-wise search, where k- itemsets are used to explore (k+1)-itemsets.
• First, the set of frequent 1-itemsets is found by scanning the database to
accumulate the count for each item, and collecting those items that satisfy
minimum support. The resulting set is denoted by L1.
• Next, L1 is used to find L2, the set of frequent 2-itemsets,which is used to
find L3, and so on, until no more frequent k-itemsets can be found.
• The finding of each Lk requires one full scan of the database.
• To improve the efficiency of the level-wise generation of frequent itemsets,
an important property called the Apriori property is used to reduce the
search space.
Apriori property: All nonempty subsets of a frequent itemset must also be
frequent.
• The Apriori property is based on the following observation. By definition, if
an itemset I does not satisfy the minimum support threshold, min sup, then I
is not frequent, that is,P(I)< min sup. If an item A is added to the itemset I,
then the resulting itemset (i.e.,IUA) cannot occur more frequently than I.
Therefore, IUA is not frequent either, that is, P(IUA)< min sup.
• This property belongs to a special category of properties called
antimonotonicity in the sense that if a set cannot pass a test, all of its
supersets will fail the same test as well. It is called antimonotonicity
because the property is monotonic in the context of failing a test.
• A two-step process is followed, consisting of join and prune actions.
1. The join step: To find Lk, a set of candidate k-itemsets is generated by
joining Lk-1 with itself. This set of candidates is denoted Ck.
2. The prune step: Ck is a superset of Lk, that is, its members may or may
not be frequent, but all of the frequent k-itemsets are included in Ck. A
database scan to determine the count of each candidate in Ck would
result in the determination of Lk.
Generating Association Rules from Frequent
Itemsets:
• Once the frequent itemsets from transactions in a database D have
been found, it is straightforward to generate strong association rules
from them.
FP-Growth
• FP-growth (finding frequent itemsets without candidate generation). We
reexamine
• the mining of transaction database, D, of Table in previous Example using the
frequent pattern growth approach.
• The first scan of the database is the same as Apriori, which derives the set of
frequent items (1-itemsets) and their support counts (frequencies). Let the
minimum support count be
• Secondly the set of frequent items is sorted in the order of descending support
count. This resulting set or list is denoted by L. Thus, we have L = {{I2:7}, {I1:6},
{I3:6}, {I4:2},{I5:2}}
• An FP-tree is then constructed as follows. First, create the root of the tree, labeled
with “null.” Scan database D a second time. The items in each transaction are
processed in L order (i.e., sorted according to descending support count), and a
branch is created for each transaction.
• The FP-tree is mined as follows. Start from each frequent length-1 pattern (as an initial suffix pattern), construct its
conditional pattern base (a “sub-database,”which consists of the set of prefix paths in the FP-tree co-occurring with the
suffix pattern), then construct its (conditional) FP-tree, and perform mining recursively on the tree. The pattern growth is
achieved by the concatenation of the suffix pattern with the frequent patterns generated from a conditional FPtree.
From Association Mining to Correlation
Analysis using Lift Ratio
• A correlation measure can be used to augment the support-confidence framework for association rules. This leads to correlation rules of the form
A=>B [support, confidence, correlation]
• That is, a correlation rule is measured not only by its support and confidence but also by the correlation between itemsetsA and B. There are many
different correlation measures from which to choose. In this section, we study various correlation measures to determine which would be good for
mining large data sets.
• Lift is a simple correlation n measure that is given as follows. The occurrence of itemset A is independent of the occurrence of itemsetB if
= P(A)P(B); otherwise, itemsetsA and B are dependent and correlated as events. This definition can easily be extended to more than two
itemsets.
• The lift between the occurrence of A and B can be measured by computing
• If the lift(A,B) is less than 1, then the occurrence of A is negatively correlated with the occurrence of B.
• If the resulting value is greater than 1, then A and B are positively correlated, meaning that the occurrence of one implies the occurrence of the other.
• If the resulting value is equal to 1, then A and B are independent and there is no correlation between them.
• Because this value is less than 1, there is a negative correlation
between the occurrence of {gameg}and {video}.