Download Classification and Prediction - Data Warehousing - Lecture Slide and more Slides Data Warehousing in PDF only on Docsity!
Classification and Prediction
Chapter 7. Classification and
Prediction
What is classification? What is prediction?
Issues regarding classification and prediction
Classification by decision tree induction
Bayesian Classification
Classification by backpropagation
Classification based on concepts from association rule mining
Other Classification Methods
Prediction
Classification accuracy
Summary
Classification—A Two-Step Process
Step 1 - Model construction
- describe a set of predetermined classes Each tuple/sample is assumed to belong to a predefined class, as determined by the class label attribute The set of tuples used for model construction is the training set The model is represented as classification rules, decision trees, or mathematical formulae
Step 2 - Model usage
- Estimate accuracy of the model The known label of test sample is compared with the classified result from the model Accuracy rate is the percentage of test set samples that are correctly classified by the model Test set is independent of training set
- Use model to classify future or unknown objects
Classification Process (1): Model
Construction
Training Data
N A M E R A N K Y E A R S T E N U R E D
M ike A ssistant P rof 3 no M ary A ssistant P rof 7 yes B ill P rofessor 2 yes Jim A ssociate P rof 7 yes D ave A ssistant P rof 6 no A nne A ssociate P rof 3 no
Classification Algorithms
IF rank = ‘professor’ OR years > 6 THEN tenured = ‘yes’
Classifier (Model)
Supervised vs. Unsupervised
Learning
Supervised learning (classification)
- Supervision: The training data (observations, measurements, etc.) are accompanied by labels indicating the class of the observations
- New data is classified based on the training set
Unsupervised learning (clustering)
- The class labels of training data is unknown
- Given a set of measurements, observations, etc. have the aim of establishing the existence of classes or clusters in the data
Issues regarding classification and
prediction (1): Data Preparation
Data cleaning
- Preprocess data in order to reduce noise (smoothing technique) handle missing values (most commonly occurring value)
Relevance analysis (feature selection)
- Remove the irrelevant or redundant attributes
Data transformation
- Generalize to higher level concepts
- Normalize data
Classification by Decision Tree
Induction
Decision tree
- A flow-chart-like tree structure
- Internal node denotes a test on an attribute
- Branch represents an outcome of the test
- Leaf nodes represent class labels or class distribution
Decision tree generation consists of two phases
- Tree construction At start, all the training examples are at the root Partition examples recursively based on selected attributes
- Tree pruning Identify and remove branches that reflect noise or outliers
Use of decision tree: Classifying an unknown sample
- Test the attribute values of the sample against the decision tree
Training Dataset
age income student credit_rating <=30 high no fair <=30 high no excellent 31…40 high no fair
40 medium no fair 40 low yes fair 40 low yes excellent 31…40 low yes excellent <=30 medium no fair <=30 low yes fair 40 medium yes fair <=30 medium yes excellent 31…40 medium no excellent 31…40 high yes fair 40 medium no excellent
buys_computer
no
no no
yes
yes
yes
yes
no
no
yes
yes
yes
yes
yes
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
Algorithm for Decision Tree
Induction (continued)
Basic algorithm (generate_decision_tree)
- Create a node N
- If samples 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 most common class in sample
- Select test-attribute, the attribute with highest info gain from attribute-list
- Label node N with test-attribute
- For each known value ai of test-attribute Grow a branch from node N for the condition test-attribute =ai Let si be the set of samples in samples for which test-attribute =ai If si is empty then - Attach a leaf labeled with the most common class in samples Else attach the node returned by generate_decision_tree(si, attribute-list )
Information Gain in Decision
Tree Induction
Assume that using attribute A, a set S will be
partitioned into sets { S 1 , S 2 , …, Sv }
- If Si contains pi examples of P and ni examples of N , the entropy, or the expected information needed to classify objects in all subtrees Si is
The encoding information that would be gained
by branching on A
n
1
i
i i
i i I p n p n
p n E A
Gain ( A ) I ( p , n ) E ( A )
Attribute Selection by Information
Gain Computation
Class P: buys_computer = ―yes‖ Class N: buys_computer = ―no‖ I(p, n) = I(9, 5) =0. Compute the entropy for age :
Hence
age p^ Similarly i ni I(pi, ni) <=30 2 3 0. 30…40 4 0 0
40 3 2 0.
( 3 , 2 ) 0. 69 14
5
( 4 , 0 ) 14
( 2 , 3 )^4 14
( )^5
I
E age I I
( _ ) 0. 048
Gain credit rating
Gain student
Gain income
Gain ( age ) I ( p , n ) E ( age )
Avoid Overfitting in Classification
The generated tree may overfit the training data
- Too many branches, some may reflect anomalies due to noise or outliers
- Result is in poor accuracy for unseen samples
Two approaches to avoid overfitting
- Prepruning: Halt tree construction early—do not split a node if this would result in the goodness measure falling below a threshold Difficult to choose an appropriate threshold
- Postpruning: Remove branches from a ―fully grown‖ tree—get a sequence of progressively pruned trees Use a set of data different from the training data to decide which is the ―best pruned tree‖
Enhancements to basic decision
tree induction
Allow for continuous-valued attributes
- Dynamically define new discrete-valued attributes that partition the continuous attribute value into a discrete set of intervals
Handle missing attribute values
- Assign the most common value of the attribute
- Assign probability to each of the possible values
Attribute construction
- Create new attributes based on existing ones that are sparsely represented
- This reduces fragmentation, repetition, and replication