Post on 02-Dec-2014
description
Data Mining: the PracticeData Mining: the PracticeAn IntroductionAn Introduction
Slides taken fromSlides taken from:
Data Mining by I. H. Witten and E. Frank
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
2
What’s it all about?
• Data vs information• Data mining and machine learning• Structural descriptions
– Rules: classification and association– Decision trees
• Datasets– Weather, contact lens, CPU performance, labor negotiation
data, soybean classification
• Fielded applications– Loan applications, screening images, load forecasting, machine
fault diagnosis, market basket analysis
• Generalization as search• Data mining and ethics
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
3
Data vs. information
• Society produces huge amounts of data– Sources: business, science, medicine, economics,
geography, environment, sports, …
• Potentially valuable resource• Raw data is useless: need techniques to
automatically extract information from it– Data: recorded facts– Information: patterns underlying the data
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
4
Data mining
• Extracting– implicit,– previously unknown,– potentially useful
information from data• Needed: programs that detect patterns and
regularities in the data• Strong patterns good predictions
– Problem 1: most patterns are not interesting– Problem 2: patterns may be inexact (or spurious)– Problem 3: data may be garbled or missing
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
5
Machine learning techniques
• Algorithms for acquiring structural descriptions from examples
• Structural descriptions represent patterns explicitly
– Can be used to predict outcome in new situation– Can be used to understand and explain how
prediction is derived(may be even more important)
• Methods originate from artificial intelligence, statistics, and research on databases
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
6
Structural descriptions
• Example: if-then rules
……………
HardNormalYesMyopePresbyopic
NoneReducedNoHypermetropePre-presbyopic
SoftNormalNoHypermetropeYoung
NoneReducedNoMyopeYoung
Recommended lenses
Tear production rate
AstigmatismSpectacle prescription
Age
If tear production rate = reducedthen recommendation = none
Otherwise, if age = young and astigmatic = no then recommendation = soft
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
7
Screening images• Given: radar satellite images of coastal waters• Problem: detect oil slicks in those images• Oil slicks appear as dark regions with changing
size and shape• Not easy: lookalike dark regions can be caused
by weather conditions (e.g. high wind)• Expensive process requiring highly trained
personnel
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
8
Enter machine learning• Extract dark regions from normalized image• Attributes:
– size of region– shape, area– intensity– sharpness and jaggedness of boundaries– proximity of other regions– info about background
• Constraints:– Few training examples—oil slicks are rare!– Unbalanced data: most dark regions aren’t slicks– Regions from same image form a batch– Requirement: adjustable false-alarm rate
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
9
Marketing and sales I
• Companies precisely record massive amounts of marketing and sales data
• Applications:– Customer loyalty:
identifying customers that are likely to defect by detecting changes in their behavior(e.g. banks/phone companies)
– Special offers:identifying profitable customers(e.g. reliable owners of credit cards that need extra money during the holiday season)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
10
Marketing and sales II
• Market basket analysis– Association techniques find
groups of items that tend tooccur together in atransaction(used to analyze checkout data)
• Historical analysis of purchasing patterns• Identifying prospective customers
– Focusing promotional mailouts(targeted campaigns are cheaper than mass-marketed ones)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
11
Generalization as search
• Inductive learning: find a concept description that fits the data
• Example: rule sets as description language – Enormous, but finite, search space
• Simple solution:– enumerate the concept space– eliminate descriptions that do not fit examples– surviving descriptions contain target concept
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
12
Enumerating the concept space
• Search space for weather problem– 4 x 4 x 3 x 3 x 2 = 288 possible combinations– With 14 rules 2.7x1034 possible rule sets
• Other practical problems:– More than one description may survive– No description may survive
• Language is unable to describe target concept• or data contains noise
• Another view of generalization as search:hill-climbing in description space according to pre-specified matching criterion
– Most practical algorithms use heuristic search that cannot guarantee to find the optimum solution
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
13
Bias
• Important decisions in learning systems:– Concept description language– Order in which the space is searched– Way that overfitting to the particular training data is
avoided
• These form the “bias” of the search:– Language bias– Search bias– Overfitting-avoidance bias
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
14
Language bias
• Important question:– is language universal
or does it restrict what can be learned?
• Universal language can express arbitrary subsets of examples
• If language includes logical or (“disjunction”), it is universal
• Example: rule sets• Domain knowledge can be used to exclude some
concept descriptions a priori from the search
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
15
Search bias
• Search heuristic– “Greedy” search: performing the best single step– “Beam search”: keeping several alternatives– …
• Direction of search– General-to-specific
• E.g. specializing a rule by adding conditions
– Specific-to-general• E.g. generalizing an individual instance into a rule
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
16
Overfitting-avoidance bias
• Can be seen as a form of search bias• Modified evaluation criterion
– E.g. balancing simplicity and number of errors
• Modified search strategy– E.g. pruning (simplifying a description)
• Pre-pruning: stops at a simple description before search proceeds to an overly complex one
• Post-pruning: generates a complex description first and simplifies it afterwards
Concepts, instances, attributesConcepts, instances, attributesSlides for Chapter 2 of Data Mining by I. H. Witten and E. Frank
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
18
Input: Concepts, instances, attributes
● Terminology● What’s a concept?
Classification, association, clustering, numeric prediction
● What’s in an example? Relations, flat files, recursion
● What’s in an attribute? Nominal, ordinal, interval, ratio
● Preparing the input ARFF, attributes, missing values, getting to know
data
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
19
Terminology
● Components of the input: Concepts: kinds of things that can be
learned● Aim: intelligible and operational concept
description Instances: the individual, independent
examples of a concept● Note: more complicated forms of input are
possible Attributes: measuring aspects of an instance
● We will focus on nominal and numeric ones
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
20
What’s a concept?● Styles of learning:
Classification learning:predicting a discrete class
Association learning:detecting associations between features
Clustering:grouping similar instances into clusters
Numeric prediction:predicting a numeric quantity
● Concept: thing to be learned● Concept description:
output of learning scheme
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
21
Classification learning
● Example problems: weather data, contact lenses, irises, labor negotiations
● Classification learning is supervised Scheme is provided with actual outcome
● Outcome is called the class of the example
● Measure success on fresh data for which class labels are known (test data)
● In practice success is often measured subjectively
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
22
Association learning
● Can be applied if no class is specified and any kind of structure is considered “interesting”
● Difference to classification learning: Can predict any attribute’s value, not just the
class, and more than one attribute’s value at a time
Hence: far more association rules than classification rules
Thus: constraints are necessary● Minimum coverage and minimum accuracy
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
23
Clustering● Finding groups of items that are similar● Clustering is unsupervised
The class of an example is not known● Success often measured subjectively
…
…
…
Iris virginica1.95.12.75.8102
101
52
51
2
1
Iris virginica2.56.03.36.3
Iris versicolor
1.54.53.26.4
Iris versicolor
1.44.73.27.0
Iris setosa0.21.43.04.9
Iris setosa0.21.43.55.1
TypePetal width
Petal length
Sepal width
Sepal length
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
24
Numeric prediction● Variant of classification learning where
“class” is numeric (also called “regression”)
● Learning is supervised Scheme is being provided with target
value● Measure success on test data
……………
40FalseNormalMildRainy
55FalseHighHot Overcast
0TrueHigh Hot Sunny
5FalseHighHotSunny
Play-timeWindyHumidityTemperatureOutlook
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
25
What’s in an example?● Instance: specific type of example
● Thing to be classified, associated, or clustered● Individual, independent example of target
concept● Characterized by a predetermined set of
attributes● Input to learning scheme: set of instances/dataset● Represented as a single relation/flat file
● Rather restricted form of input ● No relationships between objects
● Most common form in practical data mining
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
26
What’s in an attribute?
● Each instance is described by a fixed predefined set of features, its “attributes”
● But: number of attributes may vary in practice
Possible solution: “irrelevant value” flag● Related problem: existence of an
attribute may depend of value of another one
● Possible attribute types (“levels of measurement”):
Nominal, ordinal, interval and ratio
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
27
Nominal quantities
● Values are distinct symbols Values themselves serve only as labels or
names Nominal comes from the Latin word for name
● Example: attribute “outlook” from weather data
Values: “sunny”,”overcast”, and “rainy”● No relation is implied among nominal
values (no ordering or distance measure)● Only equality tests can be performed
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
28
Ordinal quantities● Impose order on values● But: no distance between values defined● Example:
attribute “temperature” in weather data Values: “hot” > “mild” > “cool”
● Note: addition and subtraction don’t make sense
● Example rule:temperature < hot play = yes
● Distinction between nominal and ordinal not always clear (e.g. attribute “outlook”)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
29
Interval quantities
● Interval quantities are not only ordered but measured in fixed and equal units
● Example 1: attribute “temperature” expressed in degrees Fahrenheit
● Example 2: attribute “year”● Difference of two values makes sense● Sum or product doesn’t make sense
Zero point is not defined!
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
30
Ratio quantities
● Ratio quantities are ones for which the measurement scheme defines a zero point
● Example: attribute “distance” Distance between an object and itself is zero
● Ratio quantities are treated as real numbers
All mathematical operations are allowed● But: is there an “inherently” defined zero
point? Answer depends on scientific knowledge (e.g.
Fahrenheit knew no lower limit to temperature)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
31
Attribute types used in practice
● Most schemes accommodate just two levels of measurement: nominal and ordinal
● Nominal attributes are also called “categorical”, ”enumerated”, or “discrete”
But: “enumerated” and “discrete” imply order
● Special case: dichotomy (“boolean” attribute)
● Ordinal attributes are called “numeric”, or “continuous”
But: “continuous” implies mathematical continuity
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
32
Metadata
● Information about the data that encodes background knowledge
● Can be used to restrict search space● Examples:
Dimensional considerations(i.e. expressions must be dimensionally correct)
Circular orderings(e.g. degrees in compass)
Partial orderings(e.g. generalization/specialization relations)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
33
Preparing the input
● Denormalization is not the only issue● Problem: different data sources (e.g. sales
department, customer billing department, …)
Differences: styles of record keeping, conventions, time periods, data aggregation, primary keys, errors
Data must be assembled, integrated, cleaned up
“Data warehouse”: consistent point of access● External data may be required (“overlay
data”)● Critical: type and level of data aggregation
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
34
The ARFF format
%% ARFF file for weather data with some numeric features%@relation weather
@attribute outlook {sunny, overcast, rainy}@attribute temperature numeric@attribute humidity numeric@attribute windy {true, false}@attribute play? {yes, no}
@datasunny, 85, 85, false, nosunny, 80, 90, true, noovercast, 83, 86, false, yes...
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
35
Additional attribute types
• ARFF supports string attributes:
– Similar to nominal attributes but list of values is not pre-specified
• It also supports date attributes:
– Uses the ISO-8601 combined date and time format yyyy-MM-dd-THH:mm:ss
@attribute description string
@attribute today date
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
36
Attribute types
● Interpretation of attribute types in ARFF depends on learning scheme
Numeric attributes are interpreted as● ordinal scales if less-than and greater-than are
used● ratio scales if distance calculations are
performed (normalization/standardization may be required)
Instance-based schemes define distance between nominal values (0 if values are equal, 1 otherwise)
● Integers in some given data file: nominal, ordinal, or ratio scale?
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
37
Nominal vs. ordinal
● Attribute “age” nominal
● Attribute “age” ordinal(e.g. “young” < “pre-presbyopic” < “presbyopic”)
If age = young and astigmatic = noand tear production rate = normalthen recommendation = soft
If age = pre-presbyopic and astigmatic = no and tear production rate = normal then recommendation = soft
If age pre-presbyopic and astigmatic = noand tear production rate = normalthen recommendation = soft
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
38
Missing values
● Frequently indicated by out-of-range entries
Types: unknown, unrecorded, irrelevant Reasons:
● malfunctioning equipment● changes in experimental design● collation of different datasets● measurement not possible
● Missing value may have significance in itself (e.g. missing test in a medical examination)
Most schemes assume that is not the case: “missing” may need to be coded as additional value
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
39
Inaccurate values
● Reason: data has not been collected for mining it
● Result: errors and omissions that don’t affect original purpose of data (e.g. age of customer)
● Typographical errors in nominal attributes values need to be checked for consistency
● Typographical and measurement errors in numeric attributes outliers need to be identified
● Errors may be deliberate (e.g. wrong zip codes)
● Other problems: duplicates, stale data
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 2)
40
Getting to know the data
● Simple visualization tools are very useful
Nominal attributes: histograms (Distribution consistent with background knowledge?)
Numeric attributes: graphs(Any obvious outliers?)
● 2-D and 3-D plots show dependencies ● Need to consult domain experts ● Too much data to inspect? Take a
sample!
Output: representing structural patterns
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
42
Output: representing structural patterns
● Many different ways of representing patterns
Decision trees, rules, instance-based, …● Also called “knowledge” representation● Representation determines inference
method● Understanding the output is the key to
understanding the underlying learning methods
● Different types of output for different learning problems (e.g. classification, regression, …)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
43
Classification rules
● Popular alternative to decision trees● Antecedent (pre-condition): a series of tests
(just like the tests at the nodes of a decision tree)
● Tests are usually logically ANDed together (but may also be general logical expressions)
● Consequent (conclusion): classes, set of classes, or probability distribution assigned by rule
● Individual rules are often logically ORed together
Conflicts arise if different conclusions apply
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
44
The weather problem
• Conditions for playing a certain game
……………
YesFalseNormalMildRainy
YesFalseHighHot Overcast
NoTrueHigh Hot Sunny
NoFalseHighHotSunny
PlayWindyHumidityTemperatureOutlook
If outlook = sunny and humidity = high then play = noIf outlook = rainy and windy = true then play = noIf outlook = overcast then play = yesIf humidity = normal then play = yesIf none of the above then play = yes
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
45
Weather data with mixed attributes
• Some attributes have numeric values
……………
YesFalse8075Rainy
YesFalse8683Overcast
NoTrue9080Sunny
NoFalse8585Sunny
PlayWindyHumidityTemperatureOutlook
If outlook = sunny and humidity > 83 then play = noIf outlook = rainy and windy = true then play = noIf outlook = overcast then play = yesIf humidity < 85 then play = yesIf none of the above then play = yes
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
46
Association rules
• Association rules…– … can predict any attribute and combinations of
attributes
– … are not intended to be used together as a set
• Problem: immense number of possible associations– Output needs to be restricted to show only the most
predictive associations only those with high support and high confidence
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
47
Support and confidence of a rule• Support: number of instances predicted correctly • Confidence: number of correct predictions, as
proportion of all instances that rule applies to• Example: 4 cool days with normal humidity
Support = 4, confidence = 100%
• Normally: minimum support and confidence pre-specified (e.g. 58 rules with support 2 and confidence 95% for weather data)
If temperature = cool then humidity = normal
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
48
Interpreting association rules
• Interpretation is not obvious:
is not the same as
• It means that the following also holds:
If windy = false and play = no then outlook = sunny and humidity = high
If windy = false and play = no then outlook = sunny If windy = false and play = no then humidity = high
If humidity = high and windy = false and play = no then outlook = sunny
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
49
Decision trees
● “Divide-and-conquer” approach produces tree
● Nodes involve testing a particular attribute● Usually, attribute value is compared to constant
● Other possibilities: ● Comparing values of two attributes● Using a function of one or more attributes
● Leaves assign classification, set of classifications, or probability distribution to instances
● Unknown instance is routed down the tree
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
50
Nominal and numeric attributes
● Nominal:number of children usually equal to number values attribute won’t get tested more than once● Other possibility: division into two subsets
● Numeric:test whether value is greater or less than constant attribute may get tested several times● Other possibility: three-way split (or multi-way
split)● Integer: less than, equal to, greater than● Real: below, within, above
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
51
Missing values
● Does absence of value have some significance?
● Yes “missing” is a separate value● No “missing” must be treated in a
special way Solution A: assign instance to most popular
branch Solution B: split instance into pieces
● Pieces receive weight according to fraction of training instances that go down each branch
● Classifications from leave nodes are combined using the weights that have percolated to them
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
52
The contact lenses data
NoneReducedYesHypermetropePre-presbyopic NoneNormalYesHypermetropePre-presbyopicNoneReducedNoMyopePresbyopicNoneNormalNoMyopePresbyopicNoneReducedYesMyopePresbyopicHardNormalYesMyopePresbyopicNoneReducedNoHypermetropePresbyopicSoftNormalNoHypermetropePresbyopicNoneReducedYesHypermetropePresbyopicNoneNormalYesHypermetropePresbyopic
SoftNormalNoHypermetropePre-presbyopicNoneReducedNoHypermetropePre-presbyopicHardNormalYesMyopePre-presbyopicNoneReducedYesMyopePre-presbyopicSoftNormalNoMyopePre-presbyopicNoneReducedNoMyopePre-presbyopichardNormalYesHypermetropeYoungNoneReducedYesHypermetropeYoungSoftNormalNoHypermetropeYoungNoneReducedNoHypermetropeYoungHardNormalYesMyopeYoungNoneReducedYesMyopeYoung SoftNormalNoMyopeYoungNoneReducedNoMyopeYoung
Recommended lenses
Tear production rate
AstigmatismSpectacle prescription
Age
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
53
A complete and correct rule set
If tear production rate = reduced then recommendation = noneIf age = young and astigmatic = no
and tear production rate = normal then recommendation = softIf age = pre-presbyopic and astigmatic = no
and tear production rate = normal then recommendation = softIf age = presbyopic and spectacle prescription = myope
and astigmatic = no then recommendation = noneIf spectacle prescription = hypermetrope and astigmatic = no
and tear production rate = normal then recommendation = softIf spectacle prescription = myope and astigmatic = yes
and tear production rate = normal then recommendation = hardIf age young and astigmatic = yes
and tear production rate = normal then recommendation = hardIf age = pre-presbyopic
and spectacle prescription = hypermetropeand astigmatic = yes then recommendation = none
If age = presbyopic and spectacle prescription = hypermetropeand astigmatic = yes then recommendation = none
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
54
Classification vs. association rules
• Classification rule:predicts value of a given attribute (the classification of an example)
• Association rule:predicts value of arbitrary attribute (or combination)
If outlook = sunny and humidity = highthen play = no
If temperature = cool then humidity = normalIf humidity = normal and windy = false
then play = yesIf outlook = sunny and play = no
then humidity = highIf windy = false and play = no
then outlook = sunny and humidity = high
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
55
A decision tree for this problem
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 1)
56
• Example: 209 different computer configurations
• Linear regression function
Predicting CPU performance
0
0
32
128
CHMAX
0
0
8
16
CHMIN
Channels Performance
Cache (Kb)
Main memory (Kb)
Cycle time (ns)
45040001000480209
67328000512480208
…
26932320008000292
19825660002561251
PRPCACHMMAXMMINMYCT
PRP = -55.9 + 0.0489 MYCT + 0.0153 MMIN + 0.0056 MMAX+ 0.6410 CACH - 0.2700 CHMIN + 1.480 CHMAX
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
57
Linear regression for the CPU data
PRP = -56.1
+ 0.049 MYCT+ 0.015 MMIN+ 0.006 MMAX+ 0.630 CACH- 0.270 CHMIN+ 1.46 CHMAX
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
58
Trees for numeric prediction
• Regression: the process of computing an expression that predicts a numeric quantity
• Regression tree: “decision tree” where each leaf predicts a numeric quantity
– Predicted value is average value of training instances that reach the leaf
• Model tree: “regression tree” with linear regression models at the leaf nodes
– Linear patches approximate continuous function
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
59
Regression tree for the CPU data
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
60
Model tree for the CPU data
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
61
Instance-based representation
• Simplest form of learning: rote learning– Training instances are searched for instance
that most closely resembles new instance– The instances themselves represent the
knowledge– Also called instance-based learning
• Similarity function defines what’s “learned”• Instance-based learning is lazy learning• Methods: nearest-neighbor, k-nearest-
neighbor, …
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
62
The distance function
• Simplest case: one numeric attribute– Distance is the difference between the two
attribute values involved (or a function thereof)
• Several numeric attributes: normally, Euclidean distance is used and attributes are normalized
• Nominal attributes: distance is set to 1 if values are different, 0 if they are equal
• Are all attributes equally important?– Weighting the attributes might be necessary
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
63
Representing clusters I
Simple 2-D representation
Venn diagram
Overlapping clusters
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 3)
64
Representing clusters II
1 2 3
a 0.4 0.1 0.5
b 0.1 0.8 0.1
c 0.3 0.3 0.4
d 0.1 0.1 0.8
e 0.4 0.2 0.4
f 0.1 0.4 0.5
g 0.7 0.2 0.1
h 0.5 0.4 0.1
…
Probabilistic assignment
Dendrogram
NB: dendron is the Greek word for tree
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
65
Simplicity first
● Simple algorithms often work very well! ● There are many kinds of simple structure,
eg: One attribute does all the work All attributes contribute equally &
independently A weighted linear combination might do Instance-based: use a few prototypes Use simple logical rules
● Success of method depends on the domain
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
66
Inferring rudimentary rules
● 1R: learns a 1-level decision tree I.e., rules that all test one particular
attribute● Basic version
One branch for each value Each branch assigns most frequent class Error rate: proportion of instances that
don’t belong to the majority class of their corresponding branch
Choose attribute with lowest error rate
(assumes nominal attributes)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
67
Pseudo-code for 1R
For each attribute,For each value of the attribute, make a rule as
follows:count how often each class appearsfind the most frequent classmake the rule assign that class to this
attribute-valueCalculate the error rate of the rules
Choose the rules with the smallest error rate
● Note: “missing” is treated as a separate attribute value
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
68
Evaluating the weather attributes
3/6True No*
5/142/8False YesWindy
1/7Normal Yes
4/143/7High NoHumidity
5/14
4/14
Total errors
1/4Cool Yes
2/6Mild Yes
2/4Hot No*Temp
2/5Rainy Yes
0/4Overcast Yes
2/5Sunny NoOutlook
Errors
RulesAttribute
NoTrueHighMildRainy
YesFalseNormalHotOvercast
YesTrueHighMildOvercast
YesTrueNormalMildSunny
YesFalseNormalMildRainy
YesFalseNormalCoolSunny
NoFalseHighMildSunny
YesTrueNormalCoolOvercast
NoTrueNormalCoolRainy
YesFalseNormalCoolRainy
YesFalseHighMildRainy
YesFalseHighHot Overcast
NoTrueHigh Hot Sunny
NoFalseHighHotSunny
PlayWindy
Humidity
TempOutlook
* indicates a tie
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
69
Constructing decision trees
● Strategy: top downRecursive divide-and-conquer fashion
First: select attribute for root nodeCreate branch for each possible attribute value
Then: split instances into subsetsOne for each branch extending from the node
Finally: repeat recursively for each branch, using only instances that reach the branch
● Stop if all instances have the same class
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
70
Which attribute to select?
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
71
Which attribute to select?
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
72
Criterion for attribute selection
● Which is the best attribute? Want to get the smallest tree Heuristic: choose the attribute that
produces the “purest” nodes● Popular impurity criterion: information
gain Information gain increases with the
average purity of the subsets● Strategy: choose attribute that gives
greatest information gain
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
73
Computing information
● Measure information in bits Given a probability distribution, the info
required to predict an event is the distribution’s entropy
Entropy gives the information required in bits(can involve fractions of bits!)
● Formula for computing the entropy:entropy p1,p2,... ,pn=−p1 logp1−p2 logp2 ...−pn log pn
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
74
Example: attribute Outlook
● Outlook = Sunny :
● Outlook = Overcast :
● Outlook = Rainy :
● Expected information for attribute:
Note: thisis normallyundefined.
info [2,3]=entropy 2 /5,3 /5=−2 /5 log 2/5−3 /5 log 3 /5=0.971bits
info [4,0 ]=entropy 1,0=−1 log 1−0 log 0=0 bits
info [2,3]=entropy 3 /5,2 /5=−3 /5 log 3/5−2 /5 log 2 /5=0.971bits
info [3,2] , [4,0] , [3,2]=5 /14×0.9714 /14×05 /14×0.971=0.693bits
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
75
Computing information gain
● Information gain: information before splitting – information after splitting
● Information gain for attributes from weather data:
gain(Outlook ) = 0.247 bitsgain(Temperature ) = 0.029 bitsgain(Humidity ) = 0.152 bitsgain(Windy ) = 0.048 bits
gain(Outlook ) = info([9,5]) – info([2,3],[4,0],[3,2])= 0.940 – 0.693= 0.247 bits
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
76
Continuing to split
gain(Temperature ) = 0.571 bits
gain(Humidity ) = 0.971 bits
gain(Windy ) = 0.020 bits
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
77
Final decision tree
● Note: not all leaves need to be pure; sometimes identical instances have different classes Splitting stops when data can’t be split any
further
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
78
Covering algorithms: Ruler Learners
● Convert decision tree into a rule set Straightforward, but rule set overly
complex More effective conversions are not trivial
● Instead, can generate rule set directly for each class in turn find rule set that
covers all instances in it(excluding instances not in the class)
● Called a covering approach: at each stage a rule is identified that
“covers” some of the instances
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
79
Example: generating a rule
If x > 1.2then class = a
If x > 1.2 and y > 2.6then class = a
If truethen class = a
● Possible rule set for class “b”:
● Could add more rules, get “perfect” rule set
If x 1.2 then class = bIf x > 1.2 and y 2.6 then class = b
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
80
Simple covering algorithm
● Generates a rule by adding tests that maximize rule’s accuracy
● Similar to situation in decision trees: problem of selecting an attribute to split on
But: decision tree inducer maximizes overall purity
● Each new test reducesrule’s coverage:
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
81
Selecting a test
● Goal: maximize accuracy t total number of instances covered by
rule p positive examples of the class covered
by rule t – p number of errors made by ruleSelect test that maximizes the ratio p/t
● We are finished when p/t = 1 or the set of instances can’t be split any further
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
82
Example: contact lens data
● Rule we seek:● Possible tests:
4/12Tear production rate = Normal
0/12Tear production rate = Reduced
4/12Astigmatism = yes
0/12Astigmatism = no
1/12Spectacle prescription = Hypermetrope
3/12Spectacle prescription = Myope
1/8Age = Presbyopic
1/8Age = Pre-presbyopic
2/8Age = Young
If ? then recommendation = hard
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
83
Modified rule and resulting data
● Rule with best test added:
● Instances covered by modified rule:
NoneReducedYesHypermetropePre-presbyopic NoneNormalYesHypermetropePre-presbyopic NoneReducedYesMyopePresbyopic
HardNormalYesMyopePresbyopicNoneReducedYesHypermetropePresbyopicNoneNormalYesHypermetropePresbyopic
HardNormalYesMyopePre-presbyopic
NoneReducedYesMyopePre-presbyopic
hardNormalYesHypermetropeYoungNoneReducedYesHypermetropeYoungHardNormalYesMyopeYoungNoneReducedYesMyopeYoung
Recommended lenses
Tear production rate
AstigmatismSpectacle prescription
Age
If astigmatism = yes then recommendation = hard
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
84
Further refinement
● Current state:
● Possible tests:
4/6Tear production rate = Normal
0/6Tear production rate = Reduced
1/6Spectacle prescription = Hypermetrope
3/6Spectacle prescription = Myope
1/4Age = Presbyopic
1/4Age = Pre-presbyopic
2/4Age = Young
If astigmatism = yes and ? then recommendation = hard
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
85
Modified rule and resulting data
● Rule with best test added:
● Instances covered by modified rule:
NoneNormalYesHypermetropePre-presbyopic HardNormalYesMyopePresbyopic
NoneNormalYesHypermetropePresbyopic
HardNormalYesMyopePre-presbyopic
hardNormalYesHypermetropeYoungHardNormalYesMyopeYoung
Recommended lenses
Tear production rate
AstigmatismSpectacle prescription
Age
If astigmatism = yes and tear production rate = normal then recommendation = hard
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
86
Further refinement● Current state:
● Possible tests:
● Tie between the first and the fourth test
We choose the one with greater coverage
1/3Spectacle prescription = Hypermetrope
3/3Spectacle prescription = Myope
1/2Age = Presbyopic
1/2Age = Pre-presbyopic
2/2Age = Young
If astigmatism = yes and tear production rate = normal and ?then recommendation = hard
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
87
The result
● Final rule:
● Second rule for recommending “hard lenses”:(built from instances not covered by first rule)
● These two rules cover all “hard lenses”: Process is repeated with other two classes
If astigmatism = yesand tear production rate = normaland spectacle prescription = myopethen recommendation = hard
If age = young and astigmatism = yesand tear production rate = normalthen recommendation = hard
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
88
Pseudo-code for PRISM
For each class C Initialize E to the instance set While E contains instances in class C Create a rule R with an empty left-hand side that predicts class C Until R is perfect (or there are no more attributes to use) do For each attribute A not mentioned in R, and each value v, Consider adding the condition A = v to the left-hand side of R Select A and v to maximize the accuracy p/t (break ties by choosing the condition with the largest p) Add A = v to R Remove the instances covered by R from E
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 4)
89
Separate and conquer
● Methods like PRISM (for dealing with one class) are separate-and-conquer algorithms:
First, identify a useful rule Then, separate out all the instances it
covers Finally, “conquer” the remaining
instances● Difference to divide-and-conquer
methods: Subset covered by rule doesn’t need to be
explored any further
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 6)
90
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 listvs. one rule set for each class
Other Approaches
• 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
– Can be used for classification as well as regression
• Neural Networks – Backproagation networks (multiplayer), Self-Organising Maps
(SOM), Radial Basis Function Networks (RBF N)
• Bayesian Learning
– Naiive Bayes, Bayesian clustering, Bayesian Nets• Hidden Markov Networks (HMNs)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
92
Credibility:Evaluating what’s been learned
● Issues: training, testing, tuning● Predicting performance: confidence limits● Holdout, cross-validation, bootstrap● Comparing schemes: the t-test● Predicting probabilities: loss functions● Cost-sensitive measures● Evaluating numeric prediction● The Minimum Description Length principle
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
93
Evaluation: the key to success
● How predictive is the model we learned?● Error on the training data is not a good
indicator of performance on future data Otherwise 1-NN would be the optimum
classifier!● Simple solution that can be used if lots of
(labeled) data is available: Split data into training and test set
● However: (labeled) data is usually limited More sophisticated techniques need to be
used
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
94
Issues in evaluation
● Statistical reliability of estimated differences in performance ( significance tests)
● Choice of performance measure: Number of correct classifications Accuracy of probability estimates Error in numeric predictions
● Costs assigned to different types of errors Many practical applications involve costs
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
95
Training and testing I
● Natural performance measure for classification problems: error rate
Success: instance’s class is predicted correctly
Error: instance’s class is predicted incorrectly
Error rate: proportion of errors made over the whole set of instances
● Resubstitution error: error rate obtained from training data
● Resubstitution error is (hopelessly) optimistic!
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
96
Training and testing II
● Test set: independent instances that have played no part in formation of classifier● Assumption: both training data and test data are
representative samples of the underlying problem● Test and training data may differ in nature
● Example: classifiers built using customer data from two different towns A and B● To estimate performance of classifier from town A in
completely new town, test it on data from B
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
97
Note on parameter tuning
● It is important that the test data is not used in any way to create the classifier
● Some learning schemes operate in two stages:● Stage 1: build the basic structure● Stage 2: optimize parameter settings
● The test data can’t be used for parameter tuning!
● Proper procedure uses three sets: training data, validation data, and test data● Validation data is used to optimize parameters
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
98
Making the most of the data
● Once evaluation is complete, all the data can be used to build the final classifier
● Generally, the larger the training data the better the classifier (but returns diminish)
● The larger the test data the more accurate the error estimate
● Holdout procedure: method of splitting original data into training and test set● Dilemma: ideally both training set and test
set should be large!
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
99
Predicting performance
● Assume the estimated error rate is 25%. How close is this to the true error rate?
Depends on the amount of test data● Prediction is just like tossing a (biased!)
coin “Head” is a “success”, “tail” is an “error”
● In statistics, a succession of independent events like this is called a Bernoulli process
Statistical theory provides us with confidence intervals for the true underlying proportion
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
100
Confidence intervals
● We can say: p lies within a certain specified interval with a certain specified confidence
● Example: S=750 successes in N=1000 trials● Estimated success rate: 75%● How close is this to true success rate p?
● Answer: with 80% confidence p [73.2,76.7]
● Another example: S=75 and N=100● Estimated success rate: 75%● With 80% confidence p[69.1,80.1]
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
101
Mean and variance
● Mean and variance for a Bernoulli trial:p, p (1–p)
● Expected success rate f=S/N● Mean and variance for f : p, p (1–p)/N● For large enough N, f follows a Normal distribution
● c% confidence interval [–z X z] for random variable with 0 mean is given by:
● With a symmetric distribution:
Pr [−z≤X≤z ]=c
Pr [−z≤X≤z ]=1−2×Pr [x≥z ]
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
102
Confidence limits● Confidence limits for the normal distribution
with 0 mean and a variance of 1:
● Thus:
● To use this we have to reduce our random variable f to have 0 mean and unit variance
0.2540%
0.8420%
1.2810%
1.655%
2.33
2.58
3.09
z
1%
0.5%
0.1%
Pr[X z]
–1 0 1 1.65
Pr [−1.65≤X≤1.65 ]=90 %
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
103
Transforming f
● Transformed value for f :
(i.e. subtract the mean and divide by the standard deviation)
● Resulting equation:
● Solving for p :
f−pp 1−p/N
Pr [−z≤ f−pp 1−p/N≤z ]=c
p=f z2
2N∓z fN−
f 2
Nz2
4N2 /1 z2
N
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
104
Examples
● f = 75%, N = 1000, c = 80% (so that z = 1.28):
● f = 75%, N = 100, c = 80% (so that z = 1.28):
● Note that normal distribution assumption is only valid for large N (i.e. N > 100)
● f = 75%, N = 10, c = 80% (so that z = 1.28):
(should be taken with a grain of salt)
p∈[0.732,0 .767 ]
p∈[0.691,0 .801 ]
p∈[0.549,0 .881 ]
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
105
Holdout estimation
● What to do if the amount of data is limited?
● The holdout method reserves a certain amount for testing and uses the remainder for training
Usually: one third for testing, the rest for training
● Problem: the samples might not be representative
Example: class might be missing in the test data
● Advanced version uses stratification Ensures that each class is represented with
approximately equal proportions in both subsets
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
106
Repeated holdout method
● Holdout estimate can be made more reliable by repeating the process with different subsamples
In each iteration, a certain proportion is randomly selected for training (possibly with stratificiation)
The error rates on the different iterations are averaged to yield an overall error rate
● This is called the repeated holdout method● Still not optimum: the different test sets
overlap Can we prevent overlapping?
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
107
Cross-validation
● Cross-validation avoids overlapping test sets
First step: split data into k subsets of equal size
Second step: use each subset in turn for testing, the remainder for training
● Called k-fold cross-validation● Often the subsets are stratified before
the cross-validation is performed● The error estimates are averaged to
yield an overall error estimate
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
108
More on cross-validation
● Standard method for evaluation: stratified ten-fold cross-validation
● Why ten? Extensive experiments have shown that this is
the best choice to get an accurate estimate There is also some theoretical evidence for
this● Stratification reduces the estimate’s
variance● Even better: repeated stratified cross-
validation E.g. ten-fold cross-validation is repeated ten
times and results are averaged (reduces the variance)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
109
Leave-One-Out cross-validation
● Leave-One-Out:a particular form of cross-validation:
Set number of folds to number of training instances
I.e., for n training instances, build classifier n times
● Makes best use of the data● Involves no random subsampling ● Very computationally expensive
(exception: NN)
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
110
Leave-One-Out-CV and stratification
● Disadvantage of Leave-One-Out-CV: stratification is not possible
It guarantees a non-stratified sample because there is only one instance in the test set!
● Extreme example: random dataset split equally into two classes
Best inducer predicts majority class 50% accuracy on fresh data Leave-One-Out-CV estimate is 100%
error!
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
111
The bootstrap● CV uses sampling without replacement
● The same instance, once selected, can not be selected again for a particular training/test set
● The bootstrap uses sampling with replacement to form the training set● Sample a dataset of n instances n times with
replacement to form a new dataset of n instances● Use this data as the training set● Use the instances from the original
dataset that don’t occur in the newtraining set for testing
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
112
The 0.632 bootstrap
● Also called the 0.632 bootstrap A particular instance has a probability of
1–1/n of not being picked Thus its probability of ending up in the
test data is:
This means the training data will contain approximately 63.2% of the instances
1− 1n
n≈e−1≈0.368
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
113
Estimating error with the bootstrap
● The error estimate on the test data will be very pessimistic
Trained on just ~63% of the instances● Therefore, combine it with the
resubstitution error:
● The resubstitution error gets less weight than the error on the test data
● Repeat process several times with different replacement samples; average the results
err=0.632×etest instances0.368×etraining_instances
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
114
More on the bootstrap
● Probably the best way of estimating performance for very small datasets
● However, it has some problems Consider the random dataset from above A perfect memorizer will achieve
0% resubstitution error and ~50% error on test data
Bootstrap estimate for this classifier:
True expected error: 50%err=0.632×50%0.368×0%=31.6%
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
115
Comparing data mining schemes
● Frequent question: which of two learning schemes performs better?
● Note: this is domain dependent!● Obvious way: compare 10-fold CV estimates● Generally sufficient in applications (we don't
loose if the chosen method is not truly better)
● However, what about machine learning research?
Need to show convincingly that a particular method works better
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
116
Comparing schemes II• Want to show that scheme A is better than
scheme B in a particular domain– For a given amount of training data– On average, across all possible training sets
• Let's assume we have an infinite amount of data from the domain:
– Sample infinitely many dataset of specified size– Obtain cross-validation estimate on each dataset
for each scheme– Check if mean accuracy for scheme A is better
than mean accuracy for scheme B
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
117
Paired t-test● In practice we have limited data and a limited
number of estimates for computing the mean● Student’s t-test tells whether the means of
two samples are significantly different● In our case the samples are cross-validation
estimates for different datasets from the domain
● Use a paired t-test because the individual samples are paired
The same CV is applied twiceWilliam Gosset
Born: 1876 in Canterbury; Died: 1937 in Beaconsfield, England
Obtained a post as a chemist in the Guinness brewery in Dublin in 1899.
Invented the t-test to handle small samples for quality control in brewing.
Wrote under the name "Student".
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
118
Distribution of the means
● x1 x2 … xk and y1 y2 … yk are the 2k samples for the k different datasets
● mx and my are the means● With enough samples, the mean of a set of
independent samples is normally distributed
● Estimated variances of the means are x
2/k and y2/k
● If x and y are the true means then
are approximately normally distributed withmean 0, variance 1
mx−x
x2/k
my−y
y2/k
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
119
Student’s distribution
● With small samples (k < 100) the mean follows Student’s distribution with k–1 degrees of freedom
● Confidence limits:
0.8820%
1.3810%
1.835%
2.82
3.25
4.30
z
1%
0.5%
0.1%
Pr[X z]
0.8420%
1.2810%
1.655%
2.33
2.58
3.09
z
1%
0.5%
0.1%
Pr[X z]
9 degrees of freedom normal distribution
Assumingwe have10 estimates
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
120
Distribution of the differences
● Let md = mx – my
● The difference of the means (md) also has a Student’s distribution with k–1 degrees of freedom
● Let d2 be the variance of the difference
● The standardized version of md is called the t-statistic:
● We use t to perform the t-test
t= md
d2/k
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
121
Performing the test
• Fix a significance level • If a difference is significant at the % level,
there is a (100-)% chance that the true means differ
• Divide the significance level by two because the test is two-tailed• I.e. the true difference can be +ve or – ve
• Look up the value for z that corresponds to /2
• If t –z or t z then the difference is significant• I.e. the null hypothesis (that the difference is
zero) can be rejected
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
122
Unpaired observations
● If the CV estimates are from different datasets, they are no longer paired(or maybe we used k -fold CV for one scheme, and j -fold CV for the other one)
● Then we have to use an un paired t-test with min(k , j) – 1 degrees of freedom
● The t-statistic becomes:
x2
k y
2
j
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
123
Dependent estimates● We assumed that we have enough data to
create several datasets of the desired size ● Need to re-use data if that's not the case
E.g. running cross-validations with different randomizations on the same data
● Samples become dependent insignificant differences can become significant
● A heuristic test is the corrected resampled t-test:
Assume we use the repeated hold-out method, with n1 instances for training and n2 for testing
New test statistic is:t=md
1k
n2
n1d
2
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
124
Predicting probabilities
● Performance measure so far: success rate● Also called 0-1 loss function:
● Most classifiers produces class probabilities● Depending on the application, we might
want to check the accuracy of the probability estimates
● 0-1 loss is not the right thing to use in those cases
∑i {0 if prediction is correct1 if prediction is incorrect
}
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
125
Quadratic loss function
● p1 … pk are probability estimates for an instance
● c is the index of the instance’s actual class
● a1 … ak = 0, except for ac which is 1
● Quadratic loss is:
● Want to minimize
● Can show that this is minimized when pj = pj
*, the true probabilities
∑ j p j−a j2=∑ j!=c p j
2a−pc2
E p j−a j2
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
126
Informational loss function
● The informational loss function is –log(pc),where c is the index of the instance’s actual class
● Number of bits required to communicate the actual class
● Let p1* … pk
* be the true class probabilities
● Then the expected value for the loss function is:
● Justification: minimized when pj = pj*
● Difficulty: zero-frequency problem
−p1∗ log2p1−...−pk
∗ log2pk
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
127
Discussion● Which loss function to choose?
Both encourage honesty Quadratic loss function takes into account
all class probability estimates for an instance
Informational loss focuses only on the probability estimate for the actual class
Quadratic loss is bounded: it can never exceed 2
Informational loss can be infinite
Informational loss is related to MDL principle [later]
1∑ j p j2
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
128
Counting the cost
● In practice, different types of classification errors often incur different costs
● Examples: Terrorist profiling
● “Not a terrorist” correct 99.99% of the time Loan decisions Oil-slick detection Fault diagnosis Promotional mailing
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
129
Counting the cost
● The confusion matrix:
There are many other types of cost!● E.g.: cost of collecting training data
Actual class True negativeFalse positiveNo
False negative
True positiveYes
NoYes
Predicted class
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
130
Aside: the kappa statistic• Two confusion matrices for a 3-class problem:
actual predictor (left) vs. random predictor (right)
• Number of successes: sum of entries in diagonal (D)
• Kappa statistic:measures relative improvement over random predictor
Dobserved−Drandom
Dperfect−Drandom
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
131
Classification with costs
• Two cost matrices:
• Success rate is replaced by average cost per prediction
– Cost is given by appropriate entry in the cost matrix
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
132
Cost-sensitive classification• Can take costs into account when making
predictions– Basic idea: only predict high-cost class when
very confident about prediction
• Given: predicted class probabilities– Normally we just predict the most likely class– Here, we should make the prediction that
minimizes the expected cost• Expected cost: dot product of vector of class
probabilities and appropriate column in cost matrix• Choose column (class) that minimizes expected cost
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
133
Cost-sensitive learning● So far we haven't taken costs into account at training time
● Most learning schemes do not perform cost-sensitive learning● They generate the same classifier no matter
what costs are assigned to the different classes
● Example: standard decision tree learner● Simple methods for cost-sensitive learning:● Resampling of instances according to costs● Weighting of instances according to costs
● Some schemes can take costs into account by varying a parameter, e.g. naïve Bayes
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
134
Lift charts
● In practice, costs are rarely known● Decisions are usually made by
comparing possible scenarios● Example: promotional mailout to
1,000,000 households• Mail to all; 0.1% respond (1000)• Data mining tool identifies subset of
100,000 most promising, 0.4% of these respond (400)40% of responses for 10% of cost may pay off
• Identify subset of 400,000 most promising, 0.2% respond (800)
● A lift chart allows a visual comparison
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
135
Generating a lift chart
● Sort instances according to predicted probability of being positive:
● x axis is sample sizey axis is number of true positives
………
Yes0.884
No0.933
Yes0.932
Yes0.951
Actual classPredicted probability
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
136
A hypothetical lift chart
40% of responsesfor 10% of cost 80% of responses
for 40% of cost
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
137
ROC curves
● ROC curves are similar to lift charts Stands for “receiver operating
characteristic” Used in signal detection to show tradeoff
between hit rate and false alarm rate over noisy channel
● Differences to lift chart: y axis shows percentage of true positives in
sample rather than absolute number
x axis shows percentage of false positives in sample rather than sample size
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
138
A sample ROC curve
● Jagged curve—one set of test data● Smooth curve—use cross-validation
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
139
Cross-validation and ROC curves
● Simple method of getting a ROC curve using cross-validation:
Collect probabilities for instances in test folds
Sort instances according to probabilities● This method is implemented in WEKA● However, this is just one possibility
Another possibility is to generate an ROC curve for each fold and average them
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
140
ROC curves for two schemes
● For a small, focused sample, use method A● For a larger one, use method B● In between, choose between A and B with appropriate
probabilities
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
141
The convex hull
● Given two learning schemes we can achieve any point on the convex hull!
● TP and FP rates for scheme 1: t1 and f1● TP and FP rates for scheme 2: t2 and f2● If scheme 1 is used to predict 100× q % of the cases and scheme 2 for the rest, then● TP rate for combined scheme:
q × t1 + (1-q) × t2● FP rate for combined scheme:
q × f1+(1-q) × f2
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
142
More measures...
● Percentage of retrieved documents that are relevant: precision=TP/(TP+FP)
● Percentage of relevant documents that are returned:
recall =TP/(TP+FN)● Precision/recall curves have hyperbolic shape● Summary measures: average precision at 20%, 50%
and 80% recall (three-point average recall)● F-measure=(2recallprecision)/(recall+precision)● sensitivity × specificity = (TP / (TP + FN)) × (TN / (TP
+ TN))● Area under the ROC curve (AUC):
probability that randomly chosen positive instance is ranked above randomly chosen negative one
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
143
Summary of some measures
ExplanationPlotDomain
TP/(TP+FN)
TP/(TP+FP)
Recall
Precision
Information retrieval
Recall-precision curve
TP/(TP+FN)
FP/(FP+TN)
TP rate
FP rate
Communications
ROC curve
TP(TP+FP)/(TP+FP+TN+FN)
TP
Subset size
MarketingLift chart
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
144
Cost curves• Cost curves plot expected costs directly
• Example for case with uniform costs (i.e. error):
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
145
Cost curves: example with costs
Normalized expected cost=fn×pc[+]fp×1−pc[+]
Probability cost functionpc [+]= p [+]C[+|-]p [+]C[+|-]p [-]C[-|+]
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
146
Evaluating numeric prediction
● Same strategies: independent test set, cross-validation, significance tests, etc.
● Difference: error measures● Actual target values: a1 a2 …an
● Predicted target values: p1 p2 … pn
● Most popular measure: mean-squared error
● Easy to manipulate mathematically
p1−a12...pn−an
2
n
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
147
Other measures
● The root mean-squared error :
● The mean absolute error is less sensitive to outliers than the mean-squared error:
● Sometimes relative error values are more appropriate (e.g. 10% for an error of 50 when predicting 500)
p1−a1 2...pn−an
2
n
∣p1−a1∣...∣pn−an∣n
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
148
Improvement on the mean
● How much does the scheme improve on simply predicting the average?
● The relative squared error is:
● The relative absolute error is:
p1−a12...pn−an
2
a−a12...a−an
2
∣p1−a1∣...∣pn−an∣∣a−a1∣...∣a−an∣
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
149
Correlation coefficient
● Measures the statistical correlation between the predicted values and the actual values
● Scale independent, between –1 and +1● Good performance leads to large values!
SPA
SPSA
SP=∑i pi−p
2
n−1 SA=∑i ai−a
2
n−1SPA=
∑ i pi−p a i−a n−1
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
150
Which measure?● Best to look at all of them● Often it doesn’t matter● Example:
0.910.890.880.88Correlation coefficient
30.4%34.8%40.1%43.1%Relative absolute error
35.8%39.4%57.2%42.2%Root rel squared error
29.233.438.541.3Mean absolute error
57.463.391.767.8Root mean-squared error
DCBA
● D best● C second-
best● A, B arguable
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
151
The MDL principle● MDL stands for minimum description length
● The description length is defined as: space required to describe a theory
+ space required to describe the theory’s mistakes
● In our case the theory is the classifier and the mistakes are the errors on the training data
● Aim: we seek a classifier with minimal DL
● MDL principle is a model selection criterion
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
152
Model selection criteria● Model selection criteria attempt to find a good compromise between:● The complexity of a model● Its prediction accuracy on the training data
● Reasoning: a good model is a simple model that achieves high accuracy on the given data
● Also known as Occam’s Razor :the best theory is the smallest onethat describes all the facts William of Ockham, born in the village of Ockham in Surrey
(England) about 1285, was the most influential philosopher of
the 14th century and a controversial theologian.
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
153
Elegance vs. errors
● Theory 1: very simple, elegant theory that explains the data almost perfectly
● Theory 2: significantly more complex theory that reproduces the data without mistakes
● Theory 1 is probably preferable● Classical example: Kepler’s three laws
on planetary motion Less accurate than Copernicus’s latest
refinement of the Ptolemaic theory of epicycles
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
154
MDL and compression● MDL principle relates to data compression:● The best theory is the one that compresses
the data the most● I.e. to compress a dataset we generate a
model and then store the model and its mistakes
● We need to compute(a) size of the model, and(b) space needed to encode the errors
● (b) easy: use the informational loss function
● (a) need a method to encode the model
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
155
MDL and Bayes’s theorem
● L[T]=“length” of the theory● L[E|T]=training set encoded wrt the
theory● Description length= L[T] + L[E|T]● Bayes’s theorem gives a posteriori
probability of a theory given the data:
● Equivalent to:
constant
Pr [T|E]=Pr [E|T]Pr [T]Pr [E]
−logPr [T|E]=−logPr [E|T]−logPr [T ]logPr [E ]
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
156
MDL and MAP
● MAP stands for maximum a posteriori probability
● Finding the MAP theory corresponds to finding the MDL theory
● Difficult bit in applying the MAP principle: determining the prior probability Pr[T] of the theory
● Corresponds to difficult part in applying the MDL principle: coding scheme for the theory
● I.e. if we know a priori that a particular theory is more likely we need fewer bits to encode it
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
157
Discussion of MDL principle
● Advantage: makes full use of the training data when selecting a model
● Disadvantage 1: appropriate coding scheme/prior probabilities for theories are crucial
● Disadvantage 2: no guarantee that the MDL theory is the one which minimizes the expected error
● Note: Occam’s Razor is an axiom!● Epicurus’s principle of multiple explanations:
keep all theories that are consistent with the data
Data Mining: Practical Machine Learning Tools and Techniques (Chapter 5)
158
MDL and clustering
● Description length of theory:bits needed to encode the clusters
e.g. cluster centers● Description length of data given theory:
encode cluster membership and position relative to cluster
e.g. distance to cluster center● Works if coding scheme uses less code
space for small numbers than for large ones
● With nominal attributes, must communicate probability distributions for each cluster