Classification
Classification
• In each of these examples, the data analysis task is classification, where a model or
classifier is constructed to predict class (categorical) labels, such as “safe” or “risky” for
the loan application data; “yes” or “no” for the marketing data; or “treatment A,”
“treatment B,” or “treatment C” for the medical data.
• These categories can be represented by discrete values, where the ordering among
values has no meaning.
• For example, the values 1, 2, and 3 may be used to represent treatments A, B, and C,
where there is no ordering implied among this group of treatment regimes.
6.1 Basic Concepts
• Suppose that the marketing manager wants to predict how much a given customer will
spend during a sale at AllElectronics.
• This data analysis task is an example of numeric prediction, where the model constructed
predicts a continuous-valued function, or ordered value, as opposed to a class label.
• This model is a predictor.
• Regression analysis is a statistical methodology that is most often used for numeric
prediction; hence the two terms tend to be used synonymously, although other methods
for numeric prediction exist. Classification and numeric prediction are the two major types
of prediction problems.
6.1 Basic Concepts
• Ranking is another type of numerical prediction where the model predicts the
ordered values (i.e., ranks), for example, a web search engine (e.g., Google) ranks
the relevant webpages with respect to a given query, with the higher-ranked
webpages being more relevant to the query.
• Classification and numeric prediction are the two major types of prediction
problems.
• It is worth pointing out that classification and numerical prediction (e.g.,
regression) are closely related to each other.
6.1.2 General Approach to Classification
6.1.2 General Approach to Classification
Supervised vs. Unsupervised Learning
6.1.2 General Approach to 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.
6.1.2 General Approach to Classification
• Likewise, we could use clustering techniques to find social media posts sharing similar topics without
knowing their actual class labels.
• The landscape of the prediction problem (e.g., classification, regression, ranking) has gone beyond
supervised vs. unsupervised learning.
• To name a few, in semisupervised classification, it builds a classifier based on a limited number of
labeled training tuples (whose true class labels are given during training) and a large number of
unlabeled training tuples (whose class labels are unknown during training); in zero-shot learning, some
class label might appear after the classification model has been built.
• In other words, during the training phase, there are no (i.e., zero) labeled training tuples for such a class
label.
6.1.2 General Approach to Classification
• Both semi supervised learning and zero-shot learning belong to weakly supervised learning in that the
supervision information for training the model is weaker than the standard supervised learning.
• For the classification task, this means that the supervision (i.e., the true class labels of training tuples) is
known only for a small fraction of the entire training set in semisupervised learning; or is absent for
certain class label(s) in zero-shot learning.
6.1.2 General Approach to Classification
• The accuracy of a classifier on a given test set is the percentage of test 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 Fig. 6.1(a) from the analysis of data from previous loan
applications can be used to approve or reject new or future loan applicants.
6.1.2 General Approach to Classification
6.2 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. Figure 6.2
• Some decision tree algorithms produce only binary trees (where each internal
node branches to exactly two other nodes), whereas others can produce
nonbinary trees.
• “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 tuple.
• Decision trees can easily be converted to classification rules.
6.2 Decision Tree Induction
• Decision tree induction algorithms have been used for classification in many application
areas such as medicine, manufacturing and production, financial analysis, astronomy,
and molecular biology.
• Decision trees are the basis of several commercial rule induction systems.
6.2.1 Decision Tree Induction
• During the late 1970s and early 1980s, J. Ross Quinlan, a researcher in machine learning, developed a
decision tree algorithm known as ID3 (Iterative Dichotomiser).
• This work expanded on earlier work on concept learning systems, described by E. B. Hunt, J. Marin, and P.
T. Stone.
• Quinlan later presented C4.5 (a successor of ID3), which became a benchmark to which newer supervised
learning algorithms are often compared.
• In 1984, a group of statisticians (L. Breiman, J. Friedman, R. Olshen, and C. Stone) published the book
Classification and Regression Trees (CART), which described the generation of binary decision trees.
• ID3 and CART were invented independently of one another at around the same time, yet follow a similar
approach for learning decision trees from training tuples.
• These two cornerstone algorithms spawned a flurry of work on decision tree induction.
6.2.1 Decision Tree Induction
If the tuples in D are all of the same class, then node N becomes a leaf and
is labeled with that class (steps 2 and 3). Note that steps 4 and 5 are
terminating conditions.
6.2.1 Decision Tree Induction
• Otherwise, the algorithm calls Attribute selection method to determine the splitting criterion.
• The splitting criterion tells us which attribute to test at node N by determining the “best” way to separate or
partition the tuples in D into individual classes (step 6).
• The splitting criterion also tells us which branches to grow from node N with respect to the outcomes of the
chosen test.
• More specifically, the splitting criterion indicates the splitting attribute and may also indicate either a
split-point or a splitting subset.
• The splitting criterion is determined so that, ideally, the resulting partitions at each branch are as “pure” as
possible.
• A partition is pure if all the tuples in it belong to the same class.
6.2.1 Decision Tree Induction
The node N is labeled with the splitting criterion, which serves as a test at the node (step 7). A branch is grown
from node N for each of the outcomes of the splitting criterion. The tuples in D are partitioned accordingly (steps
10 to 11).
8.2.1 Decision Tree Induction
6.2.1 Decision Tree Induction
• The algorithm uses the same process recursively to form a decision tree for the tuples at each resulting
partition, Dj , of D (step 14).
• The recursive partitioning stops only when any one of the following terminating conditions is true:
1. All the tuples in partition D (represented at node N) belong to the same class (steps 2 and 3).
2. There are no remaining attributes on which the tuples may be further partitioned (step 4).
In this case, majority voting is employed (step 5). This involves converting node N into a leaf and labeling
it with the most common class in D.
Alternatively, the class distribution of the node tuples may be stored.
3. There are no tuples for a given branch, that is, a partition Dj is empty (step 12).
In this case, a leaf is created with the majority class in D (step 13).
• The resulting decision tree is returned (step 15).
6.2.1 Decision Tree Induction
• The computational complexity of the algorithm given training set D is O(n × |D| × log(|D|)), where n is the
number of attributes describing the tuples in D and |D| is the number of training tuples in D.
• This means that the computational cost of growing a tree grows at most n × |D| × log(|D|) with |D| tuples.
• Incremental versions of decision tree induction have also been proposed.
• When given new training data, it restructures the decision tree acquired from learning on previous training
data rather than relearning a new tree from scratch.
• Differences in decision tree algorithms include how the attributes are selected in creating the tree and the
mechanisms used for pruning .
6.2.1 Decision Tree Induction
• Decision tree is closely related to another type of tree, called regression tree, which is used to predict the
continuous output value.
• A regression tree is very similar to a decision tree in that it also partitions the entire attribute space into multiple
subregions, each corresponding to a leaf node.
• The main difference is as follows.
• In a regression tree, a leaf node holds a continuous value instead of a categorical value (i.e., class label) in a
decision tree.
• The continuous value of a leaf node is learned during the training phase, which is set as the average output value
of all training tuples fallen in the corresponding subregions.
• CART uses residual sum of squares (RSS) as the objective function, which is the sum of the squared difference
between the actual and predicted output values of training tuples
6.2.1 Decision Tree Induction
• where yi is the actual output value of the ith training tuple, and is the predicted output by the regression tree.
• Choosing the average output of all training tuples in the corresponding subregion is optimal in that it minimizes
the RSS in Eq. (6.1).
• Each leaf node value is then used to predict the output of a test tuple which falls into it.
• Fig. 6.5 presents an example of a regression tree for predicting the average yearly income based on an
individual’s education (e.g., whether or not the individual attended the college, the average GPA at college, etc.).
FIGURE 6.5
6.2.2 Attribute selection measures
• An attribute selection measure is a heuristic for selecting the splitting criterion that “best” separates a
given data partition, D, of class-labeled training tuples into individual classes.
• If we were to split D into smaller partitions according to the outcomes of the splitting criterion, ideally,
each partition would be pure (i.e., all the tuples that fall into a given partition would belong to the same
class).
• Conceptually, the “best” splitting criterion is the one that most closely results in such a scenario.
• Attribute selection measures are also known as splitting rules because they determine how the tuples at a
given node are to be split.
Attribute selection measures
• The attribute selection measure provides a ranking for each attribute describing the given training tuples.
• The attribute having the best score for the measure is chosen as the splitting attribute for the given
tuples.
• If the splitting attribute is continuous-valued or if we are restricted to binary trees, then, respectively,
either a split point or a splitting subset must also be determined as part of the splitting criterion.
• The tree node created for partition D is labeled with the splitting criterion, branches are grown for each
outcome of the criterion, and the tuples are partitioned accordingly.
• This section describes three popular attribute selection measures—
• The notation used herein is as follows.
• information gain, • Let D, the data partition, be a training set of class-labeled tuples.
• Suppose the class label attribute has m distinct values defining m distinct classes,
• gain ratio, and Ci (for i =1,...,m).
• Gini impurity. • Let Ci,D be the set of tuples of class Ci in D.
• Let |D| and |Ci,D| denote the number of tuples in D and Ci,D, respectively.
Attribute selection measures
Information Gain
• Information gain ID3 uses information gain as its attribute selection measure.
• This measure is based on pioneering work by Claude Shannon on information theory, which studied the
value or “information content” of messages. Let node N represent or hold the tuples of partition D.
• The attribute with the highest information gain is chosen as the splitting attribute for node N.
• This attribute minimizes the information needed to classify the tuples in the resulting partitions and
reflects the least randomness or “impurity” in these partitions.
• Such an approach minimizes the expected number of tests needed to classify a given tuple and
guarantees that a simple (but not necessarily the simplest) tree is found.
• The expected information needed to classify a tuple in D is given by
Attribute selection measures
• where pi is the nonzero probability that an arbitrary tuple in D belongs to class Ci and is
estimated by |Ci,D|/|D|.
• A log function to the base 2 is used, because the information is encoded in bits.
• Info(D) is just the average amount of information needed to identify the class label of a tuple in
D.
• Note that, at this point, the information we have is based solely on the proportions of tuples of
each class.
• Info(D) is also known as the entropy of D.
Attribute selection measures
• Now, suppose we were to partition the tuples in D on some attribute A having v distinct values,
{a1,a2,...,av}, as observed from the training data.
• If A is discrete-valued, these values correspond directly to the v outcomes of a test on A.
• Attribute A can be used to split D into v partitions or subsets, {D1,D2,...,Dv}, where Dj contains those
tuples in D that have outcome aj of A. These partitions would correspond to the branches grown from
node N.
• Ideally, we would like this partitioning to produce an exact classification of the tuples.
• That is, we would like for each partition to be pure. However, it is quite likely that the partitions will be
impure (e.g., where a partition may contain a collection of tuples from different classes rather than
from a single class).
Attribute selection measures
• How much more information would we still need (after the partitioning) to arrive at an exact
classification? This amount is measured by
• There are nine tuples of class yes and five tuples of class no. A (root) node N is created for the tuples
in D.
• To find the splitting criterion for these tuples, we must compute the information gain of each
attribute.
• We first use Eq. (6.2) to compute the expected information needed to classify a tuple in D:
• Next, we need to compute the expected information requirement for each attribute.
• Let’s start with the attribute age.
• We need to look at the distribution of yes and no tuples for each category of age.
For the age category “youth” there are two yes tuples and three no tuples.
For the category “middle_aged,” there are four yes tuples and zero no tuples.
For the category “senior,” there are three yes tuples and two no tuples.
• Using Eq. (6.3), the expected information needed to classify a tuple in D if the tuples are partitioned
according to age is
Attribute selection measures
• “But how can we compute the information gain of an attribute that is continuous-valued, unlike in the
example?”
• Suppose, instead, that we have an attribute A that is continuous-valued rather than discrete-valued.
• (For example, suppose that instead of the discretized version of age from the example, we have the raw
values for this attribute.) For such a scenario, we must determine the “best” split-point for A, where the
split-point is a threshold on A.
• We first sort the values of A in the increasing order. Typically, the midpoint between each pair of
adjacent values is considered as a possible split-point. Therefore, given v values of A, (v − 1) possible
splits are evaluated. For example, the midpoint between the values ai and ai+1 of A is
Attribute selection measures
• If the values of A are sorted in advance, then determining the best split for A requires only one
pass through the values. For each possible split-point for A,
• we evaluate InfoA(D), where the number of partitions is two, that is, v = 2 (or j = 1, 2) in Eq.
(6.3). The point with the minimum expected information requirement for A is selected as the
split_point for A.
• 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
Attribute selection measures
Gain Ratio
• The information gain measure is biased toward tests with many outcomes.
• That is, it prefers to select attributes having a large number of values.
• For example, consider an attribute that acts as a unique identifier such as product ID.
• A split on product ID would result in a large number of partitions (as many as there are values), each one
containing just one tuple.
• Because each partition is pure, the information required to classify data set D based on this partitioning
would be Infoproduct ID(D) = 0. Therefore the information gained by partitioning on this attribute is
maximal. Clearly, such a partitioning is useless for classification.
Attribute selection measures
Gain Ratio
Gain Ratio
• This value represents the potential information generated by splitting the training data
set, D, into v partitions, corresponding to the v outcomes of a test on attribute A.
• Note that, for each outcome, it considers the number of tuples having that outcome with
respect to the total number of tuples in D.
• The gain ratio is defined as
• The attribute with the maximum gain ratio is selected as the splitting attribute.
• Note, however, that as the split information approaches 0, the ratio becomes unstable.
Attribute selection measures
• We exclude the power set, {low, medium, high}, and the empty set from
consideration since, conceptually, they do not represent a split.
• Therefore, there are 2v − 2 possible ways to form two partitions of the data, D,
based on a binary split on A.
• When considering a binary split, we compute a weighted sum of the impurity of
each resulting partition.
• For example, if a binary split on A partitions D into D 1 and D2, the Gini index of D
given that partitioning is
Gini Impurity
• The attribute that maximizes the reduction in impurity (or, equivalently, has the
minimum Gini index) is selected as the splitting attribute.
• This attribute and either its splitting subset (for a discrete-valued splitting
attribute) or split-point (for a continuous-valued splitting attribute) together
form the splitting criterion.
Gini Impurity
• To find the splitting criterion for the tuples in D, we need to compute the Gini impurity for each
attribute.
• Let’s start with the attribute income and consider each of the possible splitting subsets. Consider the
subset {low, medium}.
• Similarly, the Gini impurity values for splits on the remaining subsets are 0.458 (for the subsets {low,
high} and {medium}) and 0.450 (for the subsets {medium, high} and {low}).
• Therefore, the best binary split for attribute income is on {low, medium} (or {high}) because it
minimizes the Gini index.
• Evaluating age, we obtain {youth, senior} (or {middle_aged}) as the best split for age with a Gini
impurity of 0.375; the attributes student and credit_rating are both binary, with Gini impurity
values of 0.367 and 0.429, respectively.
• The attribute age and splitting subset {youth, senior} therefore give the minimum Gini impurity
overall, with a reduction in impurity of 0.459 − 0.357 = 0.102.
• The binary split “age ∈ {youth, senior?}” results in the maximum reduction in impurity of the tuples in
D and is returned as the splitting criterion.
• Node N is labeled with the criterion, two branches are grown from it, and the tuples are partitioned
accordingly.
Gini Impurity
• “So, what is the relationship between Gini impurity and information gain?”
• ” Intuitively, both measures aim to quantify to what extent the impurity will be reduced if we split the
current node based on the given attribute.
• Information gain, rooted in information theory, measures the impurity based on (the change of) the
average amount of information needed to identify the class label of a tuple.
• Gini impurity is related to mis-classification in the following way. Based on the class label distribution in
the current node, it tells how likely a randomly chosen tuple will be mis-classified if it is assigned to a
random class label.
• Gini impurity is always used for binary split, whereas information gain allows multiway split. In terms of
computation, Gini impurity is slightly more efficient than information gain, since the latter involves the
logarithm computation. In practice, however, both measures often lead to very similar decision trees.
Other attribute selection measures
• We have shown three measures that are commonly used for building decision trees.
• These measures are not without their biases.
• Information gain, as we saw, is biased toward multivalued attributes.
• Although the gain ratio adjusts for this bias, it tends to prefer unbalanced splits in which one partition is
much smaller than the others.
• The Gini impurity is biased toward multivalued attributes and has difficulty when the number of classes
is large.
• It also tends to favor tests that result in equal-size partitions and purity in both partitions.
• Although biased, these measures give reasonably good results in practice.
Other attribute selection measures
Example 6.4.
• Let us look at an example in Table 6.2 on how to use RSS to find the best split point.
• Suppose there are five training tuples at a regression tree node, and each training tuple has a true
output value yi and a continuous attribute xi(i = 1,..., 5).
• We want to find the best split point for attribute xi to split the tree node into two leaf nodes.
• More specifically, all the tuples whose xi is less than or equal to the split point will go to the left leaf
node, and the remaining training tuples will go to the right leaf node.
Other attribute selection measures
• Since xi is a continuous attribute with five possible values, there are four candidate split points, including x i = 1.5, xi
= 2.5, xi = 3.5 and xi = 4.5.
• For each candidate split point, we partition the current tree node into two leaf nodes.
• The average output value yl of the training tuples in the left leaf node is used to predict the output of all tuples
residing in the left leaf node.
• Likewise, the average output value yr of the training tuples in the right leaf node is used to predict the output of all
tuples residing in the right leaf node.
Other attribute selection measures
• For example, if the split point xi = 1.5, only the first training tuple goes to the left leaf node, and we have that y l = y1
= 10; and yr = (y2 + y3 + y4 + y5)/4 = (12 + 8 + 20 + 22)/4 = 15.5.
• Using the predicted output values for all five training tuples (yl or yr), we can use Eq. (6.1) to calculate RSS. Again, if
the split point xi = 1.5, we have that RSS = 5 i=1(yi − ˆyi)2 = (y1 − yl)2 + (y2 − yr)2 + (y3 − yr)2 + (y4 − yr)2 + (y5 − yr)2 =
122.25.
• The computation results for all four possible split points are summarized in Table 6.3. Since xi = 3.5 has the smallest
RSS, it is chosen as the split point.
Other attribute selection measures
• Attribute selection measures based on the Minimum Description Length (MDL) principle have the least bias
toward multivalued attributes.
• MDL-based measures use encoding techniques to define the “best” decision tree as the one that requires the
fewest number of bits to both
• encode the tree and
• encode the exceptions to the tree (i.e., cases that are not correctly classified by the tree). Its main idea is that the
simplest solution is preferred.
• The philosophy underlying the MLD principle is Occam’s razor, also known as law of parsimony.
• In data mining and machine learning, Occam’s razor is often translated into a design principle that one should
favor a model with a shorter description (hence minimum description length) for the data over a lengthier model,
provided that everything else is equal (e.g., both shorter and lengthier models share the same training set errors)
Other attribute selection measures
• The cost complexity pruning algorithm used in CART is an example of the postpruning
approach.
• This approach considers the cost complexity of a tree to be a function of the number of leaves in
the tree and the error rate of the tree (where the error rate is the percentage of tuples
misclassified by the tree). It starts from the bottom of the tree.
• For each internal node, N, it computes the cost complexity of the subtree at N, and the cost
complexity of the subtree at N if it were to be pruned (i.e., replaced by a leaf node). The two
values are compared.
• If pruning the subtree at node N would result in a smaller cost complexity, then the subtree is
pruned; otherwise, it is kept.
6.2.3 Tree pruning
• Rather than pruning trees based on estimated error rates, we can prune trees based on the number
of bits required to encode them.
• The “best” pruned tree is the one that minimizes the number of encoding bits.
• This method adopts the MDL [Link] basic idea is that the simplest solution is preferred.
• Unlike cost complexity pruning, it does not require an independent set of tuples (i.e., the pruning
set).
• Alternatively, prepruning and postpruning may be interleaved for a combined approach.
• Postpruning requires more computation than prepruning, yet generally leads to a more reliable tree.
• No single pruning method has been found to be superior over all others.
• Although some pruning methods do depend on the availability of additional data for pruning, this is
usually not a concern when dealing with large databases.
6.2.3 Tree pruning
• Although pruned trees tend to be more compact than their unpruned counterparts, they may still be rather large
and complex.
• Decision trees can suffer from repetition and replication (Fig. 6.8), making them overwhelming to interpret.
• Repetition occurs when an attribute is repeatedly tested along a given branch of the tree (e.g., “age < 60?,”
followed by “age < 45?,” and so on).
• In replication, duplicate subtrees exist within the tree.
• These situations can impede the accuracy and comprehensibility of a decision tree.
• The use of multivariate splits (splits based on a combination of attributes) can prevent these problems.
• Another approach is to use a different form of knowledge representation, such as rules, instead of decision trees.
which shows how a rule-based classifier can be constructed by extracting IF-THEN rules from a decision tree.
6.2.3 Tree pruning
6.2.3 Tree pruning
• Naive Bayesian classifiers assume that the effect of an attribute value on a given class is
independent of the values of the other attributes.
• This assumption is called class conditional independence.
• It is made to simplify the computations involved and, in this sense, is considered
“naive.”
6.3.1 Bayes’ Theorem
• Bayes’ theorem is named after Thomas Bayes, a nonconformist English clergyman who
did early work in probability and decision theory during the 18th century.
• Let X be a data tuple.
• In Bayesian terms, X is considered “evidence.”
• Let H be some hypothesis such as that the data tuple X belongs to a specified class C.
• For classification problems, we want to determine P(H|X), the probability that the
hypothesis H holds given the “evidence” or observed data tuple X.
• In other words, we are looking for the probability that tuple X belongs to class C, given
that we know the attribute description of X.
6.3.1 Bayes’ Theorem
• Therefore, the overall classification error of Bayes classifier, which is the expectation (i.e., the weighted
average) of the risk of all possible tuples, is the lowest in all possible classifiers.
• Given its theoretic optimality, Bayes classifier plays a foundational role in the statistical machine
learning community.
• For example, many classifiers (e.g., naïve Bayesian classifier, k-Nearest-Neighbor classifier, logistic
regression, Bayesian network, etc.) can be viewed as approximated Bayes classifiers.
• Bayes classifier is also useful in that it provides a theoretical justification for other classifiers that do
not explicitly use Bayes’ theorem.
• For example, under certain assumptions, it can be shown that many neural network and curve-fitting
algorithms output the maximum posteriori hypothesis, as does the Bayes classifier.
6.3.1 Bayes’ Theorem
The naïve Bayesian classifier, or simple Bayesian classifier, follows the same procedure as Bayes classifier,
except the way it estimates the conditional probabilities.
1. Let D be a training set of tuples and their associated class labels.
2. As usual, each tuple is represented by an n-dimensional attribute vector, X = (x1,x2,...,xn), depicting n
measurements made on the tuple from n attributes, respectively, A1,A2,...,An.
3. Suppose that there are m classes, C1,C2,...,Cm.
4. Given a tuple, X, the classifier will predict that X belongs to the class having the highest posterior
probability, conditioned on X.
5. That is, the naïve Bayesian classifier predicts that tuple X belongs to the class Ci if and only if
6.3.2 Naïve Bayesian classification
• As P(X) is constant for all classes, we only need to find out which class maximizes P(X|Ci)P(Ci).
• If the class prior probabilities are not known, then it is commonly assumed that the classes are equally
likely, that is, P(C1) = P(C2) =···= P(Cm), and we would therefore maximize P(X|Ci).
• Otherwise, we maximize P(X|Ci)P(Ci).
• Note that the class prior probabilities may be estimated by P(Ci) = |Ci,D|/|D|, where |Ci,D| is the number of
training tuples of class Ci in D.
6.3.2 Naïve Bayesian classification
• Given a data set with many attributes, it would be extremely computationally expensive to compute
P(X|Ci) for the aforementioned reasons.
• To reduce computation in evaluating P(X|Ci), the naïve assumption of class-conditional independence
is made.
• This presumes that the attributes’ values are conditionally independent of one another, given the class
label of the tuple (i.e., there are no dependence relationships among the attributes, if we know which
class the tuple belongs to.).
• Thus
6.3.2 Naïve Bayesian classification
• We can easily estimate the probabilities P(x1|Ci),P(x2|Ci),...,P(xn|Ci) from the training tuples.
• Recall that here xk refers to the value of attribute Ak for tuple X.
• For each attribute, we look at whether the attribute is categorical or continuous-valued.
• For instance, to compute P(X|Ci), we consider the following:
b. If Ak is continuous-valued, then we need to do a bit more work, but the calculation is pretty
straightforward.
A continuous-valued attribute is typically assumed to have a Gaussian distribution with a mean μ and
standard deviation σ, defined by
so that
We need to compute μCi and σCi , which are the mean (i.e., average) and standard deviation, respectively, of
the values of attribute Ak for training tuples of class Ci. We then plug these two quantities into Eq. (6.14),
together with xk, to estimate P(xk|Ci).
6.3.2 Naïve Bayesian classification
6.3.2 Naïve Bayesian classification
• To predict the class label of X, P(X|Ci)P(Ci) is evaluated for each class Ci.
• The classifier predicts that the class label of tuple X is the class Ci if and only if
In other words, the predicted class label is the class Ci for which P(X|Ci)P(Ci) is the maximum.
6.3.2 Naïve Bayesian classification
• Example 8.5
• Using the Laplacian correction to avoid computing probability values of zero.
• Suppose that for the class buys computer = yes in some training database, D, containing
1000 tuples, we have 0 tuples with income = low, 990 tuples with income = medium,
and 10 tuples with income = high.
• The probabilities of these events, without the Laplacian correction, are 0, 0.990 (from
990/1000), and 0.010 (from 10/1000), respectively.
6.3.2 Naïve Bayesian classification
Using the Laplacian correction for the three quantities, we pretend that we have 1 more
tuple for each income-value pair. In this way, we instead obtain the following probabilities
(rounded up to three decimal places):
respectively.
The “corrected” probability estimates are close to their “uncorrected” counterparts, yet the
zero probability value is avoided.