Presentation is loading. Please wait.

Presentation is loading. Please wait.

Classification 1.

Similar presentations


Presentation on theme: "Classification 1."— Presentation transcript:

1 Classification 1

2 Classification – most familiar & most popular data mining technique.
Classification algorithms – statistical, decision tree, neural network, rules, etc. True positive: predicted, and actually in it False positive: predicted, but is not actually in it True negative: not predicted, and not actually in it False negative: not predicted, but is actually in it q 2

3 Classification vs. Prediction
q predicts categorical class labels (discrete or nominal) classifies data (constructs a model) based on the training set and the values (class labels) in a classifying attribute and uses it in classifying new data Prediction q models continuous-valued functions, i.e., predicts unknown or missing values Typical applications q Credit approval Target marketing Medical diagnosis Fraud detection 3 Han & Kamber

4 Classification—A Two-Step Process
Model construction: describing a set of predetermined classes q 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 training set The model is represented as classification rules, decision trees, or mathematical formulae Model usage: for classifying future or unknown objects q 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, otherwise over-fitting will occur If the accuracy is acceptable, use the model to classify data tuples whose class labels are not known 4 Han & Kamber

5 Process (1): Model Construction Classification
Algorithms Training Data Classifier (Model) IF rank = ‘professor’ OR years > 6 NAME RANK YEARS TENURED Mike Assistant Prof 3 no Mary 7 yes Bill Professor 2 Jim Associate Prof Dave 6 Anne THEN tenured = ‘yes’ Han & Kamber 5

6 Process (2): Using the Model in Prediction
Classifier Testing Data Unseen Data (Jeff, Professor, 4) Tenured? NAME RANK YEARS TENURED Tom Assistant Prof 2 no Merlisa Associate Prof 7 George Professor 5 yes Joseph 6 Han & Kamber

7 Supervised vs. Unsupervised Learning
Supervised learning (classification) q 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) q The class labels of training data is unknown Given a set of measurements, observations, etc. with the aim of establishing the existence of classes or clusters in the data 7 Han & Kamber

8 Issues: Data Preparation
Data cleaning q Preprocess data in order to reduce noise and handle missing values Relevance analysis (feature selection) q Remove the irrelevant or redundant attributes Data transformation q Generalize and/or normalize data 8 Han & Kamber

9 Issues: Evaluating Classification Methods
Accuracy q classifier accuracy: predicting class label predictor accuracy: guessing value of predicted attributes Speed q time to construct the model (training time) time to use the model (classification/prediction time) Robustness: handling noise and missing values Scalability: efficiency in disk-resident databases Interpretability q understanding and insight provided by the model Other measures, e.g., goodness of rules, such as decision tree size or compactness of classification rules q 9 Han & Kamber

10 Classification Performance
True Positive False Positive False Negative True Negative 10 Dunham

11 Confusion Matrix Predicted Class YES NO Actual Class TP FN FP TN 11

12 Accuracy = number of correct prediction s total number of predictions
= TP + TN TP + TN + FP + FN Error rate = number of wrong predictions = FN + FP Sensitivity = TP rate =TP / (TP + FP) Specificity = TN rate = TN / (TN + FN) q 12

13 This follows an example of Quinlan’s ID3 (Playing Tennis)
Decision Tree Induction: Training Dataset This follows an example of Quinlan’s ID3 (Playing Tennis) age income student credit_rating buys_computer <=30 high no fair excellent 31…40 yes >40 medium low ID3 : Iterative Dichotomizer 13 Han & Kamber

14 Output: A Decision Tree for “buys_computer” root
arc age? node <=30 student? 31..40 yes >40 credit rating? excellent no fair yes no yes no 14 Han & Kamber

15 Algorithm for Decision Tree Induction
Basic algorithm (a greedy algorithm) q 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 q 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 15 Han & Kamber

16 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| m m i i i = i = 1 log2 n is used because information is encoded in bits. If m=4, then the outcomes can be measured in bits as  1  log10 n  m  log10 2 Entropy: a measure of uncertainty in communication systems (Shannon, 1948) Expected information (entropy) needed to classify a tuple in D: Info( D) = − ∑ p log ( p ) = − ∑ | ci | log | ci | | D | | D | − log 2   = 2 log 2 n = D: Data Partition m: number of distinct classes 16 Han & Kamber

17 ∑ Information needed (after using A to split D into v
q partitions) to classify D: v | D j | j = 1 | D | InfoA ( D) = × I ( D j ); v ∈ A | D j | | D | = weightage of the jth partition Information gained by branching on attribute A Gain(A) = Info(D) − InfoA(D) q 17

18 Gain(credit _ rating ) = 0.048
Attribute Selection: Information Gain Class P: buys_computer = “yes” 5 14 4 14 Class N: buys_computer = “no” Infoage ( D) = I (2,3) + I (4,0) 9 14 9 14 5 14 5 14 5 14 Info( D) = I (9,5) = - log 2 ( ) - ) = 0.940 + I (3,2) = 0.694 log 2 ( age <=30 31…40 >40 pi 2 4 3 ni I(pi, ni) 5 14 out of 14 samples, with 2 yes’es and 3 no’s. Hence Gain(age) = Info( D) − Infoage ( D) = 0.246 I (2,3) means “age <=30” has 5 age income student credit_rating buys_computer <=30 high no fair excellent 31…40 yes >40 medium low Similarly, Gain(income) = 0.029 Gain(student ) = 0.151 Gain(credit _ rating ) = 0.048 18 Han & Kamber

19 Computing Information-Gain for Continuous-Value Attributes
Let attribute A be a continuous-valued attribute Must determine the best split point for A q 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: q 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 19 Han & Kamber

20 Gain Ratio for Attribute Selection (C4.5)
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 j = 1 | D | | D | q | D j | | D j | SplitInfo A ( D) = − ∑ × log 2 ( ) GainRatio(A) = Gain(A)/SplitInfo(A) 6 14 4 14 4 14 SplitInfo A ( D) = − × log 2 ( ) − × log 2 ( ) − × log 2 ( ) = 0.926 Ex. q gain_ratio(income) = 0.029/0.926 = 0.031 The attribute with the maximum gain ratio is selected as the splitting attribute q 20 Han & Kamber

21 Gini index (CART, IBM IntelligentMiner)
If a data set D contains examples from n classes, gini index, gini(D) is defined as n gini(D) = 1− ∑ p j j = 1 where pj is the relative frequency of class j in D If a data set D is split on A into two subsets D1 and D2, the gini ( D gini(D2) |D| |D| q 2 index gini(D) is defined asD) = |D1| gini( |D2 | ) + gini A ∆ gini( A) = gini(D) − giniA (D) Reduction in Impurity: q The attribute provides the smallest ginisplit(D) (or the largest q reduction in impurity) is chosen to split the node (need to enumerate all the possible splitting points for each attribute)Han & Kamber 21

22 Gini index (CART, IBM IntelligentMiner)
Ex. D has 9 tuples in buys_computer = “yes” and 5 in “no” gini( D) = 1 −   −   = 0.459  14   14  Suppose the attribute income partitions D into 10 in D1: {low, q  9   5  medium} and 4 in D giniincome∈ {low,medium}  10   4  ( D) =   Gini( D ) +   Gini( D )  14   14  but gini{medium,high} is 0.30 and thus the best since it is the lowest All attributes are assumed continuous-valued May need other tools, e.g., clustering, to get the possible split values q 22 Can be modified for categorical attributes q Han & Kamber

23 Naïve Bayesian Classifier: Training Dataset
age income studentcredit_ratingbuys_compu <=30 high no fair excellent no Class: C1:buys_computer = ‘yes’ C2:buys_computer = ‘no’ Data sample X = (age <=30, Income = medium, Student = yes Credit_rating = Fair) 31…40 >40 <=30 high medium low no yes fair excellent yes no >40 medium no excellent no 23

24 Naïve Bayesian Classifier: An Example
P(Ci): q P(buys_computer = “yes”) = 9/14 = 0.643 P(buys_computer = “no”) = 5/14= 0.357 Compute P(X|Ci) for each class P(age = “<=30” | buys_computer = “yes”) = 2/9 = 0.222 P(income = “medium” | buys_computer = “yes”) = 4/9 = 0.444 P(student = “yes” | buys_computer = “yes) = 6/9 = 0.667 P(credit_rating = “fair” | buys_computer = “yes”) = 6/9 = 0.667 P(age = “<= 30” | buys_computer = “no”) = 3/5 = 0.6 P(income = “medium” | buys_computer = “no”) = 2/5 = 0.4 P(student = “yes” | buys_computer = “no”) = 1/5 = 0.2 P(credit_rating = “fair” | buys_computer = “no”) = 2/5 = 0.4 X = (age <= 30 , income = medium, student = yes, credit_rating = fair) q P(X|Ci) : P(X|buys_computer = “yes”) = x x x = 0.044 P(X|buys_computer = “no”) = 0.6 x 0.4 x 0.2 x 0.4 = 0.019 P(X|Ci)*P(Ci) : P(X|buys_computer = “yes”) * P(buys_computer = “yes”) = 0.028 P(X|buys_computer = “no”) * P(buys_computer = “no”) = 0.007 Therefore, X belongs to class (“buys_computer = yes”) 24


Download ppt "Classification 1."

Similar presentations


Ads by Google