Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Data Mining Practical Machine Learning Tools and Techniques Slides for Chapter 6 of Data Mining by I. H. Witten, E. Frank and M. A. Hall Implementation: Real machine learning schemes β Decision trees β¦ β Classification rules β¦ β Frequent-pattern trees Extending linear models β¦ β From PRISM to RIPPER and PART (pruning, numeric data, β¦) Association Rules β¦ β From ID3 to C4.5 (pruning, numeric attributes, ...) Support vector machines and neural networks Instance-based learning β¦ Pruning examples, generalized exemplars, distance functions Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 2 Implementation: Real machine learning schemes β Numeric prediction β¦ β Bayesian networks β¦ β Hierarchical, incremental, probabilistic, Bayesian Semisupervised learning β¦ β Learning and prediction, fast data structures for learning Clustering: hierarchical, incremental, probabilistic β¦ β Regression/model trees, locally weighted regression Clustering for classification, co-training Multi-instance learning β¦ Converting to single-instance, upgrading learning algorithms, dedicated multi-instance methods Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 3 Industrial-strength algorithms β For an algorithm to be useful in a wide range of real-world applications it must: β¦ β¦ β¦ β¦ β Permit numeric attributes Allow missing values Be robust in the presence of noise Be able to approximate arbitrary concept descriptions (at least in principle) Basic schemes need to be extended to fulfill these requirements Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 4 Decision trees β Extending ID3: to permit numeric attributes: straightforward β to deal sensibly with missing values: trickier β stability for noisy data: requires pruning mechanism β β End result: C4.5 (Quinlan) Best-known and (probably) most widely-used learning algorithm β Commercial successor: C5.0 β Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 5 Numeric attributes β Standard method: binary splits β¦ β β Unlike nominal attributes, every attribute has many possible split points Solution is straightforward extension: β¦ β¦ β¦ β E.g. temp < 45 Evaluate info gain (or other measure) for every possible split point of attribute Choose βbestβ split point Info gain for best split point is info gain for attribute Computationally more demanding Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 6 Weather data (again!) Outlook Temperature Humidity Windy Play Sunny Hot High False No Sunny Hot High True No Overcast Hot High False Yes If If If If If Rainy Mild Normal High False Yes Rainy β¦ Cool β¦ Normal β¦ False β¦ Yes β¦ Rainy β¦ Cool β¦ Normal β¦ True β¦ No β¦ β¦ β¦ β¦ β¦ β¦ outlook = sunny and humidity = high then play = no outlook = rainy and windy = true then play = no outlook = overcast then play = yes humidity = normal then play = yes none of the above then play = yes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 7 Weather data (again!) Outlook Temperature Humidity Windy Play Sunny Hot High False No Sunny HotOutlook High Temperature True Humidity No Windy Play Overcast Hot Sunny High Hot 85 FalseHigh 85 Yes False No Rainy MildSunny 80 Normal HighHot 90 FalseHigh Yes True No Rainy β¦ Cool β¦Overcast Normal β¦ Hot 83 False β¦ High 86 Yes β¦ False Yes Rainy β¦ Cool β¦ Rainy Normal β¦ Mild 70 True β¦ Normal 96 No β¦ False Yes β¦ β¦ β¦ Rainy β¦ β¦ 68 β¦ 80 β¦ β¦ False β¦ Yes Rainy β¦ 65 β¦ 70 β¦ True β¦ No β¦ β¦ β¦ β¦ β¦ β¦ If If If If If β¦ outlook = sunny and humidity = high then play = no outlook = rainy and windy = true then play = no outlook = overcast then play = yes humidity = normal then play = yes none of the If above then = play = yes outlook sunny and humidity > 83 then play = no If outlook = rainy and windy = true then play = no If outlook = overcast then play = yes If humidity < 85 then play = no If none of the above then play = yes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 8 Example β Split on temperature attribute: 64 Yes β β 65 No 68 Yes 69 70 71 72 72 75 75 80 81 83 85 Yes Yes No No Yes Yes Yes No Yes Yes No β¦ E.g. temperature < 71.5: yes/4, no/2 temperature β₯ 71.5: yes/5, no/3 β¦ Info([4,2],[5,3]) = 6/14 info([4,2]) + 8/14 info([5,3]) = 0.939 bits Place split points halfway between values Can evaluate all split points in one pass! Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 9 Can avoid repeated sorting β Sort instances by the values of the numeric attribute β¦ β β Time complexity for sorting: O (n log n) Does this have to be repeated at each node of the tree? No! Sort order for children can be derived from sort order for parent β¦ β¦ Time complexity of derivation: O (n) Drawback: need to create and store an array of sorted indices for each numeric attribute Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 10 Binary vs multiway splits β Splitting (multi-way) on a nominal attribute exhausts all information in that attribute β¦ β Not so for binary splits on numeric attributes! β¦ β β Nominal attribute is tested (at most) once on any path in the tree Numeric attribute may be tested several times along a path in the tree Disadvantage: tree is hard to read Remedy: β¦ β¦ pre-discretize numeric attributes, or use multi-way splits instead of binary ones Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 11 Computing multi-way splits β β β Simple and efficient way of generating multi-way splits: greedy algorithm Dynamic programming can find optimum multiway split in O (n2) time β¦ imp (k, i, j ) is the impurity of the best split of values xi β¦ xj into k sub-intervals β¦ imp (k, 1, i ) = min0<j <i imp (kβ1, 1, j ) + imp (1, j+1, i ) β¦ imp (k, 1, N ) gives us the best k-way split In practice, greedy algorithm works as well Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 12 Missing values β Split instances with missing values into pieces β¦ β¦ β Info gain works with fractional instances β¦ β A piece going down a branch receives a weight proportional to the popularity of the branch weights sum to 1 use sums of weights instead of counts During classification, split the instance into pieces in the same way β¦ Merge probability distribution using weights Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 13 Pruning Prevent overfitting to noise in the data β βPruneβ the decision tree β Two strategies: β Postpruning take a fully-grown decision tree and discard unreliable parts β Prepruning stop growing a branch when information becomes unreliable β β Postpruning preferred in practiceβ prepruning can βstop earlyβ Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 14 Prepruning β Based on statistical significance test β¦ β β Stop growing the tree when there is no statistically significant association between any attribute and the class at a particular node Most popular test: chi-squared test ID3 used chi-squared test in addition to information gain β¦ Only statistically significant attributes were allowed to be selected by information gain procedure Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 15 Early stopping β β β β a b class 1 0 0 0 2 0 1 1 3 1 0 1 1 1 0 4 Pre-pruning may stop the growth process prematurely: early stopping Classic example: XOR/Parity-problem β¦ No individual attribute exhibits any significant association to the class β¦ Structure is only visible in fully expanded tree β¦ Prepruning wonβt expand the root node But: XOR-type problems rare in practice And: prepruning faster than postpruning Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 16 Postpruning First, build full tree β Then, prune it β β Fully-grown tree shows all attribute interactions Problem: some subtrees might be due to chance effects β Two pruning operations: β β β β Subtree replacement Subtree raising Possible strategies: β β β error estimation significance testing MDL principle Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 17 Subtree replacement β β Bottom-up Consider replacing a tree only after considering all its subtrees Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 18 Subtree raising β β β Delete node Redistribute instances Slower than subtree replacement (Worthwhile?) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 19 Estimating error rates β β Prune only if it does not increase the estimated error Error on the training data is NOT a useful estimator (would result in almost no pruning) β β Use hold-out set for pruning (βreduced-error pruningβ) C4.5βs method β¦ β¦ β¦ β¦ Derive confidence interval from training data Use a heuristic limit, derived from this, for pruning Standard Bernoulli-process-based method Shaky statistical assumptions (based on training data) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 20 C4.5βs method β β Error estimate for subtree is weighted sum of error estimates for all its leaves Error estimate for a node: e=ξf ξ β β β z2 2N ξz ξ f N f2 N β ξ z2 4N2 z2 N ξ/ξ1ξ ξ If c = 25% then z = 0.69 (from normal distribution) f is the error on the training data N is the number of instances covered by the leaf Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 21 Example f = 5/14 e = 0.46 e < 0.51 so prune! f=0.33 e=0.47 f=0.5 e=0.72 f=0.33 e=0.47 Combined using ratios 6:2:6 gives 0.51 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 22 Complexity of tree induction β Assume β β β m attributes n training instances tree depth O (log n) Building a tree β Subtree replacement β Subtree raising β β β β O (m n log n) O (n) O (n (log n)2) Every instance may have to be redistributed at every node between its leaf and the root Cost for redistribution (on average): O (log n) Total cost: O (m n log n) + O (n (log n)2) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 23 From trees to rules Simple way: one rule for each leaf β C4.5rules: greedily prune conditions from each rule if this reduces its estimated error β β β β Can produce duplicate rules Check for this at the end Then β β β look at each class in turn consider the rules for that class find a βgoodβ subset (guided by MDL) Then rank the subsets to avoid conflicts β Finally, remove rules (greedily) if this decreases error on the training data β Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 24 C4.5: choices and options β β C4.5rules slow for large and noisy datasets Commercial version C5.0rules uses a different technique β¦ β Much faster and a bit more accurate C4.5 has two parameters β¦ β¦ Confidence value (default 25%): lower values incur heavier pruning Minimum number of instances in the two most popular branches (default 2) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 25 Cost-complexity pruning β C4.5's postpruning often does not prune enough β¦ β¦ β Tree size continues to grow when more instances are added even if performance on independent data does not improve Very fast and popular in practice Can be worthwhile in some cases to strive for a more compact tree β¦ β¦ At the expense of more computational effort Cost-complexity pruning method from the CART (Classification and Regression Trees) learning system Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 26 Cost-complexity pruning β Basic idea: β¦ β¦ β¦ First prune subtrees that, relative to their size, lead to the smallest increase in error on the training data Increase in error (Ξ±) β average error increase per leaf of subtree Pruning generates a sequence of successively smaller trees β β¦ Each candidate tree in the sequence corresponds to one particular threshold value, Ξ±i Which tree to chose as the final model? β Use either a hold-out set or cross-validation to estimate the error of each Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 27 Discussion TDIDT: Top-Down Induction of Decision Trees β β β β β The most extensively studied method of machine learning used in data mining Different criteria for attribute/test selection rarely make a large difference Different pruning methods mainly change the size of the resulting pruned tree C4.5 builds univariate decision trees Some TDITDT systems can build multivariate trees (e.g. CART) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 28 Classification rules β β Common procedure: separate-and-conquer Differences: β¦ β¦ β¦ β¦ β¦ β Search method (e.g. greedy, beam search, ...) Test selection criteria (e.g. accuracy, ...) Pruning method (e.g. MDL, hold-out set, ...) Stopping criterion (e.g. minimum accuracy) Post-processing step Also: Decision list vs. one rule set for each class Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 29 Test selection criteria β Basic covering algorithm: β¦ β¦ β Measure 1: p/t β¦ β¦ β¦ β t total instances covered by rule p number of these that are positive Produce rules that donβt cover negative instances, as quickly as possible May produce rules with very small coverage βspecial cases or noise? Measure 2: Information gain p (log(p/t) β log(P/T)) β¦ β¦ β keep adding conditions to a rule to improve its accuracy Add the condition that improves accuracy the most P and T the positive and total numbers before the new condition was added Information gain emphasizes positive rather than negative instances These interact with the pruning mechanism used Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 30 Missing values, numeric attributes β Common treatment of missing values: for any test, they fail β¦ Algorithm must either β β β β use other tests to separate out positive instances leave them uncovered until later in the process In some cases itβs better to treat βmissingβ as a separate value Numeric attributes are treated just like they are in decision trees Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 31 Pruning rules β Two main strategies: β¦ β¦ β Other difference: pruning criterion β¦ β¦ β¦ β Incremental pruning Global pruning Error on hold-out set (reduced-error pruning) Statistical significance MDL principle Also: post-pruning vs. pre-pruning Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 32 Using a pruning set β For statistical validity, must evaluate measure on data not used for training: β¦ β β Reduced-error pruning : build full rule set and then prune it Incremental reduced-error pruning : simplify each rule as soon as it is built β¦ β This requires a growing set and a pruning set Can re-split data after rule has been pruned Stratification advantageous Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 33 Incremental reduced-error pruning Initialize E to the instance set Until E is empty do Split E into Grow and Prune in the ratio 2:1 For each class C for which Grow contains an instance Use basic covering algorithm to create best perfect rule for C Calculate w(R): worth of rule on Prune and w(R-): worth of rule with final condition omitted If w(R-) > w(R), prune rule and repeat previous step From the rules for the different classes, select the one thatβs worth most (i.e. with largest w(R)) Print the rule Remove the instances covered by rule from E Continue Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 34 Measures used in IREP β [p + (N β n)] / T β¦ β¦ (N is total number of negatives) Counterintuitive: β β Success rate p / t β¦ β Problem: p = 1 and t = 1 vs. p = 1000 and t = 1001 (p β n) / t β¦ β p = 2000 and n = 1000 vs. p = 1000 and n = 1 Same effect as success rate because it equals 2p/t β 1 Seems hard to find a simple measure of a ruleβs worth that corresponds with intuition Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 35 Variations β Generating rules for classes in order β¦ β¦ β Stopping criterion β¦ β Start with the smallest class Leave the largest class covered by the default rule Stop rule production if accuracy becomes too low Rule learner RIPPER: β¦ β¦ Uses MDL-based stopping criterion Employs post-processing step to modify rules guided by MDL criterion Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 36 Using global optimization β β β β β β RIPPER: Repeated Incremental Pruning to Produce Error Reduction (does global optimization in an efficient way) Classes are processed in order of increasing size Initial rule set for each class is generated using IREP An MDL-based stopping condition is used β¦ DL: bits needs to send examples wrt set of rules, bits needed to send k tests, and bits for k Once a rule set has been produced for each class, each rule is reconsidered and two variants are produced β¦ One is an extended version, one is grown from scratch β¦ Chooses among three candidates according to DL Final clean-up step greedily deletes rules to minimize DL Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 37 PART β β β Avoids global optimization step used in C4.5rules and RIPPER Generates an unrestricted decision list using basic separate-and-conquer procedure Builds a partial decision tree to obtain a rule β¦ β¦ β A rule is only pruned if all its implications are known Prevents hasty generalization Uses C4.5βs procedures to build a tree Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 38 Building a partial tree Expand-subset (S): Choose test T and use it to split set of examples into subsets Sort subsets into increasing order of average entropy while there is a subset X not yet been expanded AND all subsets expanded so far are leaves expand-subset(X) if all subsets expanded are leaves AND estimated error for subtree β₯ estimated error for node undo expansion into subsets and make node a leaf Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 39 Example Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 40 Notes on PART β β Make leaf with maximum coverage into a rule Treat missing values just as C4.5 does β¦ β I.e. split instance into pieces Time taken to generate a rule: β¦ Worst case: same as for building a pruned tree β β¦ Occurs when data is noisy Best case: same as for building a single rule β Occurs when data is noise free Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 41 Rules with exceptions 1.Given: a way of generating a single good rule 2.Then itβs easy to generate rules with exceptions 3.Select default class for top-level rule 4.Generate a good rule for one of the remaining classes 5.Apply this method recursively to the two subsets produced by the rule (I.e. instances that are covered/not covered) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 42 Iris data example Exceptions are represented as Dotted paths, alternatives as solid ones. Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 43 Association rules β Apriori algorithm finds frequent item sets via a generate-and-test methodology β¦ β¦ β¦ β β Successively longer item sets are formed from shorter ones Each different size of candidate item set requires a full scan of the data Combinatorial nature of generation process is costly β particularly if there are many item sets, or item sets are large Appropriate data structures can help FP-growth employs an extended prefix tree (FP-tree) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 44 FP-growth β β β FP-growth uses a Frequent Pattern Tree (FPtree) to store a compressed version of the data Only two passes are required to map the data into an FP-tree The tree is then processed recursively to βgrowβ large item sets directly β¦ Avoids generating and testing candidate item sets against the entire database Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 45 Building a frequent pattern tree 1) First pass over the data β count the number times individual items occur 2) Second pass over the data β before inserting each instance into the FP-tree, sort its items in descending order of their frequency of occurrence, as found in step 1 ξ ξ Individual items that do not meet the minimum support are not inserted into the tree Hopefully many instances will share items that occur frequently individually, resulting in a high degree of compression close to the root of the tree Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 46 An example using the weather data β Frequency of individual items (minimum support = 6) play = yes windy = false humidity = normal humidity = high windy = true temperature = mild play = no outlook = sunny outlook = rainy temperature = hot temperature = cool outlook = overcast 9 8 7 7 6 6 5 5 5 4 4 4 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 47 An example using the weather data β Instances with items sorted 1 windy=false, humidity=high, play=no, outlook=sunny, temperature=hot 2 humidity=high, windy=true, play=no, outlook=sunny, temperature=hot 3 play=yes, windy=false, humidity=high, temperature=hot, outlook=overcast 4 play=yes, windy=false, humidity=high, temperature=mild, outlook=rainy . . . 14 humidity=high, windy=true, temperature=mild, play=no, outlook=rainy β Final answer: six single-item sets (previous slide) plus two multiple-item sets that meet minimum support play=yes and windy=false play=yes and humidity=normal 6 6 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 48 Finding large item sets β β FP-tree for the weather data (min support 6) Process header table from bottom β¦ β¦ Add temperature=mild to the list of large item sets Are there any item sets containing temperature=mild that meet min support? Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 49 Finding large item sets cont. β β β FP-tree for the data conditioned on temperature=mild Created by scanning the first (original) tree β¦ Follow temperature=mild link from header table to find all instances that contain temperature=mild β¦ Project counts from original tree Header table shows that temperature=mild can't be grown any longer Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 50 Finding large item sets cont. β β β FP-tree for the data conditioned on humidity=normal Created by scanning the first (original) tree β¦ Follow humidity=normal link from header table to find all instances that contain humidity=normal β¦ Project counts from original tree Header table shows that humidty=normal can be grown to include play=yes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 51 Finding large item sets cont. β β β β All large item sets have now been found However, in order to be sure it is necessary to process the entire header link table from the original tree Association rules are formed from large item sets in the same way as for Apriori FP-growth can be up to an order of magnitude faster than Apriori for finding large item sets Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 52 Extending linear classification β β Linear classifiers canβt model nonlinear class boundaries Simple trick: β¦ β¦ β Map attributes into new space consisting of combinations of attribute values E.g.: all products of n factors that can be constructed from the attributes Example with two attributes and n = 3: x=w1 a31ξw2 a21 a2ξw3 a1 a22ξw 4 a 32 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 53 Problems with this approach β 1st problem: speed β¦ β¦ β¦ β 10 attributes, and n = 5 β >2000 coefficients Use linear regression with attribute selection Run time is cubic in number of attributes 2nd problem: overfitting β¦ β¦ Number of coefficients is large relative to the number of training instances Curse of dimensionality kicks in Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 54 Support vector machines β β Support vector machines are algorithms for learning linear classifiers Resilient to overfitting because they learn a particular linear decision boundary: β¦ β The maximum margin hyperplane Fast in the nonlinear case β¦ β¦ Use a mathematical trick to avoid creating βpseudoattributesβ The nonlinear space is created implicitly Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 55 The maximum margin hyperplane β The instances closest to the maximum margin hyperplane are called support vectors Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 56 Support vectors The support vectors define the maximum margin hyperplane β β All other instances can be deleted without changing its position and orientation β This means the hyperplane can be written as x=w0ξw1 a1ξw2 a2 ξ ξiξβ a ξ x=bξβi is supp. vector ξ· i y i a Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 57 Finding support vectors ξ ξiξβ a ξ x=bξβi is supp. vector ξ· i y i a β β Support vector: training instance for which Ξ±i > 0 Determine Ξ±i and b ?β A constrained quadratic optimization problem β¦ β¦ β¦ β Off-the-shelf tools for solving these problems However, special-purpose algorithms are faster Example: Plattβs sequential minimal optimization algorithm (implemented in WEKA) Note: all this assumes separable data! Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 58 Nonlinear SVMs β β βPseudo attributesβ represent attribute combinations Overfitting not a problem because the maximum margin hyperplane is stable β¦ β There are usually few support vectors relative to the size of the training set Computation time still an issue β¦ Each time the dot product is computed, all the βpseudo attributesβ must be included Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 59 A mathematical trick β β β Avoid computing the βpseudo attributesβ Compute the dot product before doing the nonlinear mapping Example: ξ ξiξβ a ξ ξn x=bξβi is supp. vector ξ· i y i ξ a β Corresponds to a map into the instance space spanned by all products of n attributes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 60 Other kernel functions β β Mapping is called a βkernel functionβ Polynomial kernel ξ ξiξβ a ξ ξn x=bξβi is supp. vector ξ· i y i ξ a β β β We can use others: Only requirement: Examples: ξ ξiξβ a ξξ x=bξβi is supp. vector ξ· i y i K ξ a K ξ xξi , xξj ξ=ξξ xξi ξβ ξξ xξj ξ K ξ xξi , xξ j ξ=ξ xξiβ xξ jξ1ξd K ξ xξi , xξ j ξ=expξ βξ xξi β xξj ξ2 2ξ 2 ξ K ξ xξi , xξ j ξ=tanh ξξΈ xξiβ xξ j ξbξ * Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 61 Noise β β β Have assumed that the data is separable (in original or transformed space) Can apply SVMs to noisy data by introducing a βnoiseβ parameter C C bounds the influence of any one training instance on the decision boundary β¦ β β Corresponding constraint: 0 β€ Ξ±i β€ C Still a quadratic optimization problem Have to determine C by experimentation Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 62 Sparse data SVM algorithms speed up dramatically if the data is sparse (i.e. many values are 0) β Why? Because they compute lots and lots of dot products β β Sparse data β compute dot products very efficiently β β Iterate only over non-zero values SVMs can process sparse datasets with 10,000s of attributes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 63 Applications β Machine vision: e.g face identification β β Outperforms alternative approaches (1.5% error) Handwritten digit recognition: USPS data β Comparable to best alternative (0.8% error) Bioinformatics: e.g. prediction of protein secondary structure β Text classifiation β Can modify SVM technique for numeric prediction problems β Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 64 Support vector regression β β β Maximum margin hyperplane only applies to classification However, idea of support vectors and kernel functions can be used for regression Basic method same as in linear regression: want to minimize error β¦ β¦ β Difference A: ignore errors smaller than Ξ΅ and use absolute error instead of squared error Difference B: simultaneously aim to maximize flatness of function User-specified parameter Ξ΅ defines βtubeβ Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 65 More on SVM regression β If there are tubes that enclose all the training points, the flattest of them is used β¦ β Model can be written as: β¦ β¦ β¦ β Eg.: mean is used if 2Ξ΅ > range of target values ξ ξiξβ a ξ x=bξβi is supp. vector ξ· i a Support vectors: points on or outside tube Dot product can be replaced by kernel function Note: coefficients Ξ±imay be negative No tube that encloses all training points? β¦ β¦ Requires trade-off between error and flatness Controlled by upper limit C on absolute value of coefficients Ξ±i Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 66 Examples Ξ΅=2 Ξ΅=1 Ξ΅ = 0.5 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 67 Kernel Ridge Regression β For classic linear regression using squared loss, only simple matrix operations are need to find the model β¦ β Not the case for support vector regression with user-specified loss Ξ΅ Combine the power of the kernel trick with simplicity of standard least-squares regression? β¦ Yes! Kernel ridge regression Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 68 Kernel Ridge Regression β β Like SVM, predicted class value for a test instance a is expressed as a weighted sum over the dot product of the test instance with training instances Unlike SVM, all training instances participate β not just support vectors β¦ β β No sparseness in solution (no support vectors) Does not ignore errors smaller than Ξ΅ Uses squared error instead of absolute error Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 69 Kernel Ridge Regression β More computationally expensive than standard linear regresion when #instances > #attributes β¦ β¦ β Standard regression β invert an m × m matrix (O(m3)), m = #attributes Kernel ridge regression β invert an n × n matrix (O(n3)), n = #instances Has an advantage if β¦ β¦ A non-linear fit is desired There are more attributes than training instances Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 70 The kernel perceptron β β β β β Can use βkernel trickβ to make non-linear classifier using perceptron rule Observation: weight vector is modified by adding or subtracting training instances Can represent weight vector using all instances that have been misclassified: β¦ Can use βi β j y ξ jξa'ξ jξi ai instead of βi w i a i ( where y is either -1 or +1) Now swap summation signs: β j y ξ jξβi a 'ξ jξi a i β¦ Can be expressed as: ξ 'ξ jξβ a ξ β j y ξ jξ a Can replace dot product by kernel: ξ 'ξ jξ , a ξξ β y ξ jξK ξ a j Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 71 Comments on kernel perceptron β Finds separating hyperplane in space created by kernel function (if it exists) β¦ β β Easy to implement, supports incremental learning Linear and logistic regression can also be upgraded using the kernel trick β¦ β But: doesn't find maximum-margin hyperplane But: solution is not βsparseβ: every training instance contributes to solution Perceptron can be made more stable by using all weight vectors encountered during learning, not just last one (voted perceptron) β¦ Weight vectors vote on prediction (vote based on number of successful classifications since inception) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 72 Multilayer perceptrons β β β β β Using kernels is only one way to build nonlinear classifier based on perceptrons Can create network of perceptrons to approximate arbitrary target concepts Multilayer perceptron is an example of an artificial neural network β¦ Consists of: input layer, hidden layer(s), and output layer Structure of MLP is usually found by experimentation Parameters can be found using backpropagation Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 73 Examples Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 74 Backpropagation β How to learn weights given network structure? β¦ β¦ β¦ Cannot simply use perceptron learning rule because we have hidden layer(s) Function we are trying to minimize: error Can use a general function minimization technique called gradient descent β Need differentiable activation function: use sigmoid function instead of threshold function f ξxξ= 1ξexp1 ξβx ξ β Need differentiable error function: can't use zero-one loss, but can use squared error E= 12 ξyβf ξxξξ2 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 75 The two activation functions Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 76 Gradient descent example β β β β Function: x2+1 Derivative: 2x Learning rate: 0.1 Start value: 4 Can only find a local minimum! Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 77 Minimizing the error I β Need to find partial derivative of error function for each parameter (i.e. weight) dE dw i =ξyβf ξxξξ dfdwξxξ i df ξx ξ dx =f ξx ξξ1βf ξxξξ x=βi w i f ξx i ξ df ξx ξ dw i dE dw i =f 'ξx ξf ξx i ξ =ξyβf ξxξξf 'ξxξ f ξx i ξ Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 78 Minimizing the error II β dE dw ij What about the weights for the connections from the input to the hidden layer? dx dx = dE =ξyβf ξxξξf 'ξxξ dx dw dw ij ij x=βi w i f ξx i ξ dx dw ij =w i df ξx i ξ dw ij dE dw ij df ξ xi ξ dwij dx i =f 'ξx i ξ dw =f 'ξx i ξa i ij =ξ yβf ξx ξξf 'ξxξ w i f 'ξx i ξa i Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 79 Remarks β β Same process works for multiple hidden layers and multiple output units (eg. for multiple classes) Can update weights after all training instances have been processed or incrementally: β¦ β¦ β How to avoid overfitting? β¦ β¦ β batch learning vs. stochastic backpropagation Weights are initialized to small random values Early stopping: use validation set to check when to stop Weight decay: add penalty term to error function How to speed up learning? β¦ Momentum: re-use proportion of old weight change β¦ Use optimization method that employs 2nd derivative Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 80 Radial basis function networks β β Another type of feedforward network with two layers (plus the input layer) Hidden units represent points in instance space and activation depends on distance β¦ To this end, distance is converted into similarity: Gaussian activation function β β¦ β Width may be different for each hidden unit Points of equal activation form hypersphere (or hyperellipsoid) as opposed to hyperplane Output layer same as in MLP Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 81 Learning RBF networks β β Parameters: centers and widths of the RBFs + weights in output layer Can learn two sets of parameters independently and still get accurate models β¦ β¦ β¦ β β Eg.: clusters from k-means can be used to form basis functions Linear model can be used based on fixed RBFs Makes learning RBFs very efficient Disadvantage: no built-in attribute weighting based on relevance RBF networks are related to RBF SVMs Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 82 Stochastic gradient descent β β Have seen gradient descent + stochastic backpropagation for learning weights in a neural network Gradient descent is a general-purpose optimization technique β¦ β¦ Can be applied whenever the objective function is differentiable Actually, can be used even when the objective function is not completely differentiable! β β Subgradients One application: learn linear models β e.g. linear SVMs or logistic regression Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 83 Stochastic gradient descent cont. β Learning linear models using gradient descent is easier than optimizing non-linear NN β¦ β Objective function has global minimum rather than many local minima Stochastic gradient descent is fast, uses little memory and is suitable for incremental online learning Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 84 Stochastic gradient descent cont. β For SVMs, the error function (to be minimized) is called the hinge loss Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 85 Stochastic gradient descent cont. β In the linearly separable case, the hinge loss is 0 for a function that successfully separates the data β¦ β The maximum margin hyperplane is given by the smallest weight vector that achieves 0 hinge loss Hinge loss is not differentiable at z = 1; cant compute gradient! β¦ β¦ β¦ Subgradient β something that resembles a gradient Use 0 at z = 1 In fact, loss is 0 for z β₯ 1, so can focus on z < 1 and proceed as usual Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 86 Instance-based learning β Practical problems of 1-NN scheme: β¦ Slow (but: fast tree-based approaches exist) β β¦ Noise (but: k -NN copes quite well with noise) β β¦ Remedy: remove noisy instances All attributes deemed equally important β β¦ Remedy: remove irrelevant data Remedy: weight attributes (or simply select) Doesnβt perform explicit generalization β Remedy: rule-based NN approach Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 87 Learning prototypes β β β Only those instances involved in a decision need to be stored Noisy instances should be filtered out Idea: only use prototypical examples Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 88 Speed up, combat noise β IB2: save memory, speed up classification β¦ β¦ β¦ β Work incrementally Only incorporate misclassified instances Problem: noisy data gets incorporated IB3: deal with noise β¦ β¦ Discard instances that donβt perform well Compute confidence intervals for β β β¦ 1. Each instanceβs success rate 2. Default accuracy of its class Accept/reject instances β β Accept if lower limit of 1 exceeds upper limit of 2 Reject if upper limit of 1 is below lower limit of 2 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 89 Weight attributes β IB4: weight each attribute (weights can be class-specific) β Weighted Euclidean distance: ξξw β 2 1 ξx 1βy 1ξ2ξ...ξw 2n ξx n βy n ξ2 ξ Update weights based on nearest neighbor β β β Class correct: increase weight Class incorrect: decrease weight Amount of change for i th attribute depends on |xi- yi| Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 90 Rectangular generalizations β β β Nearest-neighbor rule is used outside rectangles Rectangles are rules! (But they can be more conservative than βnormalβ rules.) Nested rectangles are rules with exceptions Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 91 Generalized exemplars β Generalize instances into hyperrectangles β¦ β¦ β Online: incrementally modify rectangles Offline version: seek small set of rectangles that cover the instances Important design decisions: β¦ Allow overlapping rectangles? β β¦ β¦ Requires conflict resolution Allow nested rectangles? Dealing with uncovered instances? Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 92 Separating generalized exemplars Class 1 Class 2 Separation line Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 93 Generalized distance functions Given: some transformation operations on attributes β K*: similarity = probability of transforming instance A into B by chance β β β Average over all transformation paths Weight paths according their probability (need way of measuring this) Uniform way of dealing with different attribute types β Easily generalized to give distance between sets of instances β Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 94 Numeric prediction β Counterparts exist for all schemes previously discussed β¦ β Decision trees, rule learners, SVMs, etc. (Almost) all classification schemes can be applied to regression problems using discretization β¦ β¦ β¦ Discretize the class into intervals Predict weighted average of interval midpoints Weight according to class probabilities Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 95 Regression trees β Like decision trees, but: β¦ β¦ β¦ β¦ β β β Splitting criterion: variation Termination criterion: Pruning criterion: measure Prediction: class values of instances minimize intra-subset std dev becomes small based on numeric error Leaf predicts average Piecewise constant functions Easy to interpret More sophisticated version: model trees Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 96 Model trees β β β Build a regression tree Each leaf β linear regression function Smoothing: factor in ancestorβs predictions β¦ β¦ β β Need linear regression function at each node At each node, use only a subset of attributes β¦ β¦ β Smoothing formula: p'= npξkq nξk Same effect can be achieved by incorporating ancestor models into the leaves Those occurring in subtree (+maybe those occurring in path to the root) Fast: tree usually uses only a small subset of the attributes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 97 Building the tree β Splitting: standard deviation reduction Ti β SDR=sd ξTξββi β£ T β£×sdξT i ξ Termination: β¦ β¦ Standard deviation < 5% of its value on full training set Too few instances remain (e.g. < 4) Pruning: β¦ Heuristic estimate of absolute error of LR models: nξξ nβξ β¦ β¦ β¦ ×average_absolute_error Greedily remove terms from LR models to minimize estimated error Heavy pruning: single model may replace whole subtree Proceed bottom up: compare error of LR model at internal node to error of subtree Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 98 Nominal attributes β Convert nominal attributes to binary ones Sort attribute by average class value β If attribute has k values, generate k β 1 binary attributes β β i th is 0 if value lies within the first i , otherwise 1 Treat binary attributes as numeric β Can prove: best split on one of the new attributes is the best (binary) split on original β Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 99 Missing values β Modify splitting criterion: Ti m SDR= β£Tβ£ ×[sd ξTξββi β£ T β£×sd ξTi ξ] β To determine which subset an instance goes into, use surrogate splitting β β β β Split on the attribute whose correlation with original is greatest Problem: complex and time-consuming Simple solution: always use the class Test set: replace missing value with average Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 100 Surrogate splitting based on class β β Choose split point based on instances with known values Split point divides instances into 2 subsets β β β β m is the average of the two averages For an instance with a missing value: β β β L (smaller class average) R (larger) Choose L if class value < m Otherwise R Once full tree is built, replace missing values with averages of corresponding leaf nodes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 101 Pseudo-code for M5' β Four methods: β¦ β¦ β¦ β¦ β β Main method: MakeModelTree Method for splitting: split Method for pruning: prune Method that computes error: subtreeError Weβll briefly look at each method in turn Assume that linear regression method performs attribute subset selection based on error Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 102 MakeModelTree MakeModelTree (instances) { SD = sd(instances) for each k-valued nominal attribute convert into k-1 synthetic binary attributes root = newNode root.instances = instances split(root) prune(root) printTree(root) } Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 103 split split(node) { if sizeof(node.instances) < 4 or sd(node.instances) < 0.05*SD node.type = LEAF else node.type = INTERIOR for each attribute for all possible split positions of attribute calculate the attribute's SDR node.attribute = attribute with maximum SDR split(node.left) split(node.right) } Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 104 prune prune(node) { if node = INTERIOR then prune(node.leftChild) prune(node.rightChild) node.model = linearRegression(node) if subtreeError(node) > error(node) then node.type = LEAF } Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 105 subtreeError subtreeError(node) { l = node.left; r = node.right if node = INTERIOR then return (sizeof(l.instances)*subtreeError(l) + sizeof(r.instances)*subtreeError(r)) /sizeof(node.instances) else return error(node) } Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 106 Model tree for servo data Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 107 Rules from model trees β β β β PART algorithm generates classification rules by building partial decision trees Can use the same method to build rule sets for regression β¦ Use model trees instead of decision trees β¦ Use variance instead of entropy to choose node to expand when building partial tree Rules will have linear models on right-hand side Caveat: using smoothed trees may not be appropriate due to separate-and-conquer strategy Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 108 Locally weighted regression β Numeric prediction that combines β β β βLazyβ: β β β β β computes regression function at prediction time works incrementally Weight training instances β β instance-based learning linear regression according to distance to test instance needs weighted version of linear regression Advantage: nonlinear approximation But: slow Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 109 Design decisions β Weighting function: β¦ β¦ β¦ β¦ β Inverse Euclidean distance Gaussian kernel applied to Euclidean distance Triangular kernel used the same way etc. Smoothing parameter is used to scale the distance function β¦ β¦ Multiply distance by inverse of this parameter Possible choice: distance of k th nearest training instance (makes it data dependent) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 110 Discussion β β β β β β Regression trees were introduced in CART Quinlan proposed model tree method (M5) M5β: slightly improved, publicly available Quinlan also investigated combining instance-based learning with M5 CUBIST: Quinlanβs commercial rule learner for numeric prediction Interesting comparison: neural nets vs. M5 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 111 From naïve Bayes to Bayesian Networks β β β β Naïve Bayes assumes: attributes conditionally independent given the class Doesnβt hold in practice but classification accuracy often high However: sometimes performance much worse than e.g. decision tree Can we eliminate the assumption? Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 112 Enter Bayesian networks β β β β Graphical models that can represent any probability distribution Graphical representation: directed acyclic graph, one node for each attribute Overall probability distribution factorized into component distributions Graphβs nodes hold component distributions (conditional distributions) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 113 Ne we two a t h rk e r fo r da th ta e Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 114 Ne we two a t h rk e r fo r da th ta e Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 115 Computing the class probabilities β Two steps: computing a product of probabilities for each class and normalization β¦ β¦ For each class value β Take all attribute values and class value β Look up corresponding entries in conditional probability distribution tables β Take the product of all probabilities Divide the product for each class by the sum of the products (normalization) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 116 Why can we do this? (Part I) β Single assumption: values of a nodeβs parents completely determine probability distribution for current node Pr [node|ancestors]=Pr [node|parents] β’ Means that node/attribute is conditionally independent of other ancestors given parents Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 117 Why can we do this? (Part II) β Chain rule from probability theory: Pr [a1, a2, ... , an ]=βni=1 Pr [ai | aiβ1 , ... , a1 ] β’ Because of our assumption from the previous slide: Pr [a1, a2, ... , an ]=βni=1 Pr [ai | aiβ1 ,... , a1 ]= βni=1 Pr [ai | ai ' s parents] Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 118 Learning Bayes nets β Basic components of algorithms for learning Bayes nets: β¦ Method for evaluating the goodness of a given network β β¦ Measure based on probability of training data given the network (or the logarithm thereof) Method for searching through space of possible networks β Amounts to searching through sets of edges because nodes are fixed Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 119 Problem: overfitting β Canβt just maximize probability of the training data β¦ β Because then itβs always better to add more edges (fit the training data more closely) Need to use cross-validation or some penalty for complexity of the network β AIC measure: β MDL measure: AIC score=βLLξK MDL score=βLLξ K2 log N β LL: log-likelihood (log of probability of data), K: number of free parameters, N: #instances β’ Another possibility: Bayesian approach with prior distribution over networks Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 120 Searching for a good structure β Task can be simplified: can optimize each node separately β¦ β¦ β β Because probability of an instance is product of individual nodesβ probabilities Also works for AIC and MDL criterion because penalties just add up Can optimize node by adding or removing edges from other nodes Must not introduce cycles! Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 121 The K2 algorithm β β β β β Starts with given ordering of nodes (attributes) Processes each node in turn Greedily tries adding edges from previous nodes to current node Moves to next node when current node canβt be optimized further Result depends on initial order Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 122 Some tricks β β Sometimes it helps to start the search with a naïve Bayes network It can also help to ensure that every node is in Markov blanket of class node β¦ β¦ β¦ Markov blanket of a node includes all parents, children, and childrenβs parents of that node Given values for Markov blanket, node is conditionally independent of nodes outside blanket I.e. node is irrelevant to classification if not in Markov blanket of class node Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 123 Other algorithms β Extending K2 to consider greedily adding or deleting edges between any pair of nodes β¦ β Further step: considering inverting the direction of edges TAN (Tree Augmented Naïve Bayes): β¦ β¦ β¦ Starts with naïve Bayes Considers adding second parent to each node (apart from class node) Efficient algorithm exists Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 124 Likelihood vs. conditional likelihood β In classification what we really want is to maximize probability of class given other attributes β Not probability of the instances β β β But: no closed-form solution for probabilities in nodesβ tables that maximize this However: can easily compute conditional probability of data based on given network Seems to work well when used for network scoring Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 125 Data structures for fast learning β β Learning Bayes nets involves a lot of counting for computing conditional probabilities Naïve strategy for storing counts: hash table β¦ β Runs into memory problems very quickly More sophisticated strategy: all-dimensions (AD) tree β¦ β¦ β¦ Analogous to kD-tree for numeric data Stores counts in a tree but in a clever way such that redundancy is eliminated Only makes sense to use it for large datasets Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 126 AD tree example Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 127 Building an AD tree β β Assume each attribute in the data has been assigned an index Then, expand node for attribute i with the values of all attributes j > i β¦ Two important restrictions: β β β Most populous expansion for each attribute is omitted (breaking ties arbitrarily) Expansions with counts that are zero are also omitted The root node is given index zero Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 128 Discussion β β We have assumed: discrete data, no missing values, no new nodes Different method of using Bayes nets for classification: Bayesian multinets β¦ β β I.e. build one network for each class and make prediction using Bayesβ rule Different class of learning methods for Bayes nets: testing conditional independence assertions Can also build Bayes nets for regression tasks Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 129 Clustering: how many clusters? β How to choose k in k-means? Possibilities: β¦ β¦ β¦ Choose k that minimizes cross-validated squared distance to cluster centers Use penalized squared distance on the training data (eg. using an MDL criterion) Apply k-means recursively with k = 2 and use stopping criterion (eg. based on MDL) β β Seeds for subclusters can be chosen by seeding along direction of greatest variance in cluster (one standard deviation away in each direction from cluster center of parent cluster) Implemented in algorithm called X-means (using Bayesian Information Criterion instead of MDL) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 130 Hierarchical clustering β Recursively splitting clusters produces a hierarchy that can be represented as a dendogram β¦ β¦ Could also be represented as a Venn diagram of sets and subsets (without intersections) Height of each node in the dendogram can be made proportional to the dissimilarity between its children Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 131 Agglomerative clustering β β Bottom-up approach Simple algorithm β¦ β¦ β¦ β¦ β¦ Requires a distance/similarity measure Start by considering each instance to be a cluster Find the two closest clusters and merge them Continue merging until only one cluster is left The record of mergings forms a hierarchical clustering structure β a binary dendogram Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 132 Distance measures β Single-linkage β¦ β¦ β¦ β Minimum distance between the two clusters Distance between the clusters closest two members Can be sensitive to outliers Complete-linkage β¦ β¦ β¦ β¦ Maximum distance between the two clusters Two clusters are considered close only if all instances in their union are relatively similar Also sensitive to outliers Seeks compact clusters Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 133 Distance measures cont. β β Compromise between the extremes of minimum and maximum distance Represent clusters by their centroid, and use distance between centroids β centroid linkage β¦ β¦ β β Works well for instances in multidimensional Euclidean space Not so good if all we have is pairwise similarity between instances Calculate average distance between each pair of members of the two clusters β average-linkage Technical deficiency of both: results depend on the numerical scale on which distances are measured Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 134 More distance measures β Group-average clustering β¦ β¦ β Uses the average distance between all members of the merged cluster Differs from average-linkage because it includes pairs from the same original cluster Ward's clustering method Calculates the increase in the sum of squares of the distances of the instances from the centroid before and after fusing two clusters β¦ Minimize the increase in this squared distance at each clustering step All measures will produce the same result if the clusters are compact and well separated β¦ β Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 135 Example hierarchical clustering β 50 examples of different creatures from the zoo data Complete-linkage Dendogram Polar plot Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 136 Example hierarchical clustering 2 Single-linkage Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 137 Incremental clustering β β β Heuristic approach (COBWEB/CLASSIT) Form a hierarchy of clusters incrementally Start: β¦ β Then: β¦ β¦ β¦ β¦ β tree consists of empty root node add instances one by one update tree appropriately at each stage to update, find the right leaf for an instance May involve restructuring the tree Base update decisions on category utility Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 138 Clustering weather data ID Outlook Temp. Humidity Windy A Sunny Hot High False B Sunny Hot High True C Overcast Hot High False D Rainy Mild High False E Rainy Cool Normal False F Rainy Cool Normal True G Overcast Cool Normal True H Sunny Mild High False I Sunny Cool Normal False J Rainy Mild Normal False K Sunny Mild Normal True L Overcast Mild High True M Overcast Hot Normal False N Rainy Mild High True 1 2 3 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 139 Clustering weather data ID Outlook Temp. Humidity Windy A Sunny Hot High False B Sunny Hot High True C Overcast Hot High False D Rainy Mild High False E Rainy Cool Normal False F Rainy Cool Normal True G Overcast Cool Normal True H Sunny Mild High False I Sunny Cool Normal False J Rainy Mild Normal False K Sunny Mild Normal True L Overcast Mild High True M Overcast Hot Normal False N Rainy Mild High True 4 5 Merge best host and runner-up 3 Consider splitting the best host if merging doesnβt help Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 140 Final hierarchy Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 141 Example: the iris data (subset) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 142 Clustering with cutoff Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 143 Category utility β Category utility: quadratic loss function defined on conditional probabilities: CUξC1, C2, ... , Ck ξ= β βl Pr [Cl ]βi β j ξPr [ ai= vij |Cl ]2βPr [ai =v ij ]2 ξ k Every instance in different category β numerator becomes nββi β j Pr [a i =v ij ]2 maximum number of attributes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 144 Numeric attributes β β Assume normal distribution: f (a)= Then: 1 β(2 Ο)Ο exp( β (aβΞΌ)2 2 Ο2 ) β j Pr [ai =v ij ]2β‘β« f (ai )2 dai = 2 β1Ο Ο β Thus CU (C 1, C 2, ... ,C k)= becomes β i βl Pr [Cl ]βi β j (Pr [ai =v ij |Cl ]2 βPr [ai =v ij ]2 ) CU (C 1, C 2, ... , C k)= k βl Pr [Cl ] 21βΟ βi ( Ο1 β Ο1 ) il i k Prespecified minimum variance β¦ acuity parameter Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 145 Probability-based clustering β Problems with heuristic approach: β¦ β¦ β¦ β¦ β β Division by k? Order of examples? Are restructuring operations sufficient? Is result at least local minimum of category utility? Probabilistic perspective β seek the most likely clusters given the data Also: instance belongs to a particular cluster with a certain probability Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 146 Finite mixtures β β Model data using a mixture of distributions One cluster, one distribution β¦ β β β governs probabilities of attribute values in that cluster Finite mixtures : finite number of clusters Individual distributions are normal (usually) Combine distributions using cluster weights Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 147 Two-class mixture model data A A B B A A A A A 51 43 62 64 45 42 46 45 45 B A A B A B A A A 62 47 52 64 51 65 48 49 46 B A A B A A B A A 64 51 52 62 49 48 62 43 40 A B A B A B B B A 48 64 51 63 43 65 66 65 46 A B B A B B A B A 39 62 64 52 63 64 48 64 48 A A B A A A 51 48 64 42 48 41 model µA=50, ΟA =5, pA=0.6 µB=65, ΟB =2, pB=0.4 Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 148 Using the mixture model β Probability that instance x belongs to cluster A: | A] Pr [ A] Pr [ A| x ]= Pr [ xPr = [x] f (x ;ΞΌ A , Ο A )p A Pr [ x] with f (x ;ΞΌ ,Ο)= β 1 β(2 Ο)Ο exp( β (xβΞΌ)2 2 Ο2 ) Probability of an instance given the clusters: Pr [ x |the_clusters]=βi Pr [ x |cluster i ] Pr [cluster i ] Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 149 Learning the clusters β Assume: β¦ β Learn the clusters β β¦ β¦ β determine their parameters I.e. means and standard deviations Performance criterion: β¦ β we know there are k clusters probability of training data given the clusters EM algorithm β¦ finds a local maximum of the likelihood Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 150 EM algorithm β EM = Expectation-Maximization β β Generalize k-means to probabilistic setting Iterative procedure: β β E βexpectationβ step: Calculate cluster probability for each instance M βmaximizationβ step: Estimate distribution parameters from cluster probabilities Store cluster probabilities as instance weights β Stop when improvement is negligible β Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 151 More on EM β Estimate parameters from weighted instances ΞΌ A= Ο A= w 1 x 1 +w 2 x 2+...+w n x n w 1 +w 2+...+w n w 1 ( x 1βΞΌ)2+w 2 (x 2 βΞΌ)2 +...+wn (x nβΞΌ)2 w1+w2 +...+w n β Stop when log-likelihood saturates β Log-likelihood: βi log(p A Pr [ xi | A]+p B Pr [ xi | B]) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 152 Extending the mixture model β β β More then two distributions: easy Several attributes: easyβassuming independence! Correlated attributes: difficult β¦ β¦ Joint model: bivariate normal distribution with a (symmetric) covariance matrix n attributes: need to estimate n + n (n+1)/2 parameters Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 153 More mixture model extensions β β Nominal attributes: easy if independent Correlated nominal attributes: difficult Two correlated attributes β v1 v2 parameters Missing values: easy Can use other distributions than normal: β β β β β β β βlog-normalβ if predetermined minimum is given βlog-oddsβ if bounded from above and below Poisson for attributes that are integer counts Use cross-validation to estimate k ! Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 154 Bayesian clustering β β Problem: many parameters β EM overfits Bayesian approach : give every parameter a prior probability distribution β¦ β¦ β β β Incorporate prior into overall likelihood figure Penalizes introduction of parameters Eg: Laplace estimator for nominal attributes Can also have prior on number of clusters! Implementation: NASAβs AUTOCLASS Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 155 Discussion β Can interpret clusters by using supervised learning β¦ β Decrease dependence between attributes? β¦ β¦ β β post-processing step pre-processing step E.g. use principal component analysis Can be used to fill in missing values Key advantage of probabilistic clustering: β¦ β¦ Can estimate likelihood of data Use it to compare different models objectively Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 156 Semisupervised learning β Semisupervised learning: attempts to use unlabeled data as well as labeled data β¦ β Why try to do this? Unlabeled data is often plentiful and labeling data can be expensive β¦ β¦ β¦ β The aim is to improve classification performance Web mining: classifying web pages Text mining: identifying names in text Video mining: classifying people in the news Leveraging the large pool of unlabeled examples would be very attractive Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6) 157 Clustering for classification β Idea: use naïve Bayes on labeled examples and then apply EM β¦ β¦ β¦ β¦ β First, build naïve Bayes model on labeled data Second, label unlabeled data based on class probabilities (βexpectationβ step) Third, train new naïve Bayes model based on all the data (βmaximizationβ step) Fourth, repeat 2nd and 3rd step until convergence Essentially the same as EM for clustering with fixed cluster membership probabilities for labeled data and #clusters = #classes Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 158 Comments β Has been applied successfully to document classification β¦ β¦ β¦ β β Certain phrases are indicative of classes Some of these phrases occur only in the unlabeled data, some in both sets EM can generalize the model by taking advantage of cooccurrence of these phrases Refinement 1: reduce weight of unlabeled data Refinement 2: allow multiple clusters per class Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 159 Co-training β Method for learning from multiple views (multiple sets of attributes), eg: β¦ β¦ β β β β β β First set of attributes describes content of web page Second set of attributes describes links that link to the web page Step 1: build model from each view Step 2: use models to assign labels to unlabeled data Step 3: select those unlabeled examples that were most confidently predicted (ideally, preserving ratio of classes) Step 4: add those examples to the training set Step 5: go to Step 1 until data exhausted Assumption: views are independent Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 160 EM and co-training β Like EM for semisupervised learning, but view is switched in each iteration of EM β¦ β Has also been used successfully with support vector machines β¦ β Uses all the unlabeled data (probabilistically labeled) for training Using logistic models fit to output of SVMs Co-training also seems to work when views are chosen randomly! β¦ Why? Possibly because co-trained classifier is more robust Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 161 Multi-instance learning β β Converting to single-instance learning Already seen aggregation of input or output β¦ β Will fail in some situations β¦ β Simple and often work well in practice Aggregating the input loses a lot of information because attributes are condensed to summary statistics individually and independently Can a bag be converted to a single instance without discarding so much info? Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 162 Converting to single-instance β β Can convert to single instance without losing so much info, but more attributes are needed in the βcondensedβ representation Basic idea: partition the instance space into regions β¦ β One attribute per region in the single-instance representation Simplest case β boolean attributes β¦ Attribute corresponding to a region is set to true for a bag if it has at least one instance in that region Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 163 Converting to single-instance β β β Could use numeric counts instead of boolean attributes to preserve more information Main problem: how to partition the instance space? Simple approach β partition into equal sized hypercubes β¦ β Only works for few dimensions More practical β use unsupervised learning β¦ Take all instances from all bags (minus class labels) and cluster β¦ Create one attribute per cluster (region) Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 164 Converting to single-instance β β Clustering ignores the class membership Use a decision tree to partition the space instead β¦ β Each leaf corresponds to one region of instance space How to learn tree when class labels apply to entire bags? β¦ β¦ Aggregating the output can be used: take the bag's class label and attach it to each of its instances Many labels will be incorrect, however, they are only used to obtain a partitioning of the space Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 165 Converting to single-instance β β β Using decision trees yields βhardβ partition boundaries So does k-means clustering into regions, where the cluster centers (reference points) define the regions Can make region membership βsoftβ by using distance β transformed into similarity β to compute attribute values in the condensed representation β¦ Just need a way of aggregating similarity scores between each bag and reference point into a single value β e.g. max similarity between each instance in a bag and the reference point Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 166 Upgrading learning algorithms β Converting to single-instance is appealing because many existing algorithms can then be applied without modification β¦ β May not be the most efficient approach Alternative: adapt single-instance algorithm to the multi-instance setting β¦ β¦ Can be achieved elegantly for for distance/similaritybased methods (e.g. nearest neighbor or SVMs) Compute distance/similarity between two bags of instances Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 167 Upgrading learning algorithms β Kernel-based methods β¦ β¦ Similarity must be a proper kernel function that satisfies certain mathematical properties One example β so called set kernel β β Given a kernel function for pairs of instances, the set kernel sums it over all pairs of instances from the two bags being compared Is generic and can be applied with any single-instance kernel function Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 168 Upgrading learning algorithms β Nearest neighbor learning β¦ β¦ Apply variants of the Hausdorff distance, which is defined for sets of points Given two bags and a distance function between pairs of instances, Hausdorff distance between the bags is Largest distance from any instance in one bag to its closest instance in the other bag β¦ Can be made more robust to outliers by using the nth-largest distance Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 169 Dedicated multi-instance methods β β β Some methods are not based directly on single-instance algorithms One basic approach β find a single hyperrectangle that contains at least one instance from each positive bag and no instances from any negative bags β¦ Rectangle encloses an area of the instance space where all positive bags overlap β¦ Originally designed for the drug activity problem mentioned in Chapter 2 Can use other shapes β e.g hyperspheres (balls) β¦ Can also use boosting to build an ensemble of balls Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 170 Dedicated multi-instance methods β Previously described methods have hard decision boundaries β an instance either falls inside or outside a hyperectangle/ball β β Other methods use probabilistic soft concept descriptions Diverse-density β¦ β¦ Learns a single reference point in instance space Probability that an instance is positive decreases with increasing distance from the reference point Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 171 Dedicated multi-instance methods β Diverse-density β¦ β¦ β¦ β¦ β¦ Combine instance probabilities within a bag to obtain probability that bag is positive βnoisy-ORβ (probabilistic version of logical OR) All instance-level probabilities 0 β noisy-OR value and baglevel probability is 0 At least one instance-level probability is β 1 the value is 1 Diverse density, like the geometric methods, is maximized when the reference point is located in an area where positive bags overlap and no negative bags are present β Gradient descent can be used to maximize Data Mining: Practical Machine Learning Tools and Techniques (Chapter 7) 172