Data Classification and Clustering Methods
Data Classification and Clustering Methods
The data classification process: (a) 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 formof classification rules. (b) Classification: Test data are used to estimate
the accuracy of the classification rules. If the accuracy is considered acceptable, the rules can
be applied to the classification of new data tuples.
Data Classification
The data classification process: (a) 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 formof classification rules. (b) Classification: Test data are used to
estimate the accuracy of the classification rules. If the accuracy is considered acceptable,
the rules can be applied to the classification of new data tuples.
Data Classification
• Because the class label of each training tuple is provided,
this step is also known as supervised learning (i.e., the
learning of the classifier is “supervised” in that it is told to
which class each training tuple belongs.
• It contrasts with unsupervised learning (or clustering), in
which the class label of each training tuple is not known,
and the number or set of classes to be learned may not be
known in advance.
• For example, if we did not have the loan decision data
available for the training set, we could use clustering to try
to determine “groups of like tuples,” which may correspond
to risk groups within the loan
• application data.
“What about classification accuracy?”
• In the second step (Figure b), the model is used for
classification.
• First, the predictive accuracy of the classifier is estimated.
• If we were to use the training set to measure the classifier’s
accuracy, this estimate would likely be optimistic, because
the classifier tends to overfit the data (i.e., during
learning it may incorporate some particular anomalies of
the training data that are not present in the general data set
overall).
• Therefore, a test set is used, made up of test tuples and
their associated class labels.
• They are independent of the training tuples, meaning that
they were not used to construct the classifier.
“What about classification accuracy?”
• The accuracy of a classifier on a given test set is the
percentage of test set tuples that are correctly classified
by the classifier. The associated class label of each test tuple
is compared with the learned classifier’s class prediction for
that tuple.
• If the accuracy of the classifier is considered acceptable, the
classifier can be used to classify future data tuples for which
the class label is not known. (Such data are also referred to
in the machine learning literature as “unknown” or
“previously unseen” data.)
• For example, the classification rules learned in Figure (a)
from the analysis of data from previous loan applications
canbe used to approve or reject new or future loan
applicants.
Decision Tree Induction
• Decision tree induction is the learning of
decision trees from class-labeled training
tuples.
• A decision tree is a flowchart-like tree
structure, where each internal node (nonleaf
node) denotes a test on an attribute, each branch
represents an outcome of the test, and each leaf
node (or terminal node) holds a class label.
• The topmost node in a tree is the root node.
Decision Tree
Decision Tree Induction
• A typical decision tree is shown in Figure below.
• It represents the concept buys computer, that is, it
predicts whether a customer at AllElectronics is
likely to purchase a computer.
• Internal nodes are denoted by rectangles, and leaf
nodes are denoted by ovals.
• Some decision tree algorithms produce only
binary trees (where each internal node branches to
exactly two other nodes), whereas others can
produce nonbinary trees.
Decision Tree Induction
A decision tree for the concept buys computer, indicating whether an AllElectronics
customer is likely to purchase a computer.
Each internal (nonleaf) node represents a test on an attribute.
Each leaf node represents a class (either buys computer = yes or buys computer = no).
How are decision trees used for
classification
• “How are decision trees used for classification?”
• Given a tuple, X, for which the associated class
label is unknown, the attribute values of the tuple
are tested against the decision tree.
• A path is traced from the root to a leaf node,
which holds the class prediction for that tuples.
• Decision trees can easily be converted to
classification rules.
• During tree construction, attribute selection
measures are used to select the attribute that best
partitions the tuples into distinct classes.
Terminologies related to decision tree
• Root Node: Root node is from where the decision
tree starts. It represents the entire dataset, which
further gets divided into two or more
homogeneous sets.
• Leaf Node: Leaf nodes are the final output node,
and the tree cannot be segregated further after
getting a leaf node.
• Splitting: Splitting is the process of dividing the
decision node/root node into sub-nodes according
to the given conditions.
Terminologies related to decision tree
• Branch/Sub Tree: A tree formed by splitting
the tree.
• Pruning: Pruning is the process of removing
the unwanted branches from the tree.
• Parent/Child node: The root node of the tree
is called the parent node, and other nodes are
called the child nodes.
How does the Decision Tree
algorithm Work?
• In a decision tree, for predicting the class of
the given dataset, the algorithm starts from the
root node of the tree.
• This algorithm compares the values of root
attribute with the record (real dataset) attribute
and, based on the comparison, follows the
branch and jumps to the next node.
How does the Decision Tree
algorithm Work?
• Step-1: Begin the tree with the root node, says S, which
contains the complete dataset.
• Step-2: Find the best attribute in the dataset
using Attribute Selection Measure (ASM).
• Step-3: Divide the S into subsets that contains possible
values for the best attributes.
• Step-4: Generate the decision tree node, which contains the
best attribute.
• Step-5: Recursively make new decision trees using the
subsets of the dataset created in step -3. Continue this
process until a stage is reached where you cannot further
classify the nodes and called the final node as a leaf node.
Example:
• Example: Suppose there is a candidate who has a job offer
and wants to decide whether he should accept the offer or
Not.
• So, to solve this problem, the decision tree starts with the
root node (Salary attribute by ASM).
• The root node splits further into the next decision node
(distance from the office) and one leaf node based on the
corresponding labels.
• The next decision node further gets split into one decision
node (Cab facility) and one leaf node.
• Finally, the decision node splits into two leaf nodes
(Accepted offers and Declined offer).
• Consider the below diagram:
Example:
Attribute Selection Measures
• Information Gain:
– Information gain is the measurement of changes in entropy
after the segmentation of a dataset based on an attribute.
– It calculates how much information a feature provides us
about a class.
– According to the value of information gain, we split the
node and build the decision tree.
– A decision tree algorithm always tries to maximize the
value of information gain, and a node/attribute having the
highest information gain is split first. It can be calculated
using the below formula:
– Information Gain= Entropy(S)-
[(Weighted Avg) *Entropy(each feature
Attribute Selection Measures
• Entropy:
– Entropy is a metric to measure the impurity in a given
attribute. It specifies randomness in data. Entropy can be
calculated as:
Entropy(s)= -P(yes)log2 P(yes)- P(no) log2 P(no)
Where,
• S= Total number of samples
• P(yes)= probability of yes
• P(no)= probability of no
–
Attribute Selection Measures
• Gini Index:
– Gini index is a measure of impurity or purity used
while creating a decision tree in the
CART(Classification and Regression Tree) algorithm.
– An attribute with the low Gini index should be
preferred as compared to the high Gini index.
– It only creates binary splits, and the CART algorithm
uses the Gini index to create binary splits.
– Gini index can be calculated using the below formula:
• Gini Index= 1- ∑jPj2
Bayesian Classification Method
• A statistical classifier: performs probabilistic prediction, i.e.,
predicts class membership probabilities
• Foundation: Based on Bayes’ Theorem.
• Performance: A simple Bayesian classifier, naïve Bayesian
classifier, has comparable performance with decision tree and
selected neural network classifiers
• Incremental: Each training example can incrementally
increase/decrease the probability that a hypothesis is correct —
prior knowledge can be combined with observed data
• Standard: Even when Bayesian methods are computationally
intractable, they can provide a standard of optimal decision
making against which other methods can be measured
Bayesian Theorem Basics
• Total probability Theorem:
• Bayes’ Theorem:
Section - 3
K-Means Algorithm - Example
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (185,7
1
4 179 68 2)
5 182 72
6 188 77
7 180 71
K
8 180 70
2
9 183 84 (170,5
6)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 62
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (185,7
1
4 179 68 2)
5 182 72
6 188 77
7 180 71
K
8 180 70
2
9 183 84 (170,5
6)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 63
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (185,7
1
4 179 68 2)
5 182 72
6 188 77
7 180 71
K
8 180 70
2
9 183 84 (169,
58)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 64
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (185,7
1
4 179 68 2)
5 182 72
6 188 77
7 180 71
K
8 180 70
2
9 183 84 (169,5
8)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 65
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (182,7
1
4 179 68 0)
5 182 72
6 188 77
7 180 71
K
8 180 70
(169,
2
9 183 84 58)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 66
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (182,7
1
4 179 68 0)
5 182 72
6 188 77
7 180 71
K
8 180 70
2
9 183 84 (169,5
8)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 67
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (182,7
1
4 179 68 1)
5 182 72
6 188 77
7 180 71
K
8 180 70
(169,
2
9 183 84 58)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 68
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (182,7
1
4 179 68 1)
5 182 72
6 188 77
7 180 71
K
8 180 70
2
9 183 84 (169,5
8)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 69
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (183,7
1
4 179 68 2)
5 182 72
6 188 77
7 180 71
K
8 180 70
(169,
2
9 183 84 58)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 70
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
3 168 60 (183,7
1
4 179 68 2)
5 182 72
6 188 77
7 180 71
K
8 180 70
2
9 183 84 (169,5
8)
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 71
K-Means Algorithm – Example Cont..
Sr. Heig Weig
ht ht
1 185 72
2 170 56 K
Cluster K1 = {1,4,5,6,7,8,9,10,11,12}
3 168 60 1
4 179 68
5 182 72
6 188 77
7 180 71
K
8 180 70
2 Cluster K2 = {2,3}
9 183 84
10 180 88
11 180 67
12 177 76
Prof. Naimish R Vadodariya #3160714 (DM) ⬥ Unit 5 – Cluster Analysis 72
K-Means Algorithm Cont..
Let us assume two clusters, and each individual's scores include two
variables.
Step-1
⮩ Choose the number of clusters.
Step-2
⮩ Set the initial partition, and the initial mean vectors for each cluster.
Step-3
⮩ For each remaining individual...
Step-4
⮩ Get averages for comparison to the Cluster 1:
▪ Add individual's A value to the sum of A values of the individuals in Cluster 1, then
divide by the total number of scores that were summed.
▪ Add individual's B value to the sum of B values of the individuals in Cluster 1, then
divide by the total number of scores that were summed.