bibliography data mining / intelligent data analysis ...data mining / intelligent data analysis...

135
Data Mining / Intelligent Data Analysis Christian Borgelt Dept. of Mathematics / Dept. of Computer Sciences Paris Lodron University of Salzburg Hellbrunner Straße 34, 5020 Salzburg, Austria [email protected] [email protected] http://www.borgelt.net/ Christian Borgelt Data Mining / Intelligent Data Analysis 1 Bibliography Textbook Springer-Verlag Heidelberg, DE 2010 (in English) picture not available in online version Textbook, 4th ed. Morgan Kaufmann Burlington, CA, USA 2016 (in English) picture not available in online version Textbook, 3rd ed. Morgan Kaufmann Burlington, CA, USA 2011 (in English) Christian Borgelt Data Mining / Intelligent Data Analysis 2 Data Mining / Intelligent Data Analysis Introduction Data and Knowledge Characteristics and Differences of Data and Knowledge Quality Criteria for Knowledge Example: Tycho Brahe and Johannes Kepler Knowledge Discovery and Data Mining How to Find Knowledge? The Knowledge Discovery Process (KDD Process) Data Analysis / Data Mining Tasks Data Analysis / Data Mining Methods Summary Christian Borgelt Data Mining / Intelligent Data Analysis 3 Introduction Today every enterprise uses electronic information processing systems. Production and distribution planning Stock and supply management Customer and personnel management Usually these systems are coupled with a database system (e.g. databases of customers, suppliers, parts etc.). Every possible individual piece of information can be retrieved. However: Data alone are not enough. In a database one may “not see the wood for the trees”. General patterns, structures, regularities go undetected. Often such patterns can be exploited to increase turnover (e.g. joint sales in a supermarket). Christian Borgelt Data Mining / Intelligent Data Analysis 4

Upload: others

Post on 03-Oct-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Data Mining / Intelligent Data Analysis

Christian Borgelt

Dept. of Mathematics / Dept. of Computer SciencesParis Lodron University of Salzburg

Hellbrunner Straße 34, 5020 Salzburg, Austria

[email protected]

[email protected]

http://www.borgelt.net/

Christian Borgelt Data Mining / Intelligent Data Analysis 1

Bibliography

TextbookSpringer-Verlag

Heidelberg, DE 2010(in English)

picture not availablein online version

Textbook, 4th ed.Morgan Kaufmann

Burlington, CA, USA 2016(in English)

picture not availablein online version

Textbook, 3rd ed.Morgan Kaufmann

Burlington, CA, USA 2011(in English)

Christian Borgelt Data Mining / Intelligent Data Analysis 2

Data Mining / Intelligent Data Analysis

• Introduction

• Data and Knowledge

◦ Characteristics and Differences of Data and Knowledge

◦ Quality Criteria for Knowledge

◦ Example: Tycho Brahe and Johannes Kepler

• Knowledge Discovery and Data Mining

◦ How to Find Knowledge?

◦ The Knowledge Discovery Process (KDD Process)

◦ Data Analysis / Data Mining Tasks

◦ Data Analysis / Data Mining Methods

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 3

Introduction

• Today every enterprise uses electronic information processing systems.

◦ Production and distribution planning

◦ Stock and supply management

◦ Customer and personnel management

• Usually these systems are coupled with a database system(e.g. databases of customers, suppliers, parts etc.).

• Every possible individual piece of information can be retrieved.

• However: Data alone are not enough.

◦ In a database one may “not see the wood for the trees”.

◦ General patterns, structures, regularities go undetected.

◦ Often such patterns can be exploited to increase turnover(e.g. joint sales in a supermarket).

Christian Borgelt Data Mining / Intelligent Data Analysis 4

Page 2: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Data

Examples of Data

• “Columbus discovered America in 1492.”

• “Mr Jones owns a Volkswagen Golf.”

Characteristics of Data

• refer to single instances(single objects, persons, events, points in time etc.)

• describe individual properties

• are often available in huge amounts (databases, archives)

• are usually easy to collect or to obtain(e.g. cash registers with scanners in supermarkets, Internet)

• do not allow us to make predictions

Christian Borgelt Data Mining / Intelligent Data Analysis 5

Knowledge

Examples of Knowledge

• “All masses attract each other.”

• “Every day at 5 pm there runs a train from Hannover to Berlin.”

Characteristic of Knowledge

• refers to classes of instances(sets of objects, persons, points in time etc.)

• describes general patterns, structure, laws, principles etc.

• consists of as few statements as possible (this is an objective!)

• is usually difficult to find or to obtain(e.g. natural laws, education)

• allows us to make predictions

Christian Borgelt Data Mining / Intelligent Data Analysis 6

Criteria to Assess Knowledge

• Not all statements are equally important, equally substantial, equally useful.

⇒ Knowledge must be assessed.

Assessment Criteria

• Correctness (probability, success in tests)

• Generality (range of validity, conditions of validity)

• Usefulness (relevance, predictive power)

• Comprehensibility (simplicity, clarity, parsimony)

• Novelty (previously unknown, unexpected)

Priority

• Science: correctness, generality, simplicity

• Economy: usefulness, comprehensibility, novelty

Christian Borgelt Data Mining / Intelligent Data Analysis 7

Tycho Brahe (1546–1601)

Who was Tycho Brahe?

• Danish nobleman and astronomer

• In 1582 he built an observatory on the island of Ven (32 km NE of Copenhagen).

• He determined the positions of the sun, the moon and the planets(accuracy: one angle minute, without a telescope!).

• He recorded the motions of the celestial bodies for several years.

Brahe’s Problem

• He could not summarize the data he had collectedin a uniform and consistent scheme.

• The planetary system he developed (the so-called Tychonic system)did not stand the test of time.

Christian Borgelt Data Mining / Intelligent Data Analysis 8

Page 3: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Johannes Kepler (1571–1630)

Who was Johannes Kepler?

• German astronomer and assistant of Tycho Brahe.

• He advocated the Copernican planetary system.

• He tried all his life to find the laws that govern the motion of the planets.

• He started from the data that Tycho Brahe had collected.

Kepler’s Laws

1. Each planet moves around the sun in an ellipse, with the sun at one focus.

2. The radius vector from the sun to the planet sweeps out equal areasin equal intervals of time.

3. The squares of the periods of any two planets are proportional to the cubes

of the semi-major axes of their respective orbits: T ∼ a32 .

Christian Borgelt Data Mining / Intelligent Data Analysis 9

How to find Knowledge?

We do not know any universal method to discover knowledge.

Problems

• Today huge amounts of data are available in databases.

We are drowning in information,but starving for knowledge. John Naisbett

• Manual methods of analysis have long ceased to be feasible.

• Simple aids (e.g. displaying data in charts) are too limited.

Attempts to Solve the Problems

• Intelligent Data Analysis

• Knowledge Discovery in Databases

• Data Mining

Christian Borgelt Data Mining / Intelligent Data Analysis 10

Knowledge Discovery and Data Mining

Christian Borgelt Data Mining / Intelligent Data Analysis 11

Knowledge Discovery and Data Mining

As a response to the challenge raised by the growing volume of data a new researcharea has emerged, which is usually characterized by one of the following phrases:

• Knowledge Discovery in Databases (KDD)

Usual characterization:

KDD is the non-trivial process of identifying valid, novel, potentially useful,and ultimately understandable patterns in data. [Fayyad et al. 1996]

• Data Mining (DM)

◦ Data mining is that step of the knowledge discovery processin which data analysis methods are applied to find interesting patterns.

◦ It can be characterized by a set of types of tasks that have to be solved.

◦ It uses methods from a variety of research areas.(statistics, databases, machine learning, artificial intelligence, soft computing etc.)

Christian Borgelt Data Mining / Intelligent Data Analysis 12

Page 4: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

The Knowledge Discovery Process (KDD Process)

Preliminary Steps

• estimation of potential benefit

• definition of goals, feasibility study

Main Steps

• check data availability, data selection, if necessary: data collection

• preprocessing (60–80% of total overhead)

◦ unification and transformation of data formats

◦ data cleaning (error correction, outlier detection, imputation of missing values)

◦ reduction / focusing (sample drawing, feature selection, prototype generation)

• Data Mining (using a variety of methods)

• visualization (also in parallel to preprocessing, data mining, and interpretation)

• interpretation, evaluation, and test of results

• deployment and documentation

Christian Borgelt Data Mining / Intelligent Data Analysis 13

The Knowledge Discovery Process (KDD Process)

pictures not available in online version

Typical depictions of the KDD Process

top: [Fayyad et al. 1996]Knowledge Discovery and Data Mining:Towards a Unifying Framework

right: CRISP-DM [Chapman et al. 1999]CRoss Industry Standard Processfor Data Mining

Christian Borgelt Data Mining / Intelligent Data Analysis 14

Data Analysis / Data Mining Tasks

• ClassificationIs this customer credit-worthy?

• Segmentation, ClusteringWhat groups of customers do I have?

• Concept DescriptionWhich properties characterize fault-prone vehicles?

• Prediction, Trend AnalysisWhat will the exchange rate of the dollar be tomorrow?

• Dependence/Association AnalysisWhich products are frequently bought together?

• Deviation AnalysisAre there seasonal or regional variations in turnover?

Christian Borgelt Data Mining / Intelligent Data Analysis 15

Data Analysis / Data Mining Methods 1

• Classical Statistics(charts, parameter estimation, hypothesis testing, model selection, regression)

tasks: classification, prediction, trend analysis

• Bayes Classifiers(probabilistic classification, naive and full Bayes classifiers, Bayesian network classifiers)

tasks: classification, prediction

• Decision and Regression Trees / Random Forests(top down induction, attribute selection measures, pruning, random forests)

tasks: classification, prediction

• k-nearest Neighbor / Case-based Reasoning(lazy learning, similarity measures, data structures for fast search)

tasks: classification, prediction

Christian Borgelt Data Mining / Intelligent Data Analysis 16

Page 5: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Data Analysis / Data Mining Methods 2

• Artificial Neural Networks(multilayer perceptrons, radial basis function networks, learning vector quantization)

tasks: classification, prediction, clustering

• Cluster Analysis(k-means and fuzzy clustering, Gaussian mixtures, hierarchical agglomerative clustering)

tasks: segmentation, clustering

• Association Rule Induction(frequent item set mining, rule generation)

tasks: association analysis

• Inductive Logic Programming(rule generation, version space, search strategies, declarative bias)

tasks: classification, association analysis, concept description

Christian Borgelt Data Mining / Intelligent Data Analysis 17

Statistics

Christian Borgelt Data Mining / Intelligent Data Analysis 18

Statistics

• Descriptive Statistics

◦ Tabular and Graphical Representations

◦ Characteristic Measures

◦ Principal Component Analysis

• Inductive Statistics

◦ Parameter Estimation(point and interval estimation, finding estimators)

◦ Hypothesis Testing(parameter test, goodness-of-fit test, dependence test)

◦ Model Selection(information criteria, minimum description length)

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 19

Statistics: Introduction

Statistics is the art to collect, to display, to analyze, and to interpret datain order to gain new knowledge.

“Applied Statistics” [Lothar Sachs 1999]

[...] statistics, that is, the mathematical treatment of reality, [...]

Hannah Arendt [1906–1975] in “The Human Condition” 1958

There are three kinds of lies: lies, damned lies, and statistics.

Benjamin Disraeli [1804–1881] (attributed by Mark Twain, but disputed)

Statistics, n. Exactly 76.4% of all statistics (including this one) are inventedon the spot. However, in 83% of cases it is inappropriate to admit it.

The Devil’s IT Dictionary

Christian Borgelt Data Mining / Intelligent Data Analysis 20

Page 6: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Basic Notions

• Object, CaseData describe objects, cases, persons etc.

• (Random) SampleThe objects or cases described by a data set is called a sample,their number is the sample size.

• AttributeObjects and cases are described by attributes,patients in a hospital, for example, by age, sex, blood pressure etc.

• (Attribute) ValueAttributes have different possible values.The age of a patient, for example, is a non-negative number.

• Sample ValueThe value an attribute has for an object in the sample is called sample value.

Christian Borgelt Data Mining / Intelligent Data Analysis 21

Scale Types / Attribute Types

Scale Type Possible Operations Examples

nominal test for equality sex/gender(categorical, qualitative) blood group

ordinal test for equality exam grade(rank scale, comparative) greater/less than wind strength

metric test for equality length(interval scale, quantitative) greater/less than weight

difference timemaybe ratio temperature

• Nominal scales are sometimes divided into dichotomic (binary, two values)and polytomic (more than two values).

• Metric scales may or may not allow us to form a ratio of values:weight and length do, temperature (in ◦C) does not.time as duration does, time as calender time does not.

• Counts may be considered as a special type (e.g. number of children).

Christian Borgelt Data Mining / Intelligent Data Analysis 22

Descriptive Statistics

Christian Borgelt Data Mining / Intelligent Data Analysis 23

Tabular Representations: Frequency Table

• Given data set: ~x = (3, 4, 3, 2, 5, 3, 1, 2, 4, 3, 3, 4, 4, 1, 5, 2, 2, 3, 5, 3, 2, 4, 3, 2, 3)

ak hk rk∑ki=1 hi

∑ki=1 ri

1 2 225 = 0.08 2 2

25 = 0.08

2 6 625 = 0.24 8 8

25 = 0.32

3 9 925 = 0.36 17 17

25 = 0.68

4 5 525 = 0.20 22 22

25 = 0.88

5 3 325 = 0.12 25 25

25 = 1.00

• Absolute Frequency hk (frequency of an attribute value ak in the sample).

• Relative Frequency rk =hkn , where n is the sample size (here n = 25).

• Cumulated Absolute/Relative Frequency∑ki=1 hi and

∑ki=1 ri.

Christian Borgelt Data Mining / Intelligent Data Analysis 24

Page 7: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Tabular Representations: Contingency Tables

• Frequency tables for two or more attributes are called contingency tables.

• They contain the absolute or relative frequency of value combinations.

a1 a2 a3 a4∑

b1 8 3 5 2 18b2 2 6 1 3 12b3 4 1 2 7 14∑

14 10 8 12 44

• A contingency table may also contain the marginal frequencies,i.e., the frequencies of the values of individual attributes.

• Contingency tables for a higher number of dimensions (≥ 4)may be difficult to read.

Christian Borgelt Data Mining / Intelligent Data Analysis 25

Graphical Representations: Pole and Bar Chart

• Numbers, which may be, for example, the frequencies of attribute valuesare represented by the lengths of poles/sticks (left) or the height of bars (right).

10

5

0

0.4

0.3

0.2

0.1

0.01 2 3 4 5

10

5

0

0.4

0.3

0.2

0.1

0.01 2 3 4 5

• Bar charts are the most frequently used and most comprehensible wayof displaying absolute frequencies.

• A wrong impression can result if the vertical scale does not start at 0(for frequencies or other absolute numbers).

Christian Borgelt Data Mining / Intelligent Data Analysis 26

Frequency Polygon and Line Chart

• Frequency polygon: the ends of the poles of a pole chart are connected by lines.(Numbers are still represented by lengths.)

10

5

0

0.4

0.3

0.2

0.1

0.01 2 3 4 5 0 1 2 3 4

0

1

2

3

4

x

y bluered

lines

• If the attribute values on the horizontal axis are not ordered,connecting the ends of the poles does not make sense.

• Line charts are frequently used to display time series.

Christian Borgelt Data Mining / Intelligent Data Analysis 27

Area and Volume Charts

• Numbers may also be represented by geometric quantities other than lengths,like areas or volumes.

• Area and volume charts are usually less comprehensible than bar charts,because humans have more difficulties to compare and assess the relative sizeof areas and especially of volumes than lengths.(exception: the represented numbers describe areas or volumes)

12 3

4 5 1 2 3 4 5

• Sometimes the height of a two- or three-dimensional object is usedto represent a number. The diagram then conveys a misleading impression.

Christian Borgelt Data Mining / Intelligent Data Analysis 28

Page 8: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Pie and Stripe Charts

• Relative numbers may be represented by angles or sections of a stripe.

Pie Chart

Stripe Chart

1

2

3

4

5

1 2 3 4 5

Mosaic Chart

• Mosaic charts can be used to display contingency tables.

• More than two attributes are possible, but then separation distances and colormust support the visualization to keep it comprehensible.

Christian Borgelt Data Mining / Intelligent Data Analysis 29

Histograms

• Intuitively: Histograms are frequency bar charts for metric data.

• However: Since there are so many different values,values have to be grouped in order to arrive a proper representation.

Most common approach: form equally sized intervals (so-called bins)and count the frequency of sample values inside each interval.

• Attention: Depending on the size and the position of the binsthe histogram may look considerably different.

• In sketches often only a rough outline of a histogram is drawn:

Christian Borgelt Data Mining / Intelligent Data Analysis 30

Histograms: Number of Bins

[18-28] (28-38] (38-48] (48-58] (58-68] (68-78] (78-88] (88-98]0

200

400

600

800

1000

age

freq

uenc

y

0

200

400

600

800

1000 • Ages of customers of a super-market/store (fictitious data);year of analysis: 2010.

• Depiction as a histogramindicates larger market shareamong younger people, butnothing is too conspicuous.

Christian Borgelt Data Mining / Intelligent Data Analysis 31

Histograms: Number of Bins

[18-28] (28-38] (38-48] (48-58] (58-68] (68-78] (78-88] (88-98]0

200

400

600

800

1000

age

freq

uenc

y

0

200

400

600

800

1000 • Ages of customers of a super-market/store (fictitious data);year of analysis: 2010.

• Depiction as a histogramindicates larger market shareamong younger people, butnothing is too conspicuous.

[18-20]

(20-22]

(22-24]

(24-26]

(26-28]

(28-30]

(30-32]

(32-34]

(34-36]

(36-38]

(38-40]

(40-42]

(42-44]

(44-46]

(46-48]

(48-50]

(50-52]

(52-54]

(54-56]

(56-58]

(58-60]

(60-62]

(62-64]

(64-66]

(66-68]

(68-70]

(70-72]

(72-74]

(74-76]

(76-78]

(78-80]

(80-82]

(82-84]

(84-86]

(86-88]

(88-90]

(90-92]

(92-94]

(94-96]

(96-98]

0

100

200

300

400

500

age

freq

uenc

y

0

100

200

300

400

500

Christian Borgelt Data Mining / Intelligent Data Analysis 32

Page 9: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Histograms: Number of Bins

–3 –2 –1 0 1 2 3 4 5 60

0.05

0.1

0.15

0.2

attribute value

prob

abili

ty d

ensi

ty • Probability density functionof a sample distribution,from which the data forthe following histogramswas sampled (1000 values).

–3 –2 –1 0 1 2 3 4 5 6 70

25

50

75

100

125

150

175

attribute value

freq

uenc

y

• A histogram with 11 bins,for the data that was sampledfrom the above distribution.

• How should we choosethe number of bins?

• What happensif we choose badly?

Christian Borgelt Data Mining / Intelligent Data Analysis 33

Histograms: Number of Bins

–3 –2 –1 0 1 2 3 4 5 60

0.05

0.1

0.15

0.2

attribute value

prob

abili

ty d

ensi

ty • Probability density functionof a sample distribution,from which the data forthe following histogramswas sampled (1000 values).

–3 –2 –1 0 1 2 3 4 5 6 70

50

100

150

200

250

300

350

attribute value

freq

uenc

y

• A histogram with too few bins,for the same data as before.

• As a consequence of the low num-ber of bins, the distribution looksunimodal (only one maximum), butskewed (asymmetric).

Christian Borgelt Data Mining / Intelligent Data Analysis 34

Histograms: Number of Bins

–3 –2 –1 0 1 2 3 4 5 60

0.05

0.1

0.15

0.2

attribute value

prob

abili

ty d

ensi

ty • Probability density functionof a sample distribution,from which the data forthe following histogramswas sampled (1000 values).

–3 –2 –1 0 1 2 3 4 5 6 70

5

10

15

attribute value

freq

uenc

y

• A histogram with too many bins,for the same data as before.

• As a consequence of the high numberof bins, the shape of the distributionis not well discernable.

Christian Borgelt Data Mining / Intelligent Data Analysis 35

Histograms: Number of Bins

–3 –2 –1 0 1 2 3 4 5 60

0.05

0.1

0.15

0.2

attribute value

prob

abili

ty d

ensi

ty • Probability density functionof a sample distribution,from which the data forthe following histogramswas sampled (1000 values).

–3 –2 –1 0 1 2 3 4 5 6 70

25

50

75

100

125

150

175

attribute value

freq

uenc

y• A histogram with 11 bins, a numbercomputed with Sturges’ Rule:

k = ⌈log2(n) + 1⌉,where n is the number of data points(here: n = 1000).

• Sturges’ rule is tailored to data fromnormal distributions and data sets ofmoderate size (n ≤ 200).

Christian Borgelt Data Mining / Intelligent Data Analysis 36

Page 10: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Histograms: Number of Bins

–3 –2 –1 0 1 2 3 4 5 60

0.05

0.1

0.15

0.2

attribute value

prob

abili

ty d

ensi

ty • Probability density functionof a sample distribution,from which the data forthe following histogramswas sampled (1000 values).

–3 –2 –1 0 1 2 3 4 5 6 70

20

40

60

80

100

120

attribute value

freq

uenc

y

• A histogram with 17 bins, a numberthat was computed with:

k =⌈1h (maxi{xi} −maxi{xi})

⌉,

where h may be chosen as

h = 3.5 · s · n−13

(s: sample standard deviation) or

h = 2 · (Q3 −Q1) · n−13

(Q3 −Q1: interquartile range).

Christian Borgelt Data Mining / Intelligent Data Analysis 37

3-Dimensional Diagrams

• 3-dimensional bar charts may be used to display contingency tables(the 3rd dimension represents the value pair frequency).

• The 3rd spacial dimension may be replaced by a color scale.This type of chart is sometimes referred to as a heatmap.(In a 3-dimensional bar chart color may also code the z-value (redundantly).)

• Surface plots are 3-dimensional analogs of line charts.

01

23 0

12

3

0

3

6

9

x

y

z

0 1 2 3

0

1

2

3

x

y

0

3

6

9z

–2–1

01

2

–2–1

01

2

1

x

y

z

Christian Borgelt Data Mining / Intelligent Data Analysis 38

Scatter Plots

• Scatter plots are used to display 2- or 3-dimensional metric data sets.

• Sample values are the coordinates of a point(that is, numbers are represented by lengths).

1 2 3 4 5 6 70

0.5

1

1.5

2

2.5

petal length / cm

petalwidth

/cm

iris data

12

34

5

24

68

1012250

500

750

1000

1250

1500

attrib

ute7attribute 10

attribute

13

wine data

• Scatter plots provide simple means to check for dependency.

Christian Borgelt Data Mining / Intelligent Data Analysis 39

How to Lie with Statistics

pictures not available in online version

Often the vertical axis ofa pole or bar chart doesnot start at zero, but atsome higher value.

In such a case the con-veyed impression of theratio of the depicted val-ues is completely wrong.

This effect is used tobrag about increases inturnover, speed etc.

Sources of these diagrams and thoseon the following transparencies:Darrell Huff:How to Lie with Statistics, 1954.Walter Kramer:So lugt man mit Statistik, 1991.

Christian Borgelt Data Mining / Intelligent Data Analysis 40

Page 11: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

How to Lie with Statistics

pictures not available in online version

• Depending on the position of the zero line of a pole, bar, or line chartcompletely different impressions can be conveyed.

Christian Borgelt Data Mining / Intelligent Data Analysis 41

How to Lie with Statistics

pictures not available in online version

• Poles and bars are frequently replaced by (sketches of) objectsin order to make the diagram more aesthetically appealing.

• However, objects are perceived as 2- or even 3-dimensional andthus convey a completely different impression of the numerical ratios.

Christian Borgelt Data Mining / Intelligent Data Analysis 42

How to Lie with Statistics

pictures not available in online version

Christian Borgelt Data Mining / Intelligent Data Analysis 43

How to Lie with Statistics

pictures not available in online version

• In the left diagram the areas of the barrels represent the numerical value.However, since the barrels are drawn 3-dimensional,a wrong impression of the numerical ratios is conveyed.

• The right diagram is particularly striking: an area measure is representedby the side length of a rectangle representing the apartment.

Christian Borgelt Data Mining / Intelligent Data Analysis 44

Page 12: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Good Data Visualization

picture not available in online version

• This is likely the most famous example of good data visualization.

• It is easy to understand and conveys information about several quantities,like number of people, location, temperature etc. [Charles Joseph Minard 1869]

Christian Borgelt Data Mining / Intelligent Data Analysis 45

Descriptive Statistics:

Characteristic Measures

Christian Borgelt Data Mining / Intelligent Data Analysis 46

Descriptive Statistics: Characteristic Measures

Idea: Describe a given sample by few characteristic measuresand thus summarize the data.

• Localization Measures

Localization measures describe, often by a single number,where the data points of a sample are located in the domain of an attribute.

• Dispersion Measures

Dispersion measures describe how much the data pointsvary around a localization parameter and thus indicatehow well this parameter captures the localization of the data.

• Shape Measures

Shape measures describe the shape of the distribution of the data pointsrelative to a reference distribution.The most common reference distribution is the normal distribution (Gaussian).

Christian Borgelt Data Mining / Intelligent Data Analysis 47

Localization Measures: Mode and Median

• Mode x∗The mode is the attribute value that is most frequent in the sample.It need not be unique, because several values can have the same frequency.It is the most general measure, because it is applicable for all scale types.

• Median xThe median minimizes the sum of absolute differences:

n∑

i=1

|xi − x| = min . and thus it isn∑

i=1

sgn(xi − x) = 0

If x = (x(1), . . . , x(n)) is a sorted data set, the median is defined as

x =

x(n+1

2 ), if n is odd,

12

(x(n2 )

+ x(n2+1)), if n is even.

The median is applicable to ordinal and metric attributes.(For non-metric attributes either x(n2 )

or x(n2+1)needs to be chosen for even n.)

Christian Borgelt Data Mining / Intelligent Data Analysis 48

Page 13: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Localization Measures: Arithmetic Mean

• Arithmetic Mean xThe arithmetic mean minimizes the sum of squared differences:

n∑

i=1

(xi − x)2 = min . and thus it isn∑

i=1

(xi − x) =n∑

i=1

xi − nx = 0

The arithmetic mean is defined as

x =1

n

n∑

i=1

xi.

The arithmetic mean is only applicable to metric attributes.

• Even though the arithmetic mean is the most common localization measure,the median is preferable if

◦ there are few sample cases,

◦ the distribution is asymmetric, and/or

◦ one expects that outliers are present.

Christian Borgelt Data Mining / Intelligent Data Analysis 49

How to Lie with Statistics

pictures not available in online version

Christian Borgelt Data Mining / Intelligent Data Analysis 50

Dispersion Measures: Range and Interquantile Range

A man with his head in the freezer and feet in the ovenis on the average quite comfortable.

old statistics joke

• Range RThe range of a data set is the difference between the maximum and the minimumvalue.

R = xmax − xmin = max ni=1xi −min ni=1xi

• Interquantile RangeThe p-quantile of a data set is a value such that a fraction of p of all sample valuesare smaller than this value. (The median is the 1

2-quantile.)

The p-interquantile range, 0 < p < 12, is the difference between

the (1− p)-quantile and the p-quantile.

The most common is the interquartile range (p = 14).

Christian Borgelt Data Mining / Intelligent Data Analysis 51

Dispersion Measures: Average Absolute Deviation

• Average Absolute DeviationThe average absolute deviation is the average of the absolute deviations of thesample values from the median or the arithmetic mean.

• Average Absolute Deviation from the Median

dx =1

n

n∑

i=1

|xi − x|

• Average Absolute Deviation from the Arithmetic Mean

dx =1

n

n∑

i=1

|xi − x|

• It is always dx ≤ dx, since the median minimizes the sum of absolute deviations(see the definition of the median).

Christian Borgelt Data Mining / Intelligent Data Analysis 52

Page 14: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Dispersion Measures: Variance and Standard Deviation

• (Empirical) Variance s2

It would be natural to define the variance as the average squared deviation:

v2 =1

n

n∑

i=1

(xi − x)2.

However, inductive statistics suggests that it is better defined as(Bessel’s correction, after Friedrich Wilhelm Bessel, 1784–1846)

s2 =1

n− 1

n∑

i=1

(xi − x)2.

• (Empirical) Standard Deviation sThe standard deviation is the square root of the variance, i.e.,

s =√s2 =

√√√√ 1

n− 1

n∑

i=1

(xi − x)2.

Christian Borgelt Data Mining / Intelligent Data Analysis 53

Dispersion Measures: Variance and Standard Deviation

• Special Case: Normal/Gaussian Distribution

The variance/standard deviation provides information aboutthe height of the mode and the width of the curve.

x

µ

σ σ

2σ 2σ

1√2πσ2

1√2πσ2e

1√2πσ2e2

fX(x;µ, σ2) = 1√2πσ2

· exp(− (x−µ)2

2σ2

)

• µ: expected value, estimated by mean value x

σ2: variance, estimated by (empirical) variance s2

σ: standard deviation, estimated by (empirical) standard deviation s

(Details about parameter estimation are studied later.)

Christian Borgelt Data Mining / Intelligent Data Analysis 54

Dispersion Measures: Variance and Standard Deviation

Note that it is often more convenient to compute the variance using the formulathat results from the following transformation:

s2 =1

n− 1

n∑

i=1

(xi − x)2 =1

n− 1

n∑

i=1

(x2i − 2xix + x2

)

=1

n− 1

n∑

i=1

x2i − 2xn∑

i=1

xi +n∑

i=1

x2

=1

n− 1

n∑

i=1

x2i − 2nx2 + nx2

=

1

n− 1

n∑

i=1

x2i − nx2

=1

n− 1

n∑

i=1

x2i −1

n

n∑

i=1

xi

2

• Advantage: The sums∑ni=1 xi and

∑ni=1 x

2i can both be computed in the same

traversal of the data and from them both mean and variance can be computed.

Christian Borgelt Data Mining / Intelligent Data Analysis 55

Shape Measures: Skewness

• The skewness α3 (or skew for short) measures whether, and if, how much,a distribution differs from a symmetric distribution.

• It is computed from the 3rd moment about the mean,which explains the index 3.

α3 =1

n · v3n∑

i=1

(xi − x)3 =1

n

n∑

i=1

z3i

where zi =xi − xv

and v2 =1

n

n∑

i=1

(xi − x)2.

α3 < 0: right steep α3 = 0: symmetric α3 > 0: left steep

Christian Borgelt Data Mining / Intelligent Data Analysis 56

Page 15: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Shape Measures: Kurtosis

• The kurtosis or excess α4 measures how much a distribution is arched,usually compared to a Gaussian distribution.

• It is computed from the 4th moment about the mean,which explains the index 4.

α4 =1

n · v4n∑

i=1

(xi − x)4 =1

n

n∑

i=1

z4i

where zi =xi − xv

and v2 =1

n

n∑

i=1

(xi − x)2.

α4 < 3: leptokurtic α4 = 3: Gaussian α4 > 3: platikurtic

Christian Borgelt Data Mining / Intelligent Data Analysis 57

Moments of Data Sets

• The k-th moment of a dataset is defined as

m′k =1

n

n∑

i=1

xki .

The first moment is the mean m′1 = x of the data set.

Using the moments of a data set the variance s2 can also be written as

s2 = 1n−1

(m′2 − 1

nm′ 21

)and also v2 = 1

nm′2 − 1

n2m′ 21 .

• The k-th moment about the mean is defined as

mk =1

n

n∑

i=1

(xi − x)k.

It is m1 = 0 and m2 = v2 (i.e., the average squared deviation).

The skewness is α3 =m3

m3/22

and the kurtosis is α4 =m4m2

2.

Christian Borgelt Data Mining / Intelligent Data Analysis 58

Visualizing Characteristic Measures: Box Plots

◦◦◦ outliersxmax maximum(or max{x | x ≤ Q3 + 1.5(Q3 −Q1)}or 97.5% quantile)

Q3 3. quartile

x arithmetic meanx = Q2 median/2. quartile

Q1 1. quartile

xmin

(or min{x | x ≥ Q1 − 1.5(Q3 −Q1)}or 2.5% quantile)

minimum

A box plot is a common way tocombine some important char-acteristic measures into a singlegraphical representation.

Often the central box is drawnconstricted (〉〈) w.r.t. the arith-metic mean in order to empha-size its location.

The “whiskers” are often limitedin length to 1.5(Q3−Q1). Datapoints beyond these limits aresuspected to be outliers.

Box plots are often used to get a quick impression of the distribution of the databy showing them side by side for several attributes or data subsets.

Christian Borgelt Data Mining / Intelligent Data Analysis 59

Box Plots: Examples

• left top: two samples from astandard normal distribution.

• left bottom: two samples from anexponential distribution.

• right bottom:probability density function of theexponential distribution with λ = 1.

0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

attribute value

prob

abili

ty d

ensi

ty

Christian Borgelt Data Mining / Intelligent Data Analysis 60

Page 16: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Multidimensional Characteristic Measures

General Idea: Transfer the characteristic measures to vectors.

• Arithmetic MeanThe arithmetic mean for multi-dimensional data is the vector meanof the data points. For two dimensions it is

(x, y) =1

n

n∑

i=1

(xi, yi) = (x, y)

For the arithmetic mean the transition to several dimensions only combinesthe arithmetic means of the individual dimensions into one vector.

• Other measures are transferred in a similar way.However, sometimes the transfer leads to new quantities, as for the variance,which requires adaptation due to its quadratic nature.

Christian Borgelt Data Mining / Intelligent Data Analysis 61

Excursion: Vector Products

General Idea: Transfer dispersion measures to vectors.

For the variance, the square of the difference to the mean has to be generalized.

Inner ProductScalar Product

~v⊤~v

v1v2...vm

(v1, v2, . . . , vm)∑mi=1 v

2i

Outer ProductMatrix Product

~v~v⊤ ( v1, v2, . . . , vm )

v1v2...vm

v21 v1v2 · · · v1vmv1v2 v22 · · · v2vm... . . . ...

v1vm v2vm · · · v2m

• In principle both vector products may be used for a generalization.

• The second, however, yields more information about the distribution:

◦ a measure of the (linear) dependence of the attributes,

◦ a description of the direction dependence of the dispersion.

Christian Borgelt Data Mining / Intelligent Data Analysis 62

Covariance Matrix

• Covariance MatrixCompute variance formula with vectors (square: outer product ~v~v⊤):

S =1

n− 1

n∑

i=1

((xiyi

)−(x

y

))((xiyi

)−(x

y

))⊤=

(s2x sxysyx s2y

)

where s2x and s2y are variances and sxy is the covariance of x and y:

s2x = sxx =1

n− 1

n∑

i=1

(xi − x)2 =1

n− 1

n∑

i=1

x2i − nx2

s2y = syy =1

n− 1

n∑

i=1

(yi − y)2 =1

n− 1

n∑

i=1

y2i − ny2

sxy = syx =1

n− 1

n∑

i=1

(xi − x)(yi − y) =1

n− 1

n∑

i=1

xiyi − nxy

(Using n− 1 instead of n is called Bessel’s correction, after Friedrich Wilhelm Bessel, 1784–1846.)

Christian Borgelt Data Mining / Intelligent Data Analysis 63

Reminder: Variance and Standard Deviation

• Special Case: Normal/Gaussian Distribution

The variance/standard deviation provides information aboutthe height of the mode and the width of the curve.

x

µ

σ σ

2σ 2σ

1√2πσ2

1√2πσ2e

1√2πσ2e2

fX(x;µ, σ2) = 1√2πσ2

· exp(− (x−µ)2

2σ2

)

• µ: expected value, estimated by mean value x,

σ2: variance, estimated by (empirical) variance s2,

σ: standard deviation, estimated by (empirical) standard deviation s.

Important: the standard deviation has the same unit as the expected value.

Christian Borgelt Data Mining / Intelligent Data Analysis 64

Page 17: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Multivariate Normal Distribution

• A univariate normal distribution has the density function

fX(x;µ, σ2) =1√2πσ2

· exp(−(x− µ)

2

2σ2

)

µ: expected value, estimated by mean value x,

σ2: variance, estimated by (empirical) variance s2,σ: standard deviation, estimated by (empirical) standard deviation s.

• A multivariate normal distribution has the density function

f ~X(~x; ~µ,Σ) =1√

(2π)m|Σ|· exp

(−12(~x− ~µ)⊤Σ−1(~x− ~µ)

)

m: size of the vector ~x (it is m-dimensional),~µ: expected value vector, estimated by mean value vector ~x,Σ: covariance matrix, estimated by (empirical) covariance matrix S,|Σ|: determinant of the covariance matrix Σ.

Christian Borgelt Data Mining / Intelligent Data Analysis 65

Interpretation of a Covariance Matrix

• The variance/standard deviation relates the spread of the distribution tothe spread of a standard normal distribution (σ2 = σ = 1).

• The covariance matrix relates the spread of the distribution tothe spread of a multivariate standard normal distribution (Σ = 1).

• Example: bivariate normal distribution

–2 –10

12–2

–10

12

–2 –10

12–2

–10

12

standard general

• Question: Is there a multivariate analog of standard deviation?

Christian Borgelt Data Mining / Intelligent Data Analysis 66

Interpretation of a Covariance Matrix

Question: Is there a multivariate analog of standard deviation?

First insight:If the covariances vanish,the contour lines are axes-parallel ellipses.The upper ellipse is inscribed into therectangle [−σx, σx]× [−σy, σy].

Σ =

(σ2x 00 σ2y

)−σx σxσy

−σy

Second insight:If the covariances do not vanish,the contour lines are rotated ellipses.Still the upper ellipse is inscribed into therectangle [−σx, σx]× [−σy, σy].

Σ =

(σ2x σxyσxy σ2y

)

−σx σxσy

−σy

Consequence: A covariance matrix describes a scaling and a rotation.

Christian Borgelt Data Mining / Intelligent Data Analysis 67

Interpretation of a Covariance Matrix

A covariance matrix is always positive semi-definite.

• positive semi-definite: ∀~v ∈ IRm : ~v⊤S ~v ≥ 0,negative semi-definite: ∀~v ∈ IRm : ~v⊤S ~v ≤ 0,

• For any ~x ∈ IRm the outer product ~x~x⊤ yields a positive semi-definite matrix:

∀~v ∈ IRm : ~v⊤~x~x⊤~v = (~v⊤~x)2 ≥ 0.

• If Si, i = 1, . . . , k, are positive (negative) semi-definite matrices,then S =

∑ki=1 Si is a positive (negative) semi-definite matrix.

∀~v ∈ IRm : ~v⊤S~v = ~v⊤(∑k

i=1 Si)~v =

∑ki=1 ~v

⊤Si~v︸ ︷︷ ︸≥0

≥ 0.

• A(n empirical) covariance matrix is computed as

S =n∑

i=1

(~xi − ~x )⊤(~xi − ~x ).

As the sum of positive semi-definite matrices it is positive semi-definite itself.

Christian Borgelt Data Mining / Intelligent Data Analysis 68

Page 18: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Interpretation of a Covariance Matrix

A covariance matrix is generally positive definite,unless all data points lie in a lower-dimensional (linear) subspace.

• positive definite: ∀~v ∈ IRm−{~0} : ~v⊤S ~v > 0,negative definite: ∀~v ∈ IRm−{~0} : ~v⊤S ~v < 0,

• A(n empirical) covariance matrix is computed as S =∑ni=1(~xi − ~x )⊤(~xi − ~x ).

• Let ~zi = (~xi − ~x ), i = 1, . . . , n, and suppose that

∃~v ∈ IRm−{~0} : ∀i; 1 ≤ i ≤ n : ~v⊤~zi = 0 (implying ~v⊤~zi~z⊤i ~v = (~v⊤~zi)2 = 0).

Furthermore, suppose that the set {~z1, . . . , ~zn} of difference vectors spans IRm.Then there exist α1, . . . , αn ∈ IR such that ~v = α1~z1 + . . . + αn~zn.

Hence ~v⊤~v = ~v⊤~z1︸ ︷︷ ︸=0

α1 + . . . + ~v⊤~zn︸ ︷︷ ︸=0 (by assumption)

αn = 0, implying ~v = ~0, contradicting ~v 6= ~0.

• Therefore, if the ~zi, i = 1, . . . , n, span IRm, then S is positive definite.Only if the ~zi, i = 1, . . . , n, do not span IRm, that is, if the data points liein a lower-dimensional (linear) subspace, S is only positive semi-definite.

Christian Borgelt Data Mining / Intelligent Data Analysis 69

Cholesky Decomposition

• Intuitively: Compute an analog of standard deviation.

• Let S be a symmetric, positive definite matrix (e.g. a covariance matrix).Cholesky decomposition serves the purpose to compute a “square root” of S.

◦ symmetric: ∀1 ≤ i, j ≤ m : sij = sji or S⊤ = S.

(S⊤ is the transpose of the matrix S.)

◦ positive definite: for all m-dimensional vectors ~v 6= ~0 it is ~v⊤ S ~v > 0

• Formally: Compute a left/lower triangular matrix L such that LL⊤ = S.(L⊤ is the transpose of the matrix L.)

lii =

sii −

i−1∑

k=1

l2ik

12

lji =1

lii

sij −

i−1∑

k=1

likljk

, j = i + 1, i + 2, . . . ,m.

Christian Borgelt Data Mining / Intelligent Data Analysis 70

Cholesky Decomposition

Special Case: Two Dimensions

• Covariance matrix

Σ =

σ2x σxy

σxy σ2y

• Cholesky decomposition

L =

σx 0

σxyσx

1

σx

√σ2xσ

2y − σ2xy

1

2

3

4

unitcircle

mapping with L

~v ′ = L~v

12

34

Christian Borgelt Data Mining / Intelligent Data Analysis 71

Eigenvalue Decomposition

• Eigenvalue decomposition also yields an analog of standard deviation.

• It is computationally more expensive than Cholesky decomposition.

• Let S be a symmetric, positive definite matrix (e.g. a covariance matrix).

◦ S can be written as

S = R diag(λ1, . . . , λm) R−1,

where the λj, j = 1, . . . ,m, are the eigenvalues of Sand the columns of R are the (normalized) eigenvectors of S.

◦ The eigenvalues λj, j = 1, . . . ,m, of S are all positive

and the eigenvectors of S are orthonormal (→ R−1 = R⊤).

• Due to the above, S can be written as S = TT⊤, where

T = R diag(√

λ1, . . . ,√λm

)

Christian Borgelt Data Mining / Intelligent Data Analysis 72

Page 19: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Eigenvalue Decomposition

Special Case: Two Dimensions

• Covariance matrix

Σ =

σ2x σxy

σxy σ2y

• Eigenvalue decomposition

T =

c −ss c

σ1 0

0 σ2

,

s = sinφ, c = cosφ, φ = 12 arctan

2σxyσ2x−σ2y

,

σ1 =√c2σ2x + s2σ2y + 2scσxy,

σ2 =√s2σ2x + c2σ2y − 2scσxy.

1

2

3

4

unitcircle

mapping with T

~v ′ = T~v

1

2

3

4

φ

σ1

σ2

Christian Borgelt Data Mining / Intelligent Data Analysis 73

Eigenvalue Decomposition

Eigenvalue decomposition enables us to write a covariance matrix Σ as

Σ = TT⊤ with T = R diag(√

λ1, . . . ,√λm

).

As a consequence we can write its inverse Σ−1 as

Σ−1 = U⊤U with U = diag

(λ−1

21 , . . . , λ

−12

m

)R⊤.

U describes the inverse mapping of T, i.e., rotates the ellipse so that its axes coincidewith the coordinate axes and then scales the axes to unit length. Hence:

(~x− ~y)⊤Σ−1(~x− ~y) = (~x− ~y)⊤U⊤U(~x− ~y) = (~x ′ − ~y ′)⊤(~x ′ − ~y ′),where ~x ′ = U~x and ~y ′ = U~y.

Result: (~x− ~y)⊤Σ−1(~x− ~y) is equivalent to the squared Euclidean distance inthe properly scaled eigensystem of the covariance matrix Σ.

d(~x, ~y) =√(~x− ~y)⊤Σ−1(~x− ~y) is called Mahalanobis distance.

Christian Borgelt Data Mining / Intelligent Data Analysis 74

Eigenvalue Decomposition

Eigenvalue decomposition also shows that the determinant of the covariancematrix Σ provides a measure of the (hyper-)volume of the (hyper-)ellipsoid. It is

|Σ| = |R| |diag(λ1, . . . , λm)| |R⊤| = |diag(λ1, . . . , λm)| =m∏

i=1

λi,

since |R| = |R⊤| = 1 as R is orthogonal with unit length columns, and thus

√|Σ| =

m∏

i=1

√λi,

which is proportional to the (hyper-)volume of the (hyper-)ellipsoid.

To be precise, the volume of them-dimensional (hyper-)ellipsoid a (hyper-)sphere withradius r is mapped to with the eigenvalue decomposition of a covariance matrix Σ is

Vm(r) =πm2 rm

Γ(m2 + 1

)√|Σ|, where

Γ(x) =∫∞0 e−ttx−1 dt, x > 0,

Γ(x + 1) = x · Γ(x), Γ(12) =√π, Γ(1) = 1.

Christian Borgelt Data Mining / Intelligent Data Analysis 75

Eigenvalue Decomposition

Special Case: Two Dimensions

• Covariance matrix and its eigenvalue decomposition:

Σ =

σ2x σxy

σxy σ2y

and T =

cosφ − sinφ

sinφ cosφ

σ1 0

0 σ2

.

1

2

3

4

unitcircle

mapping with T

~v ′ = T~v

1

2

3

4

φ

σ1

σ2

• The area of the ellipse, to which the unit circle (area π) is mapped, is

A = πσ1σ2 = π√|Σ|.

Christian Borgelt Data Mining / Intelligent Data Analysis 76

Page 20: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Covariance Matrices of Example Data Sets

Σ ≈(3.59 0.190.19 3.54

)

L ≈(1.90 00.10 1.88

)

Σ ≈(2.33 1.441.44 2.41

)

L ≈(1.52 00.95 1.22

)

Σ ≈(1.88 1.621.62 2.03

)

L ≈(1.37 01.18 0.80

)

Σ ≈(2.25 −1.93−1.93 2.23

)

L ≈(1.50 0−1.29 0.76

)

Christian Borgelt Data Mining / Intelligent Data Analysis 77

Covariance Matrix: Summary

• A covariance matrix provides information about the height of the modeand about the spread/dispersion of a multivariate normal distribution(or of a set of data points that are roughly normally distributed).

• A multivariate analog of standard deviation can be computedwith Cholesky decomposition and eigenvalue decomposition.The resulting matrix describes the distribution’s shape and orientation.

• The shape and the orientation of a two-dimensional normal distributioncan be visualized as an ellipse (curve of equal probability density;similar to a contour line — line of equal height — on a map.)

• The shape and the orientation of a three-dimensional normal distributioncan be visualized as an ellipsoid (surface of equal probability density).

• The (square root of the) determinant of a covariance matrix describesthe spread of a multivariate normal distribution with a single value.It is a measure of the area or (hyper-)volume of the (hyper-)ellipsoid.

Christian Borgelt Data Mining / Intelligent Data Analysis 78

Correlation and

Principal Component Analysis

Christian Borgelt Data Mining / Intelligent Data Analysis 79

Correlation Coefficient

• The covariance is a measure of the strength of linear dependenceof the two quantities of which it is computed.

• However, its value depends on the variances of the individual dimensions.⇒ Normalize to unit variance in the individual dimensions.

• Correlation Coefficient(more precisely: Pearson’s Product Moment Correlation Coefficient or

Bravais–Pearson Correlation Coefficient)

ρxy =sxysxsy

, ρxy ∈ [−1,+1].

• ρxy measures the strength of linear dependence (of y on x):

ρxy = −1: the data points lie perfectly on a straight line with negative slope.ρyx = +1: the data points lie perfectly on a straight line with positive slope.

• ρxy = 0: there is no linear dependence between the two attributes(but there may be a non-linear dependence!).

Christian Borgelt Data Mining / Intelligent Data Analysis 80

Page 21: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Correlation Coefficient

• ρxy exists whenever sx > 0, sy > 0, and then we have −1 ≤ ρxy ≤ +1.

• In case of ρxy = 0, we call the sample (x1, y1), . . . , (xn, yn) uncorrelated.

• ρxy is not a measure of dependence — it only measures linear dependence.ρxy = 0 only means that there is no linear dependence.

• Example: Suppose the data points lie symmetrically on a parabola, ρxy = 0.

• Note that ρxy = ρyx (simply because sxy = syx),which justifies that we merely write ρ in the following.

Christian Borgelt Data Mining / Intelligent Data Analysis 81

Correlation Coefficients of Example Data Sets

nocorrelation(ρ ≈ 0.05)

weakpositivecorrelation(ρ ≈ 0.61)

strongpositivecorrelation(ρ ≈ 0.83)

strongnegativecorrelation(ρ ≈ −0.86)

Christian Borgelt Data Mining / Intelligent Data Analysis 82

Correlation Matrix

• Normalize Data (z-score normalization)

Transform data to mean value 0 and variance/standard deviation 1:

∀i; 1 ≤ i ≤ n : x′i =xi − xsx

, y′i =yi − ysy

.

• Compute Covariance Matrix of Normalized Data

Sum outer products of transformed data vectors:

Σ′ =1

n− 1

n∑

i=1

(x′iy′i

)(x′iy′i

)⊤=

(1 ρρ 1

)

Subtraction of mean vector is not necessary (because it is ~µ′ = (0, 0)⊤).Diagonal elements are always 1 (because of unit variance in each dimension).

• Normalizing the data and then computing the covariances orcomputing the covariances and then normalizing them has the same effect.

Christian Borgelt Data Mining / Intelligent Data Analysis 83

Correlation Matrix: Interpretation

Special Case: Two Dimensions

• Correlation matrix

Σ′ =

1 ρ

ρ 1

,

eigenvalues: σ21, σ22

correlation: ρ =σ21−σ22σ21+σ

22

Side note: The (numerical)eccentricity ǫ of an ellipse(in geometry) satisfies

ǫ2 =|σ21 − σ22|

max(σ21, σ22).

• Eigenvalue decomposition

T =

c −ss c

σ1 0

0 σ2

,

s = sin π4 = 1√2, σ1 =

√1 + ρ,

c = cos π4 = 1√2, σ2 =

√1− ρ.

1

2

3

4

unitcircle

mapping with T

~v ′ = T~v

1

2

3

4

π4

σ1

σ2

Christian Borgelt Data Mining / Intelligent Data Analysis 84

Page 22: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Correlation Matrix: Interpretation• Via the ellipse that results from mappinga unit circle with an eigenvalue decompo-sition of a correlation matrix, correlationcan be understood geometrically.

• In this view correlation is related tothe (numerical) eccentricity of an ellipse(different normalization, though).

• Correlation:

ρ =σ21 − σ22σ21 + σ22

√σ21 + σ22: distance

vertex to co-vertex

σ22 → 0 ⇒ ρ→ +1,

σ21 → 0 ⇒ ρ→ −1.• Squared (numerical) eccentricity:

ǫ2 =|σ21 − σ22|

max(σ21, σ22)

max(σ1, σ2): lengthof semi-major axis

F1 F2

P

e a

b

aa

e =√a2 − b2 ǫ =

√a2−b2

a

Given the two focal points F1 andF2 and the length a of the semi-major axis, an ellipse is the set ofpoints {P | |F1P | + |F2P | = 2a}.Linear eccentricity:

e =√a2 − b2

(Numerical) eccentricity:

ǫ = ea =

√a2−b2a

Christian Borgelt Data Mining / Intelligent Data Analysis 85

Correlation Matrix: Interpretation

• For two dimensions the eigenvectors of a correlation matrix are always

~v1 =(

1√2, 1√

2

)and ~v2 =

(− 1√

2, 1√

2

)

(or their opposites −~v1 or −~v2 or exchanged).

The reason is that the normalization trans-forms the data points in such a way that theellipse, the unit circle is mapped to by the“square root” of the covariance matrix of thenormalized data, is always inscribed into thesquare [−1, 1] × [−1, 1]. Hence the ellipse’smajor axes are the square’s diagonals.

• The situation is analogous in m-dimensional spaces:the eigenvectors are always m of the 2m−1 diagonalsof the m-dimensional unit (hyper-)cube around the origin.

Christian Borgelt Data Mining / Intelligent Data Analysis 86

Attention: Correlation 6⇒ Causation!

pictures not available in online version

• Always remember:An observed correlation may be purely coincidental!

• This is especially the case if the data come from processesthat show relatively steady growth or decline (these are always correlated).

• In order to claim a causal connection between quantities,the actual mechanism needs to be discovered and confirmed!

Christian Borgelt Data Mining / Intelligent Data Analysis 87

Attention: Correlation 6⇒ Causation!

Does high fat intakecause breast cancer?

picture not available in online version

• Data shows a clear correlationbetween breast cancer deathrates and fat intake.

• Is this evidencefor a causal connection?If at all, it is quite weak.

• Amount of fat in diet andamount of sugar are correlated.

• Plot of amount of sugar in dietand colon cancer death rateswould look similar.

• How rich a country is influencesthe amount of fat and sugar inthe diet, but also a lot of otherfactors (e.g. life expectancy).

Christian Borgelt Data Mining / Intelligent Data Analysis 88

Page 23: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Attention: Correlation 6⇒ Causation!

pictures not available in online version

Christian Borgelt Data Mining / Intelligent Data Analysis 89

Attention: Correlation 6⇒ Causation!

pictures not available in online version

Christian Borgelt Data Mining / Intelligent Data Analysis 90

Attention: Correlation 6⇒ Causation!

pictures not available in online version

Christian Borgelt Data Mining / Intelligent Data Analysis 91

Attention: Correlation 6⇒ Causation!

pictures not available in online version

Christian Borgelt Data Mining / Intelligent Data Analysis 92

Page 24: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Attention: Correlation 6⇒ Causation!

pictures not available in online version

Christian Borgelt Data Mining / Intelligent Data Analysis 93

Attention: Correlation 6⇒ Causation!

pictures not available in online version

Christian Borgelt Data Mining / Intelligent Data Analysis 94

Regression Line

• Since the covariance/correlation measures linear dependence,it is not surprising that it can be used to define a regression line:

(y − y) = sxys2x

(x− x) or y =sxys2x

(x− x) + y.

• The regression line can be seen as a conditional arithmetic mean:there is one arithmetic mean for the y-dimensions for each x-value.

• This interpretation is supported by the fact that the regression lineminimizes the sum of squared differences in y-direction.(Reminder: the arithmetic mean minimizes the sum of squared differences.)

• More information on regression and the method of least squaresin the corresponding chapter (to be discussed later).

Christian Borgelt Data Mining / Intelligent Data Analysis 95

Principal Component Analysis

• Correlations between the attributes of a data set can be used toreduce the number of dimensions:

◦ Of two strongly correlated features only one needs to be considered.

◦ The other can be reconstructed approximately from the regression line.

◦ However, the feature selection can be difficult.

• Better approach: Principal Component Analysis (PCA)

◦ Find the direction in the data space that has the highest variance.

◦ Find the direction in the data space that has the highest varianceamong those perpendicular to the first.

◦ Find the direction in the data space that has the highest varianceamong those perpendicular to the first and second and so on.

◦ Use first directions to describe the data.

Christian Borgelt Data Mining / Intelligent Data Analysis 96

Page 25: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Principal Component Analysis: Physical Analog

• The rotation of a body around an axis through its center of gravity can be describedby a so-called inertia tensor, which is a 3× 3-matrix

Θ =

Θxx Θxy ΘxzΘxy Θyy ΘyzΘxz Θyz Θzz

.

• The diagonal elements of this tensor are called the moments of inertia.They describe the “resistance” of the body against being rotated.

• The off-diagonal elements are the so-called deviation moments.They describe forces vertical to the rotation axis.

• All bodies possess three perpendicular axes through their center of gravity, aroundwhich they can be rotated without forces perpendicular to the rotation axis.These axes are called principal axes of inertia.There are bodies that possess more than 3 such axes (example: a homogeneous sphere),but all bodies have at least three such axes.

Christian Borgelt Data Mining / Intelligent Data Analysis 97

Principal Component Analysis: Physical Analog

The principal axesof inertia of a box.

• The deviation moments cause “rattling” in the bearings of the rotation axis,which cause the bearings to wear out quickly.

• A car mechanic who balances a wheel carries out, in a way, a principal axestransformation. However, instead of changing the orientation of the axes, he/sheadds small weights to minimize the deviation moments.

• A statistician who does a principal component analysis, finds, in a way, the axesthrough a weight distribution with unit weights at each data point, around whichit can be rotated most easily.

Christian Borgelt Data Mining / Intelligent Data Analysis 98

Principal Component Analysis: Formal Approach

• Normalize all attributes to arithmetic mean 0 and standard deviation 1:

x′ =x− xsx

• Compute the correlation matrix Σ(i.e., the covariance matrix of the normalized data)

• Carry out a principal axes transformation of the correlation matrix,that is, find a matrix R, such that R⊤ΣR is a diagonal matrix.

• Formal procedure:

◦ Find the eigenvalues and eigenvectors of the correlation matrix,i.e., find the values λi and vectors ~vi, such that Σ~vi = λi~vi.

◦ The eigenvectors indicate the desired directions.

◦ The eigenvalues are the variances in these directions.

Christian Borgelt Data Mining / Intelligent Data Analysis 99

Principal Component Analysis: Formal Approach

• Select dimensions using the percentage of explained variance.

◦ The eigenvalues λi are the variances σ2i in the principal dimensions.

◦ It can be shown that the sum of the eigenvalues of anm×m correlation matrixis m. Therefore it is plausible to define λim as the share the i-th principal axishas in the total variance.

◦ Sort the λi descendingly and find the smallest value k, such that

k∑

i=1

λim≥ α,

where α is a user-defined parameter (e.g. α = 0.9).

◦ Select the corresponding k directions (given by the eigenvectors).

• Transform the data to the new data space by multiplying the data pointswith a matrix, the rows of which are the eigenvectors of the selected dimensions.

Christian Borgelt Data Mining / Intelligent Data Analysis 100

Page 26: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Principal Component Analysis: Example

x 5 15 21 29 31 43 49 51 61 65

y 33 35 24 21 27 16 18 10 4 12

y

x

30

20

10

00 10 20 30 40 50 60

• Strongly correlated features ⇒ Reduction to one dimension possible.

• Second dimension may be reconstructed from regression line.

Christian Borgelt Data Mining / Intelligent Data Analysis 101

Principal Component Analysis: Example

Normalize to arithmetic mean 0 and standard deviation 1:

x =1

10

10∑

i=1

xi =370

10= 37,

y =1

10

10∑

i=1

yi =200

10= 20,

s2x =1

9

10∑

i=1

x2i − 10x2

=

17290− 13690

9= 400 ⇒ sx = 20,

s2y =1

9

10∑

i=1

y2i − 10y2

=

4900− 4000

9= 100 ⇒ sy = 10.

x′ −1.6 −1.1 −0.8 −0.4 −0.3 0.3 0.6 0.7 1.2 1.4

y′ 1.3 1.5 0.4 0.1 0.7 −0.4 −0.2 −1.0 −1.6 −0.8

Christian Borgelt Data Mining / Intelligent Data Analysis 102

Principal Component Analysis: Example

• Compute the correlation matrix (covariance matrix of normalized data).

Σ =1

9

(9 −8.28−8.28 9

)=

(1 −23

25−23

25 1

).

• Find the eigenvalues and eigenvectors, i.e., the values λi and vectors ~vi, i = 1, 2,such that

Σ~vi = λi~vi or (Σ− λi1)~vi = ~0.where 1 is the unit matrix.

• Here: Find the eigenvalues as the roots of the characteristic polynomial.

c(λ) = |Σ− λ1| = (1− λ)2 − 529

625.

For more than 3 dimensions, this method is numerically unstable and should bereplaced by some other method (Jacobi-Transformation, Householder Transfor-mation to tridiagonal form followed by the QR algorithm etc.).

Christian Borgelt Data Mining / Intelligent Data Analysis 103

Principal Component Analysis: Example

• The roots of the characteristic polynomial c(λ) = (1− λ)2 − 529625 are

λ1/2 = 1±√529

625= 1± 23

25, i.e. λ1 =

48

25and λ2 =

2

25

• The corresponding eigenvectors are determined by solving for i = 1, 2the (underdetermined) linear equation system

(Σ− λi1)~vi = ~0

• The resulting eigenvectors (normalized to length 1) are

~v1 =

(1√2,− 1√

2

)and ~v2 =

(1√2,1√2

),

(Note that for two dimensions always these two vectors result.Reminder: directions of the eigenvectors of a correlation matrix.)

Christian Borgelt Data Mining / Intelligent Data Analysis 104

Page 27: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Principal Component Analysis: Example

• Therefore the transformation matrix for the principal axes transformation is

R =

1√2

1√2

− 1√2

1√2

, for which it is R⊤ΣR =

(λ1 00 λ2

)

• However, instead of R⊤ we use√2R⊤ to transform the data:

(x′′

y′′

)=√2 ·R⊤ ·

(x′

y′

).

Resulting data set (additional factor√2 leads to nicer values):

x′′ −2.9 −2.6 −1.2 −0.5 −1.0 0.7 0.8 1.7 2.8 2.2

y′′ −0.3 0.4 −0.4 −0.3 0.4 −0.1 0.4 −0.3 −0.4 0.6

• y′′ is discarded (s2y′′ = 2λ2 =425) and only x′′ is kept (s2x′′ = 2λ1 =

9625).

Christian Borgelt Data Mining / Intelligent Data Analysis 105

The Iris Data

pictures not available in online version

• Collected by Edgar Anderson on the Gaspe Peninsula (Canada).

• First analyzed by Ronald Aylmer Fisher (famous statistician).

• 150 cases in total, 50 cases per Iris flower type.

• Measurements of sepal length and width and petal length and width (in cm).

• Most famous data set in pattern recognition and data analysis.

Christian Borgelt Data Mining / Intelligent Data Analysis 106

The Iris Data

5 6 7 8

2

2.5

3

3.5

4

4.5

sepal length / cm

sepa

l wid

th /

cm

Iris setosaIris versicolorIris virginica

1 2 3 4 5 6 70

0.5

1

1.5

2

2.5

petal length / cm

peta

l wid

th /

cm

Iris setosaIris versicolorIris virginica

• Scatter plots of the iris data set for sepal length vs. sepal width (left)and for petal length vs. petal width (right).All quantities are measured in centimeters (cm).

Christian Borgelt Data Mining / Intelligent Data Analysis 107

Principal Component Analysis: Iris Data

–1.5 –1 –0.5 0 0.5 1 1.5

–1.5

–1

–0.5

0

0.5

1

1.5

normalized petal length

norm

aliz

ed p

etal

wid

th

Iris setosaIris versicolorIris virginica

–3 –2 –1 0 1 2 3–3

–2

–1

0

1

2

3

first principal component

seco

nd p

rinc

ipal

com

pone

nt

Iris setosaIris versicolorIris virginica

• Left: the first (solid line) and the second principal component (dashed line).

• Right: the iris data projected to the space that is spanned by the first and thesecond principal component (resulting from a PCA involving all four attributes).

Christian Borgelt Data Mining / Intelligent Data Analysis 108

Page 28: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Inductive Statistics

Christian Borgelt Data Mining / Intelligent Data Analysis 109

Inductive Statistics: Main Tasks

• Parameter EstimationGiven an assumption about the type of distribution of the underlying randomvariable the parameter(s) of the distribution function is estimated.

• Hypothesis TestingA hypothesis about the data generating process is tested by means of the data.

◦ Parameter TestTest whether a parameter can have certain values.

◦ Goodness-of-Fit TestTest whether a distribution assumption fits the data.

◦ Dependence TestTest whether two attributes are dependent.

• Model SelectionAmong different models that can be used to explain the data the best fitting isselected, taking the complexity of the model into account.

Christian Borgelt Data Mining / Intelligent Data Analysis 110

Inductive Statistics: Random Samples

• In inductive statistics probability theory is applied to make inferencesabout the process that generated the data. This presupposes that the sampleis the result of a random experiment, a so-called random sample.

• The random variable yielding the sample value xi is denoted Xi.xi is called a instantiation of the random variable Xi.

• A random sample x = (x1, . . . , xn) is an instantiationof the random vector X = (X1, . . . , Xn).

• A random sample is called independentif the random variables X1, . . . , Xn are (stochastically) independent, i.e. if

∀c1, . . . , cn ∈ IR : P

n∧

i=1

Xi ≤ ci

=

n∏

i=1

P (Xi ≤ ci).

• An independent random sample is called simple if the random variablesX1, . . . , Xn have the same distribution function.

Christian Borgelt Data Mining / Intelligent Data Analysis 111

Inductive Statistics:

Parameter Estimation

Christian Borgelt Data Mining / Intelligent Data Analysis 112

Page 29: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Parameter Estimation

Given:

• A data set and

• a family of parameterized distributions functions of the same type, e.g.

◦ the family of binomial distributions bX(x; p, n)with the parameters p, 0 ≤ p ≤ 1, and n ∈ IN, where n is the sample size,

◦ the family of normal distributions NX(x;µ, σ2)with the parameters µ (expected value) and σ2 (variance).

Assumption:

• The process that generated the data can be described wellby an element of the given family of distribution functions.

Desired:

• The element of the given family of distribution functions(determined by its parameters) that is the best model for the data.

Christian Borgelt Data Mining / Intelligent Data Analysis 113

Parameter Estimation

• Methods that yield an estimate for a parameter are called estimators.

• Estimators are statistics, i.e. functions of the values in a sample.

As a consequence they are functions of (instantiations of) random variablesand thus (instantiations of) random variables themselves.

Therefore we can use all of probability theory to analyze estimators.

• There are two types of parameter estimation:

◦ Point EstimatorsPoint estimators determine the best value of a parameterw.r.t. the data and certain quality criteria.

◦ Interval EstimatorsInterval estimators yield a region, a so-called confidence interval,in which the true value of the parameter lies with high certainty.

Christian Borgelt Data Mining / Intelligent Data Analysis 114

Inductive Statistics:

Point Estimation

Christian Borgelt Data Mining / Intelligent Data Analysis 115

Point Estimation

Not all statistics, that is, not all functions of the sample valuesare reasonable and useful estimator. Desirable properties are:

• ConsistencyWith growing data volume the estimated value should get closer and closerto the true value, at least with higher and higher probability.Formally: If T is an estimator for the parameter θ, it should be

∀ε > 0 : limn→∞P (|T − θ| < ε) = 1,

where n is the sample size.

• UnbiasednessAn estimator should not tend to over- or underestimate the parameter.Rather it should yield, on average, the correct value.Formally this means

E(T ) = θ.

Christian Borgelt Data Mining / Intelligent Data Analysis 116

Page 30: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Point Estimation

• EfficiencyThe estimation should be as precise as possible, that is, the deviation from thetrue value should be as small as possible. Formally: If T and U are two estimatorsfor the same parameter θ, then T is called more efficient than U if

D2(T ) < D2(U).

• SufficiencyAn estimator should exploit all information about the parameter contained in thedata. More precisely: two samples that yield the same estimate should have thesame probability (otherwise there is unused information).Formally: an estimator T for a parameter θ is called sufficientiff for all samples x = (x1, . . . , xn) with T (x) = t the expression

fX1(x1; θ) · · · fXn(xn; θ)

fT (t; θ)

is independent of θ.

Christian Borgelt Data Mining / Intelligent Data Analysis 117

Point Estimation: Example

Given: a family of uniform distributions on the interval [0, θ], i.e.

fX(x; θ) =

{1θ, if 0 ≤ x ≤ θ,0, otherwise.

Desired: an estimate for the unknown parameter θ.

• We will now consider two estimators for the parameter θand compare their properties.

◦ T = max{X1, . . . , Xn}◦ U = n+1

n max{X1, . . . , Xn}

• General approach:

◦ Find the probability density function of the estimator.

◦ Check the desirable properties by exploiting this density function.

Christian Borgelt Data Mining / Intelligent Data Analysis 118

Point Estimation: Example

To analyze the estimator T = max{X1, . . . , Xn}, we compute its density function:

fT (t; θ) = ddtFT (t; θ) = d

dtP (T ≤ t)

= ddtP (max{X1, . . . , Xn} ≤ t)

= ddtP(∧

ni=1Xi ≤ t

)= d

dt

n∏

i=1

P (Xi ≤ t)

= ddt(FX(t; θ))n = n · (FX(t; θ))n−1fX(t, θ)

where

FX(x; θ) =∫ x

−∞fX(x; θ) dx =

0, if x ≤ 0,xθ , if 0 ≤ x ≤ θ,1, if x ≥ θ.

Therefore it is

fT (t; θ) =n · tn−1θn

for 0 ≤ t ≤ θ, and 0 otherwise.

Christian Borgelt Data Mining / Intelligent Data Analysis 119

Point Estimation: Example

• The estimator T = max{X1, . . . , Xn} is consistent:

limn→∞P (|T − θ| < ǫ) = lim

n→∞P (T > θ − ǫ)

= limn→∞

∫ θ

θ−ǫn · tn−1θn

dt = limn→∞

[tn

θn

θ−ǫ

= limn→∞

(θn

θn− (θ − ǫ)n

θn

)

= limn→∞

(1−

(θ − ǫθ

)n)= 1

• It is not unbiased:

E(T ) =∫ ∞−∞

t · fT (t; θ) dt =∫ θ

0t · n · t

n−1

θndt

=

[n · tn+1(n + 1)θn

0

=n

n + 1θ < θ for n <∞.

Christian Borgelt Data Mining / Intelligent Data Analysis 120

Page 31: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Point Estimation: Example

• The estimator U = n+1n max{X1, . . . , Xn} has the density function

fU (u; θ) =nn+1

(n + 1)nun−1

θnfor 0 ≤ t ≤ n+1

n θ, and 0 otherwise.

• The estimator U is consistent (without formal proof).

• It is unbiased:

E(U) =∫ ∞−∞

u · fU (u; θ) du

=∫ n+1

n θ

0u · nn+1

(n + 1)nun−1

θndu

=nn+1

(n + 1)nθn

[un+1

n + 1

]n+1n θ

0

=nn+1

(n + 1)nθn· 1

n + 1

(n + 1

nθ)n+1

= θ

Christian Borgelt Data Mining / Intelligent Data Analysis 121

Point Estimation: Example

Given: a family of normal distributions NX(x;µ, σ2)

fX(x;µ, σ2) =1√2πσ2

exp

(−(x− µ)

2

2σ2

)

Desired: estimates for the unknown parameters µ and σ2.

• The median and the arithmetic mean of the sampleare both consistent and unbiased estimators for the parameter µ.

The median is less efficient than the arithmetic mean.

• The function V 2 = 1n∑ni=1(Xi − X)2 is a consistent, but biased estimator

for the parameter σ2 (it tends to underestimate the variance).

The function S2 = 1n−1

∑ni=1(Xi − X)2, however, is a consistent and unbiased

estimator for σ2 (this explains the definition of the empirical variance).

Christian Borgelt Data Mining / Intelligent Data Analysis 122

Point Estimation: Example

Given: a family of polynomial distributions

fX1,...,Xk(x1, . . . , xk; θ1, . . . , θk, n) =

n!∏ki=1 xi!

k∏

i=1

θxii ,

(n is the sample size, the xi are the frequencies of the different values ai,i = 1, . . . , k, and the θi are the probabilities with which the values ai occur.)

Desired: estimates for the unknown parameters θ1, . . . , θk

• The relative frequencies Ri =Xin of the different values ai, i = 1, . . . , k, are

◦ consistent,

◦ unbiased,

◦ most efficient, and

◦ sufficient estimators for the θi.

Christian Borgelt Data Mining / Intelligent Data Analysis 123

Inductive Statistics:

Finding Point Estimators

Christian Borgelt Data Mining / Intelligent Data Analysis 124

Page 32: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

How Can We Find Estimators?

• Up to now we analyzed given estimators,now we consider the question how to find them.

• There are three main approaches to find estimators:

◦ Method of MomentsDerive an estimator for a parameter from the moments of a distributionand its generator function.(We do not consider this method here.)

◦ Maximum Likelihood EstimationChoose the (set of) parameter value(s) that makes the sample most likely.

◦ Maximum A-posteriori EstimationChoose a prior distribution on the range of parameter values, apply Bayes’ ruleto compute the posterior probability from the sample, and choose the (set of)parameter value(s) that maximizes this probability.

Christian Borgelt Data Mining / Intelligent Data Analysis 125

Maximum Likelihood Estimation

• General idea: Choose the (set of) parameter value(s)that makes the sample most likely.

• If the parameter value(s) were known, it would be possible to compute the proba-bility of the sample. With unknown parameter value(s), however, it is still possibleto state this probability as a function of the parameter(s).

• Formally this can be described as choosing the value θ that maximizes

L(D; θ) = f (D | θ),

where D are the sample data and L is called the Likelihood Function.

• Technically the estimator is determined by

◦ setting up the likelihood function,

◦ forming its partial derivative(s) w.r.t. the parameter(s), and

◦ setting these derivatives equal to zero (necessary condition for a maximum).

Christian Borgelt Data Mining / Intelligent Data Analysis 126

Brief Excursion: Function Optimization

Task: Find values ~x = (x1, . . . , xm) such that f (~x) = f (x1, . . . , xm) is optimal.

Often feasible approach:

• A necessary condition for a (local) optimum (maximum or minimum) isthat the partial derivatives w.r.t. the parameters vanish (Pierre Fermat).

• Therefore: (Try to) solve the equation system that results from settingall partial derivatives w.r.t. the parameters equal to zero.

Example task: Minimize f (x, y) = x2 + y2 + xy − 4x− 5y.

Solution procedure:

1. Take the partial derivatives of the objective function and set them to zero:

∂f

∂x= 2x + y − 4 = 0,

∂f

∂y= 2y + x− 5 = 0.

2. Solve the resulting (here: linear) equation system: x = 1, y = 2.

Christian Borgelt Data Mining / Intelligent Data Analysis 127

Maximum Likelihood Estimation: Example

Given: a family of normal distributions NX(x;µ, σ2)

fX(x;µ, σ2) =1√2πσ2

exp

(−(x− µ)

2

2σ2

)

Desired: estimators for the unknown parameters µ and σ2.

The Likelihood Function, which describes the probability of the data, is

L(x1, . . . , xn;µ, σ2) =

n∏

i=1

1√2πσ2

exp

(−(xi − µ)

2

2σ2

).

To simplify the technical task of forming the partial derivatives,we consider the natural logarithm of the likelihood function, i.e.

lnL(x1, . . . , xn;µ, σ2) = −n ln

(√2πσ2

)− 1

2σ2

n∑

i=1

(xi − µ)2.

Christian Borgelt Data Mining / Intelligent Data Analysis 128

Page 33: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Maximum Likelihood Estimation: Example

• Estimator for the expected value µ:

∂µlnL(x1, . . . , xn;µ, σ

2) =1

σ2

n∑

i=1

(xi − µ) != 0

⇒n∑

i=1

(xi − µ) =

n∑

i=1

xi

− nµ !

= 0 ⇒ µ =1

n

n∑

i=1

xi

• Estimator for the variance σ2:

∂σ2lnL(x1, . . . , xn;µ, σ

2) = − n

2σ2+

1

2σ4

n∑

i=1

(xi − µ)2 != 0

⇒ σ2 =1

n

n∑

i=1

(xi − µ)2 =1

n

n∑

i=1

x2i −1

n2

n∑

i=1

xi

2

(biased!)

Christian Borgelt Data Mining / Intelligent Data Analysis 129

Maximum A-posteriori Estimation: Motivation

Consider the following three situations:

• A drunkard claims to be able to predict the side on which a thrown coin will land(head or tails). On ten trials he always states the correct side beforehand.

• A tea lover claims that she is able to taste whether the tea or the milk was pouredinto the cup first. On ten trials she always identifies the correct order.

• An expert of classical music claims to be able to recognize from a single sheet ofmusic whether the composer was Mozart or somebody else. On ten trials he isindeed correct every time.

Maximum likelihood estimation treats all situations alike, because formally the samplesare the same. However, this is implausible:

• We do not believe the drunkard at all, despite the sample data.

• We highly doubt the tea drinker, but tend to consider the data as evidence.

• We tend to believe the music expert easily.

Christian Borgelt Data Mining / Intelligent Data Analysis 130

Maximum A-posteriori Estimation

• Background knowledge about the plausible values can be incorporated by

◦ using a prior distribution on the domain of the parameter and

◦ adapting this distribution with Bayes’ rule and the data.

• Formally maximum a-posteriori estimation is defined as follows:find the parameter value θ that maximizes

f (θ | D) =f (D | θ)f (θ)

f (D)=

f (D | θ)f (θ)∫∞−∞ f (D | θ)f (θ) dθ

• As a comparison: maximum likelihood estimation maximizes

f (D | θ)

• Note that f (D) need not be computed: It is the same for all parameter valuesand since we are only interested in the value θ that maximizes f (θ | D) and notthe value of f (θ | D), we can treat it as a normalization constant.

Christian Borgelt Data Mining / Intelligent Data Analysis 131

Maximum A-posteriori Estimation: Example

Given: a family of binomial distributions

fX(x; θ, n) =

(n

x

)θx(1− θ)n−x.

Desired: an estimator for the unknown parameter θ.

a) Uniform prior: f (θ) = 1, 0 ≤ θ ≤ 1.

f (θ | D) = γ

(n

x

)θx(1− θ)n−x · 1 ⇒ θ =

x

n

b) Tendency towards 12: f (θ) = 6θ(1− θ), 0 ≤ θ ≤ 1.

f (θ | D) = γ

(n

x

)θx(1− θ)n−x · θ(1− θ) = γ

(n

x

)θx+1(1− θ)n−x+1

⇒ θ =x + 1

n + 2

Christian Borgelt Data Mining / Intelligent Data Analysis 132

Page 34: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Excursion: Dirichlet’s Integral

• For computing the normalization factors of the probability density functionsthat occur with polynomial distributions, Dirichlet’s Integral is helpful:

θ1. . .∫

θk

k∏

i=1

θxii dθ1 . . . dθk =

∏ki=1 Γ(xi + 1)

Γ(n + k), where n =

k∑

i=1

xi

and the Γ-function is the so-called generalized factorial:

Γ(x) =∫ ∞0

e−ttx−1 dt, x > 0,

which satisfies

Γ(x + 1) = x · Γ(x), Γ(12) =√π, Γ(1) = 1.

• Example: the normalization factor α for the binomial distribution priorf (θ) = α θ2(1− θ)3 is

α =1

∫θ θ

2(1− θ)3 dθ =Γ(5 + 2)

Γ(2 + 1) Γ(3 + 1)=

6!

2! 3!=

720

12= 60.

Christian Borgelt Data Mining / Intelligent Data Analysis 133

Maximum A-posteriori Estimation: Example

drunkard

0 0.5 1

θ

f(θ) Dirac pulse

0 0.5 1

θ

f(D|θ)

0 0.5 1

θ

f(θ|D) θ = 12

tea lover

0 0.5 1

θ

f(θ) αθ10(1− θ)10

0 0.5 1

θ

f(D|θ)

0 0.5 1

θ

f(θ|D) θ = 23

music expert

0 0.5 1

θ

f(θ) 12θ(1− θ)

0 0.5 1

θ

f(D|θ)

0 0.5 1

θ

f(θ|D) θ = 1112

Christian Borgelt Data Mining / Intelligent Data Analysis 134

Inductive Statistics:

Interval Estimation

Christian Borgelt Data Mining / Intelligent Data Analysis 135

Interval Estimation

• In general the estimated value of a parameter will differ from the true value.

• It is desirable to be able to make an assertion about the possible deviations.

• The simplest possibility is to state not only a point estimate,but also the standard deviation of the estimator:

t±D(T ) = t±√D2(T ).

• A better possibility is to find intervals that contain the true value with highprobability. Formally they can be defined as follows:Let A = gA(X1, . . . , Xn) and B = gB(X1, . . . , Xn) be two statistics with

P (A < θ < B) = 1− α, P (θ ≤ A) =α

2, P (θ ≥ B) =

α

2.

Then the random interval [A,B] (or an instantiation [a, b] of this interval)is called (1− α) · 100% confidence interval for θ.The value 1− α is called confidence level.

Christian Borgelt Data Mining / Intelligent Data Analysis 136

Page 35: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Interval Estimation

• This definition of a confidence interval is not specific enough:A and B are not uniquely determined.

• Common solution: Start from a point estimator T for the unknown parameter θand define A and B as functions of T :

A = hA(T ) and B = hB(T ).

• Instead of A ≤ θ ≤ B consider the corresponding event w.r.t. the estimator T ,that is, A∗ ≤ T ≤ B∗.

• Determine A = hA(T ) and B = hB(T ) from the inverse functionsA∗ = h−1A (θ) and B∗ = h−1B (θ).

Procedure: P (A∗ < T < B∗) = 1− α⇒ P (h−1A (θ) < T < h−1B (θ)) = 1− α⇒ P (hA(T ) < θ < hB(T )) = 1− α⇒ P (A < θ < B) = 1− α.

Christian Borgelt Data Mining / Intelligent Data Analysis 137

Interval Estimation: Example

Given: a family of uniform distributions on the interval [0, θ], i.e.

fX(x; θ) =

{1θ, if 0 ≤ x ≤ θ,0, otherwise.

Desired: a confidence interval for the unknown parameter θ.

• Start from the unbiased point estimator U = n+1n max{X1, . . . , Xn}:

P (U ≤ B∗) =∫ B∗

0fU (u; θ) du =

α

2

P (U ≥ A∗) =∫ n+1

n θ

A∗fU (u; θ) du =

α

2

• From the study of point estimators we know

fU (u; θ) =nn+1

(n + 1)nun−1

θn.

Christian Borgelt Data Mining / Intelligent Data Analysis 138

Interval Estimation: Example

• Solving the integrals gives us

B∗ = n

√α

2

n + 1

nθ and A∗ = n

√1− α

2

n + 1

nθ,

that is,

P(

n

√α

2

n + 1

nθ < U < n

√1− α

2

n + 1

nθ)= 1− α.

• Computing the inverse functions leads to

P

U

n√1− α

2n+1n

< θ <U

n√α2n+1n

= 1− α,

that is,

A =U

n√1− α

2n+1n

and B =U

n√α2n+1n

.

Christian Borgelt Data Mining / Intelligent Data Analysis 139

Inductive Statistics:

Hypothesis Testing

Christian Borgelt Data Mining / Intelligent Data Analysis 140

Page 36: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Hypothesis Testing

• A hypothesis test is a statistical procedure with which a decision is madebetween two contrary hypotheses about the process that generated the data.

• The two hypotheses may refer to

◦ the value of a parameter (Parameter Test),

◦ a distribution assumption (Goodness-of-Fit Test),

◦ the dependence of two attributes (Dependence Test).

• One of the two hypothesis is preferred, that is, in case of doubt the decisionis made in its favor. (One says that it gets the “benefit of the doubt”.)

• The preferred hypothesis is called the Null Hypothesis H0,

the other hypothesis is called the Alternative Hypothesis Ha.

• Intuitively: The null hypothesis H0 is put on trial. It is accused to be false.

Only if the evidence is strong enough, it is convicted (that is, rejected).

If there is (sufficient) doubt, however, it is acquitted (that is, accepted).

Christian Borgelt Data Mining / Intelligent Data Analysis 141

Hypothesis Testing

• The test decision is based on a test statistic,that is, a function of the sample values.

• The null hypothesis is rejected if the value of the test statisticlies inside the so-called critical region C.

• Developing a hypothesis test consists in finding the critical regionfor a given test statistic and significance level (see below).

• The test decision may be wrong. There are two possible types of errors:

Type 1: The null hypothesis H0 is rejected, even though it is correct.Type 2: The null hypothesis H0 is accepted, even though it is false.

• Type 1 errors are considered to be more severe,since the null hypothesis gets the “benefit of the doubt”.

• Hence it is tried to limit the probability of a type 1 error to a certain maximum α.This maximum value α is called significance level.

Christian Borgelt Data Mining / Intelligent Data Analysis 142

Parameter Test

• In a parameter test the contrary hypotheses refer to the value of a parameter,for example (one-sided test):

H0 : θ ≥ θ0, Ha : θ < θ0.

• For such a test usually a point estimator T is chosen as the test statistic.

• The null hypothesis H0 is rejected if the value t of the point estimator does notexceed a certain value c, the so-called critical value (that is, C = (−∞, c]).

• Formally the critical value c is determined as follows: We consider

β(θ) = Pθ(H0 is rejected) = Pθ(T ∈ C),

the so-called power β of the test.

• The power must not exceed the significance level α for values θ satisfying H0:

maxθ:θ satisfies H0

β(θ) ≤ α. (here: β(θ0) ≤ α)

Christian Borgelt Data Mining / Intelligent Data Analysis 143

Parameter Test: Intuition

• The probability of a type 1 error is the area under the estimator’sprobability density function f (T | θ0) to the left of the critical value c.(Note: This example illustrates H0 : θ ≥ θ0 and Ha : θ < θ0.)

T

f(T | θ0)

critical region C c θ0

probability ofa type 1 error

β(θ)

• Obviously the probability of a type 1 error depends on the locationof the critical value c: higher values mean a higher error probability.

• Idea: Choose the location of the cricital value so that the maximalprobability of a type 1 error equals α, the chosen significance level.

Christian Borgelt Data Mining / Intelligent Data Analysis 144

Page 37: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Parameter Test: Intuition

• What is so special about θ0 that we use f (T | θ0)?

T

f(T | θ)probability ofa type 1 error

β(θ)

critical region C c θ0 θ satisfying H0

• In principle, all θ satisfying H0 have to be considered,that is, all density functions f (T | θ) with θ ≥ θ0.

• Among these values θ, the one with the highest probability of a type 1 error(that is, the one with the highest power β(θ)) determines the critical value.

Intuitively: we consider the worst possible case.

Christian Borgelt Data Mining / Intelligent Data Analysis 145

Parameter Test: Example

• Consider a one-sided test of the expected value µ of a normal distributionN(µ, σ2)with known variance σ2, that is, consider the hypotheses

H0 : µ ≥ µ0, Ha : µ < µ0.

• As a test statistic we use the standard point estimator for the expected value

X =1

n

n∑

i=1

Xi.

This point estimator has the probability density

fX(x) = N(x;µ, σ

2

n

).

• Therefore it is (with the N(0, 1)-distributed random variable Z)

α = β(µ0) = Pµ0(X ≤ c) = P

(X − µ0σ/√n≤ c− µ0σ/√n

)= P

(Z ≤ c− µ0

σ/√n

).

Christian Borgelt Data Mining / Intelligent Data Analysis 146

Parameter Test: Example

• We have as a result that

α = Φ

(c− µ0σ/√n

),

where Φ is the distribution function of the standard normal distribution.

• The distribution function Φ is tabulated, because it cannot be represented in closedform. From such a table we retrieve the value zα satisfying α = Φ(zα).

• Then the critical value is

c = µ0 + zασ√n.

(Note that the value of zα is negative due to the usually small value of α.Typical values are α = 0.1, α = 0.05 or α = 0.01.)

• H0 is rejected if the value x of the point estimator X does not exceed c,otherwise it is accepted.

Christian Borgelt Data Mining / Intelligent Data Analysis 147

Parameter Test: Example

• Let σ = 5.4, n = 25 and x = 128. We choose µ0 = 130 and α = 0.05.

• From a standard normal distribution table we retrieve z0.05 ≈ −1.645 and get

c0.05 ≈ 130− 1.6455.4√25≈ 128.22.

Since x = 128 < 128.22 = c, we reject the null hypothesis H0.

• If, however, we had chosen α = 0.01, it would have been (with z0.01 ≈ −2.326):

c0.01 ≈ 130− 2.3265.4√25≈ 127.49

Since x = 128 > 127.49 = c, we would have accepted the null hypothesis H0.

• Instead of fixing a significance level α one may state the so-called p-value

p = Φ

(128− 130

5.4/√25

)≈ 0.032.

For α ≥ p = 0.032 the null hypothesis is rejected, for α < p = 0.032 accepted.

Christian Borgelt Data Mining / Intelligent Data Analysis 148

Page 38: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Parameter Test: p-value

• Let t be the value of the test statistic Tthat has been computed from a given data set.(Note: This example illustrates H0 : θ ≥ θ0 and Ha : θ < θ0.)

T

f(T | θ0)

t θ0

p-value of t

• The p-value is the probability that a value of t or lesscan be observed for the chosen test statistic T .

• The p-value is a lower limit for the significance level αthat may have been chosen if we wanted to reject the null hypothesis H0.

Christian Borgelt Data Mining / Intelligent Data Analysis 149

Parameter Test: p-value

Attention: p-values are often misused or misinterpreted!

• A low p-value does not mean that the result is very reliable!

All that matters for the test is whether the computed p-valueis below the chosen significance level or not.

(A low p-value could just be a chance event, an accident!)

• The significance level may not be chosen after computing the p-value,since we tend to choose lower significance levels if we know that they are met.

Doing so would undermine the reliability of the procedure!

• Stating p-values is only a convenient way of avoiding a fixed significance level(since significance levels are a matter of choice and thus user-dependent).

However: A significance level must still be chosenbefore a reported p-value is looked at.

Christian Borgelt Data Mining / Intelligent Data Analysis 150

Relevance of the Type-2 Error

• Reminder: There are two possible types of errors:

Type 1: The null hypothesis H0 is rejected, even though it is correct.

Type 2: The null hypothesis H0 is accepted, even though it is false.

• Type-1 errors are considered to be more severe,since the null hypothesis gets the “benefit of the doubt”.

• However, type-2 errors should not be neglected completely:

◦ It is always possible to achieve a vanishing probability of a type-1 error:Simply accept the null hypothesis in all instances, regardless of the data.

◦ Unfortunately such an approach maximizes the type-2 error.

• Generally, type-1 and type-2 errors are complementary quantities:

The lower we require the type-1 error to be (the lower the significance level),the higher will be the probability of a type-2 error.

Christian Borgelt Data Mining / Intelligent Data Analysis 151

Relationship between Type-1 and Type-2 Error

• Suppose there are only two possible parameter values θ0 and θ1 with θ1 < θ0.(That is, we have H0 : θ = θ0 and Ha : θ = θ1.)

T

f(T | θ0)f(T | θ1)

cθ1 θ0

probability of atype-1 error type-2 error

• Lowering the significance level α moves the critical value c to the left:lower type-1 error (red), but higher type-2 error (blue).

• Increasing the significance level α moves the critical value c to the right:higher type-1 error (red), but lower type-2 error (blue).

Christian Borgelt Data Mining / Intelligent Data Analysis 152

Page 39: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Inductive Statistics:

Model Selection

Christian Borgelt Data Mining / Intelligent Data Analysis 153

Model Selection

• Objective: select the model that best fits the data,taking the model complexity into account.

The more complex the model, the better it usually fits the data.

x

y

0 1 2 3 4 5 6 7 80

1

2

3

4

5

6

7 black line:regression line(2 free parameters)

blue curve:7th order regression polynomial(8 free parameters)

• The blue curve fits the data points perfectly, but it is not a good model.

Christian Borgelt Data Mining / Intelligent Data Analysis 154

Information Criteria

• There is a tradeoff between model complexity and fit to the data.

Question: How much better must a more complex model fit the datain order to justify the higher complexity?

• One approach to quantify the tradeoff: Information Criteria

Let M be a model and Θ the set of free parameters of M . Then:

ICκ(M,Θ | D) = − 2 lnP (D |M,Θ) + κ|Θ|,where D are the sample data and κ is a parameter.

Special cases:

◦ Akaike Information Criterion (AIC): κ = 2

◦ Bayesian Information Criterion (BIC): κ = lnn,where n is the sample size

• The lower the value of these measures, the better the model.

Christian Borgelt Data Mining / Intelligent Data Analysis 155

Minimum Description Length

• Idea: Consider the transmission of the data from a sender to a receiver.

Since the transmission of information is costly,the length of the message to be transmitted should be minimized.

• A good model of the data can be used to transmit the data with fewer bits.

However, the receiver does not know the model the sender usedand thus cannot decode the message.

Therefore: if the sender uses a model, he/she has to transmit the model as well.

• description length = length of model description+ length of data description

(A more complex model increases the length of the model description,but reduces the length of the data description.)

• The model that leads to the smallest total description length is the best.

Christian Borgelt Data Mining / Intelligent Data Analysis 156

Page 40: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Minimum Description Length: Example

• Given: a one-dimensional sample from a polynomial distribution.

• Question: are the probabilities of the attribute values sufficiently differentto justify a non-uniform distribution model?

• Coding using no model (equal probabilities for all values):

l1 = n log2 k,

where n is the sample size and k the number of attribute values.

• Coding using a polynomial distribution model:

l2 = log2(n + k − 1)!

n!(k − 1)!︸ ︷︷ ︸model description

+ log2n!

x1! . . . xk!︸ ︷︷ ︸data description

(Idea: Use a codebook with one page per configuration, that is, frequency distri-bution (model) and specific sequence (data), and transmit the page number.)

Christian Borgelt Data Mining / Intelligent Data Analysis 157

Minimum Description Length: Example

Some details about the codebook idea:

• Model Description:There are n objects (the sample cases) that have to be partitioned into k groups(one for each attribute value). (Model: distribute n balls on k boxes.)

Number of possible distributions:(n + k − 1)!

n!(k − 1)!

Idea: number of possible sequences of n + k − 1 objects (n balls and k − 1 boxwalls) of which n (the objects) and k − 1 (the box walls) are indistinguishable.

• Data Description:There are k groups of objects with ni, i = 1, . . . , k, elements in them.(The values of the nk are known from the model description.)

Number of possible sequences:n!

n1! . . . nk!

Christian Borgelt Data Mining / Intelligent Data Analysis 158

Summary Statistics

Statistics has two main areas:

• Descriptive Statistics

◦ Display the data in tables or charts.

◦ Summarize the data in characteristic measures.

◦ Reduce the dimensionality of the data with principal component analysis.

• Inductive Statistics

◦ Use probability theory to draw inferencesabout the process that generated the data.

◦ Parameter Estimation (point and interval)

◦ Hypothesis Testing (parameter, goodness-of-fit, dependence)

◦ Model Selection (tradeoff between fit and complexity)

Christian Borgelt Data Mining / Intelligent Data Analysis 159

Principles of Modeling

Christian Borgelt Data Mining / Intelligent Data Analysis 160

Page 41: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Principles of Modeling

• The Data Mining step of the KDD Process consists mainlyof model building for specific purposes (e.g. prediction).

• What type of model is to be built depends on the task, e.g.,

◦ if the task is numeric prediction, one may use a regression function,

◦ if the task is classification, one may use a decision tree,

◦ if the task is clustering, one may use a set of cluster prototypes,

◦ etc.

• Most data analysis methods comprise the following four steps:

◦ Select the Model Class (e.g. decision tree)

◦ Select the Objective Function (e.g. misclassification rate)

◦ Apply an Optimization Algorithm (e.g. top-down induction)

◦ Validate the Results (e.g. cross validation)

Christian Borgelt Data Mining / Intelligent Data Analysis 161

Model Classes

• In order to extract information from data,it is necessary to specify the general form the analysis result should have.

• We call this the model class or architecture of the analysis result.

• Attention: In Data Mining / Machine Learning the notion of a model classis considerably more general than, e.g., in statistics, where it reflectsa structure inherent in the data or represents the process of data generation.

• Typical distinctions w.r.t. model classes:

◦ Type of Model (e.g. linear function, rules, decision tree, clusters etc.)

◦ Global versus Local Model(e.g. regression models usually cover the whole data space whilerules are applicable only in the region where their antecedent is satisfied)

◦ Interpretable versus Black Box(rules and decision trees are usually considered as interpretable,artificial neural networks as black boxes)

Christian Borgelt Data Mining / Intelligent Data Analysis 162

Model Evaluation

• After a model has been constructed, one would like to know how “good” it is.

⇒ How can we measure the quality of a model?

• Desired: The model should generalize well and thus yield, on new data,an error (to be made precise) that is as small as possible.

• However, due to possible overfitting to the induction / training data(i.e. adaptations to features that are not regular, but accidental),the error on the training data is usually not too indicative.

⇒ How can we assess the (expected) performance on new data?

• General idea: Evaluate on a hold-out data set (validation data),that is, on data not used for building / training the predictor.

◦ It is (highly) unlikely that the validation data exhibitsthe same accidental features as the training data.

◦ Hence an evaluation on the validation data can providea good indication of the performance on new data.

Christian Borgelt Data Mining / Intelligent Data Analysis 163

Fitting Criteria and Score / Loss Functions

• In order to find the best or at least a good model for the given data,a fitting criterion is needed, usually in the form of an objective function

f :M→ IR,

whereM is the set of considered models.

• The objective function f may also be referred to as

◦ Score Function (usually to be maximized),

◦ Loss Function (usually to be minimized).

• Typical examples of objective functions are (m ∈M is a model, D the data)

◦ Mean squared error (MSE): f (m,D) = 1|D|

∑(~x,y)∈D (m(~x)− y)2

◦ Mean absolute error (MAE): f (m,D) = 1|D|

∑(~x,y)∈D |m(~x)− y|

◦ Accuracy: f (m,D) = 1|D|

∑(~x,y)∈D δm(~x),y

Christian Borgelt Data Mining / Intelligent Data Analysis 164

Page 42: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Classification Evaluation

• The most common loss function for classification is the misclassification rate

E(m,D) = 1|D|

∑(~x,y)∈D (1− δm(~x),y),

and (alternatively) its dual, the score function accuracy

A(m,D) = 1|D|

∑(~x,y)∈D δm(~x),y = 1− E(m,D).

• A confusion matrix displays the misclassifications in more detail. It is a tablein which the rows represent the true classes and the columns the predicted classes.

• Each entry specifies how many objects from the true class of the correspondingrow are classified as belonging to the class of the corresponding column.

• The accuracy is the sum of the diagonal entries divided by the sum of all entries.

The misclassification rate (or simply error rate) is the sum ofthe off-diagonal entries divided by the sum of all entries.

• An ideal classifier has non-zero entries only on the diagonal.

Christian Borgelt Data Mining / Intelligent Data Analysis 165

Reminder: The Iris Data

pictures not available in online version

• Collected by Edgar Anderson on the Gaspe Peninsula (Canada).

• First analyzed by Ronald Aylmer Fisher (famous statistician).

• 150 cases in total, 50 cases per Iris flower type.

• Measurements of sepal length and width and petal length and width (in cm).

• Most famous data set in pattern recognition and data analysis.

Christian Borgelt Data Mining / Intelligent Data Analysis 166

Reminder: The Iris Data

5 6 7 8

2

2.5

3

3.5

4

4.5

sepal length / cm

sepa

l wid

th /

cm

Iris setosaIris versicolorIris virginica

1 2 3 4 5 6 70

0.5

1

1.5

2

2.5

petal length / cm

peta

l wid

th /

cm

Iris setosaIris versicolorIris virginica

• Scatter plots of the iris data set for sepal length vs. sepal width (left)and for petal length vs. petal width (right).All quantities are measured in centimeters (cm).

Christian Borgelt Data Mining / Intelligent Data Analysis 167

Classification Evaluation: Confusion Matrix

• The table below shows a possible confusion matrix for the Iris data set.

predicted class

true class Iris setosa Iris versicolor Iris virginica

Iris setosa 50 0 0

Iris versicolor 0 47 3

Iris virginica 0 2 48

• From this matrix, we can see that all cases of the class Iris setosa are classifiedcorrectly and no case of another class is wrongly classified as Iris setosa.

• A few cases of the other classes are wrongly classified:three cases of Iris versicolor are classified as Iris virginica,two cases of Iris virginica are classified as Iris versicolor.

• The misclassification rate is E = 2+350+47+3+2+48 =

5150 ≈ 3.33%.

• The accuracy is A = 50+47+4850+47+3+2+48 =

145150 ≈ 96.67%.

Christian Borgelt Data Mining / Intelligent Data Analysis 168

Page 43: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Classification Evaluation: Two Classes

• For many classification problems there are only two classesthat the classifier is supposed to distinguish.

• Let us call the two classes plus (or positive) and minus (or negative).

• The classifier can make two different kinds of mistakes:

◦ Cases of the class minus may be wrongly assigned to the class plus.These cases are called false positives (fp).

◦ Vice versa, cases of the class plus may be wrongly classified as minus.Such cases are called false negatives (fn).

• The cases that are classified correctly are called true positives (tp)and true negatives (tn), respectively.

• error rate: E =fp + fn

tp + fn + fp + tn

• accuracy: A =tp + tn

tp + fn + fp + tn

Confusion matrix:

true predicted class

class plus minus

plus tp fn p

minus fp tn n

Christian Borgelt Data Mining / Intelligent Data Analysis 169

Classification Evaluation: Precision and Recall

• Sometimes one would like to capture not merely the overall classification accuracy,but how well the individual classes are recognized.

• Especially if the class distribution is skewed, that is, if there are large differencesin the class frequencies, overall measures may give a wrong impression.

• For example, if in a two class problem

◦ one class occurs in 98% of all cases,◦ while the other covers only the remaining 2%,

a classifier that always predicts the first class reaches an impressive accuracyof 98%—without distinguishing between the classes at all.

• Such unpleasant situations are fairly common in practice, for example:

◦ illnesses are (fortunately) rare and◦ replies to mailings are (unfortunately?) scarce.

Hence: predict that everyone is healthy or a non-replier.

• However, such a classifier is useless to a physician or a product manager.

Christian Borgelt Data Mining / Intelligent Data Analysis 170

Classification Evaluation: Precision and Recall

• In such cases (skewed class distribution) higher error rates are usually acceptedin exchange for a better coverage of the minority class.

• In order to allow for such a possibility, the following two measures may be used:

◦ Precision: π =tp

tp + fp◦ Recall: ρ =

tp

tp + fn

[Perry, Kent & Berry 1955]

• In other words:precision is the ratio of true positives to all data points classified as positive;recall is the ratio of true positives to all actually positive data points.

• In yet other words:precision is the fraction of data points for which a positive classification is correct;recall is the fraction of positive data points that is identified by the classifier.

• Precision and recall are usually complementary quantities:higher precision may be obtained at the price of lower recall and vice versa.

Christian Borgelt Data Mining / Intelligent Data Analysis 171

Classification Evaluation: Other Quantities I• recall, sensitivity, hit rate, or true positive rate (TPR)

TPR =tp

p=

tp

tp + fn= 1− FNR

• specificity, selectivity or true negative rate (TNR)

TNR =tn

n=

tn

tn + fp= 1− FPR

• precision or positive predictive value (PPV)

PPV =tp

tp + fp

• negative predictive value (NPV)

NPV =tn

tn + fn

• miss rate or false negative rate (FNR)

FNR =fn

p=

fn

fn + tp= 1− TPR

Christian Borgelt Data Mining / Intelligent Data Analysis 172

Page 44: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Classification Evaluation: Other Quantities II• fall-out or false positive rate (FPR)

FPR =fp

n=

fp

fp + tn= 1− TNR

• false discovery rate (FDR)

FDR =fp

fp + tp= 1− PPV

• false omission rate (FOR)

FOR =fn

fn + tn= 1− NPV

• accuracy (ACC)

ACC =tp + tn

p + n=

tp + tn

tp + tn + fp + fn

• misclassification rate or error rate (ERR)

ERR =fp + fn

p + n=

fp + fn

tp + tn + fp + fn

Christian Borgelt Data Mining / Intelligent Data Analysis 173

Classification Evaluation: F-Measure

• With precision and recall we have two numbers that assess the quality of a classifier.

• A common way to combine them into one number is to compute the F1 measure[Rijsbergen 1979], which is the harmonic mean of precision and recall:

F1 =2

1π + 1

ρ

=2πρ

π + ρ.

In this formula precision and recall have the same weight.

• The generalized F measure [Rijsbergen 1979] introduces a mixing parameter.It can be found in several different, but basically equivalent versions, for example:

Fα =1

απ + 1−α

ρ

=πρ

αρ + (1− α)π, α ∈ [0, 1],

or

Fβ =1 + β2

1π + β2

ρ

=πρ(1 + β2)

ρ + β2π, β ∈ [0,∞).

Obviously, the standard F1 measure results for α = 12 or β = 1, respectively.

Christian Borgelt Data Mining / Intelligent Data Analysis 174

Classification Evaluation: F-Measure

• The generalized F measure is [Rijsbergen 1979]:

Fα =πρ

αρ + (1− α)π, α ∈ [0, 1], Fβ =πρ(1 + β2)

ρ + β2π, β ∈ [0,∞).

• By choosing the mixing parameters α or β it can be controlledwhether the focus should be more on precision or on recall:

◦ For α > 12 or β > 1 the focus is more on precision;

for α = 1 or β = 0 we have Fα = Fβ = π.

◦ For α < 12 or β < 1 the focus is more on recall;

for α = 0 or β →∞ we have Fα = Fβ = ρ.

• However, this possibility is rarely used, presumably,because precision and recall are usually considered to be equally important.

• Note that precision and recall and thus the generalized F measure as well asits special case, the F1 measure, focus on one class (namely the positive class).Exchanging the two classes usually changes all of these measures.

Christian Borgelt Data Mining / Intelligent Data Analysis 175

Classification Evaluation: More Than Two Classes

• The misclassification rate (or error rate) and the accuracycan be used regardless of the number of classes (whether only two or more).

• In contrast, precision, recall and F measure are defined only for two classes.

• However, they can be generalized to more than two classesby computing them for each class separately and averaging the results.

• In this approach, each class in turn is seen as the positive class (plus)while all other classes together form the negative class (minus).

• Macro-averaging (1st possibility of averaging) [Sebastini 2002]

◦ precision: πmacro =1

c

c∑

k=1

πk =1

c

c∑

k=1

tp(k)

tp(k) + fp(k)

◦ recall: ρmacro =1

c

c∑

k=1

ρk =1

c

c∑

k=1

tp(k)

tp(k) + fn(k)

Here c is the number of classes.

Christian Borgelt Data Mining / Intelligent Data Analysis 176

Page 45: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Classification Evaluation: More Than Two Classes

• Class-weighted averaging (2nd possibility of averaging)

◦ precision: πwgt =c∑

k=1

nknπk =

1

n

c∑

k=1

tp(k) + fn(k)

tp(k) + fp(k)· tp(k)

◦ recall: ρwgt =c∑

k=1

nknρk =

1

n

c∑

k=1

tp(k)

Here c is again the number of classes,nk is the number of cases belonging to class k, k = 1, . . . , c, andn is the total number of cases, n =

∑ck=1 nk.

• While macro-averaging treats each class as having the same weight(thus ignoring the (possibly skewed) class frequencies)class-weighted averaging takes the class frequencies into account.

• Note that class-weighted average recall is equivalent to accuracy, since∑ck=1 tp

(k) is simply the sum of the diagonal elements of the confusion matrixand n, the total number of cases, is the sum over all entries.

Christian Borgelt Data Mining / Intelligent Data Analysis 177

Classification Evaluation: More Than Two Classes

• Micro-averaging (3rd possibility of averaging) [Sebastini 2002]

◦ precision: πmicro =

∑ck=1 tp

(k)

∑ck=1

(tp(k) + fp(k)

) =1

n

c∑

k=1

tp(k)

◦ recall: ρmicro =

∑ck=1 tp

(k)

∑ck=1

(tp(k) + fn(k)

) =1

n

c∑

k=1

tp(k)

Here c is again the number of classes and n is the total number of cases.This averaging renders precision and recall identical and equivalent to accuracy.

• As a consequence, micro-averaging is not useful in this setting,but it may be useful, e.g., for averaging results over different data sets.

• For all different averaging approaches, the F1 measure may be computedas the harmonic mean of (averaged) precision and recall.

• Alternatively, the F1 measure may be computed for each class separatelyand then averaged in analogy to the above methods.

Christian Borgelt Data Mining / Intelligent Data Analysis 178

Classification Evaluation: Misclassification Costs

• Misclassifications may also be handled via misclassification costs.

• Misclassification costs are specified in a matrix analogous to a confusion matrix,that is, as a table the rows of which refer to the true classand the columns of which refer to the predicted class.

◦ The diagonal of a misclassification cost matrix is zero (correct classifications).

◦ The off-diagonal elements specify the costs of a specific misclassification:entry xi,j specifies the costs of misclassifying class i as class j.

• If a cost matrix X = (xi,j)1≤i,j≤c is given(like the one on the right), the expectedloss is used as the objective function:

L(m,D) =c∑

i=1

c∑

j=1

pi,j · xi,j

Here pi,j is the (relative) frequency withwhich class i is misclassified as class j.

true predicted classclass 1 2 . . . c

1 0 x1,2 . . . x1,c2 x2,1 0 . . . x2,c... ... ... . . . ...c xc,1 xc,2 . . . 0

Christian Borgelt Data Mining / Intelligent Data Analysis 179

Classification Evaluation: Misclassification Costs

• Misclassification costs generalize the misclassification rate,which results as the special case of equal misclassification costs.

• With misclassification costs one can avoid the problems caused by skewed classdistributions, because it can take into account that certain misclassificationscan have stronger consequences or higher costs than others.

◦ Misclassifying a sick patient as healthy has high costs(as this leaves the disease untreated).

◦ Misclassifying a healthy patient as sick has low costs(although the patient may have to endure additional tests,it will finally be revealed that he/she is healthy).

◦ Not sending an ad to a prospective buyer has high costs(because the seller loses the revenue from the sale).

◦ Sending an ad to a non-buyer has low costs(only the cost of the mailing, which may be very low, is lost).

• However, specifying proper costs can be tedious and time consuming.

Christian Borgelt Data Mining / Intelligent Data Analysis 180

Page 46: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Classification Evaluation: ROC Curves

• Some classifiers (can) yield for every case to be classifieda probability or confidence for each class.

• In such a case it is common to assign a case to the classfor which the highest confidence / probability is produced.

• In the case of two classes, plus and minus, one may assign a case to class plusif the probability for this class exceeds 0.5 and to class minus otherwise.

• However, one may also be more careful and assign a case to class plus onlyif the probability exceeds, e.g., τ = 0.8, leading to fewer false positives.

• On the other hand, choosing a threshold τ < 0.5 leads to more true positives.

• The trade-off between true positives and false positives is illustratedby the receiver operating characteristic curve (ROC curve)that shows the true positive rate versus the false positive rate.

• The area under the (ROC) curve (AUC) may be used as an indicatorhow well a classifier solves a given problem.

Christian Borgelt Data Mining / Intelligent Data Analysis 181

Classification Evaluation: ROC Curves

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

false positive rate

true

posi

tive

rate

perfectrandom“real”

ROC curves

• ROC curve: For all choices of the threshold τa new point is drawn at the respective coordinatesof false positive rate and true positive rate.

• These dots are connected to form a curve.

• The curves on the left are idealized;actual ROC curves are (usually) step functions.

• Diagonal segments may be used if the same prob-ability is assigned to cases of different classes.

• An ideal ROC curve (green) jumps to 100% true positives without producing anyfalse positives, then adds the remaining cases as false positives.

• A random classifier, which assigns random probability / confidence values to thecases, is represented by the (idealized) red ROC curve (“expected” ROC curve).

• An actual classifier may produce an ROC curve like the blue one.

Christian Borgelt Data Mining / Intelligent Data Analysis 182

Classification Evaluation: ROC Curves

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

false positive rate

true

posi

tive

rate

perfectrandom“real”

ROC curves

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

false positive rate

true

posi

tive

rate

random ROC curves0 0.2 0.4 0.6 0.8 1

0

0.2

0.4

0.6

0.8

1

false positive rate

true

posi

tive

rate

random ROC curves

• A random classifier, which assigns random probability / confidence values to thecases, is represented by the (idealized) red ROC curve (“expected” ROC curve).

• This line is idealized, because different random classifiersproduce different ROC curves that scatter around this diagonal.

• middle: 50 positive, 50 negative cases; right: 250 positive, 250 negative cases;the diagrams show 100 random ROC curves each, with one highlighted in red.

Christian Borgelt Data Mining / Intelligent Data Analysis 183

Classification Evaluation: Area Under the (ROC) Curve

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

false positive rate

true

posi

tive

rate

perfectrandom“real”

ROC curves

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

false positive rate

true

posi

tive

rate

ROC curveAUC version 1

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

false positive rate

true

posi

tive

rate

ROC curveAUC version 2

• The Area Under the (ROC) Curve (AUC) may be defined in two ways:

◦ the area extends down to the horizontal axis (more common),◦ the area extends down to the diagonal and is doubled (more intuitive).

• It is AUC2 = 2(AUC1 − 12) and AUC1 =

12AUC2 +

12.

• For a random ROC curve it is AUC1 ≈ 0.5, but AUC2 ≈ 0.Note: AUC2 may become negative, AUC1 is always non-negative!

Christian Borgelt Data Mining / Intelligent Data Analysis 184

Page 47: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Algorithms for Model Fitting

• An objective (score / loss) function does not tell us directlyhow to find the best or at least a good model.

• To find a good model, an optimization method is needed(i.e., a method that optimizes the objective function).

• Typical examples of optimization methods are

◦ Analytical / Closed Form SolutionsSometimes a solution can be obtained in a closed form (e.g. linear regression).

◦ Combinatorial OptimizationIf the model space is small, exhaustive search may be feasible.

◦ Gradient MethodsIf the objective function is differentiable, a gradient method (gradient ascentor descent) may be applied to find a (possibly only local) optimum.

◦ Random Search, Greedy Strategies and Other HeuristicsFor example, hill climbing, greedy search, alternating optimization,widening, evolutionary and swarm-based algorithms etc.

Christian Borgelt Data Mining / Intelligent Data Analysis 185

Causes of Errors

• One may distinguish between four types of errors:

◦ the pure / intrinsic / experimental / Bayes error,

◦ the sample / variance error or scatter,

◦ the lack of fit / model / bias error,

◦ the algorithmic error.

• Pure / Intrinsic / Experimental / Bayes Error

◦ Inherent in the data, impossible to overcome by any model.

◦ Due to noise, random variations, imprecise measurements,or the influence of hidden (unobservable) variables.

◦ For any data points usually several classes (if classification)or numeric values (if numeric prediction) have a non-vanishing probability.

However, usually a predictor has to produce a single class / specific value;hence it cannot yield correct predictions all of the time.

Christian Borgelt Data Mining / Intelligent Data Analysis 186

Causes of Errors: Bayes Error

• The term “Bayes error” is usually used in the context of classification.

• It describes a situation, in which for any data point more than one class is possible(multiple classes have a non-vanishing probability).

perfect class separation more difficult problem strongly overlapping classes

• If classes overlap in the data space, no model can perfectly separate them.

Christian Borgelt Data Mining / Intelligent Data Analysis 187

Causes of Errors: Bayes Error

• In the (artificial) example on the previous slide, the samples of each classare drawn from two bivariate normal distributions (four in total).

• In all three cases, the means of the distributions are the same, only the variancesdiffer, leading to a greater overlap of the classes the greater the variances.

• However, this is not necessarily the only (relevant) situation.Classes may have more or less identical means and rather differ in their variances.

• Example: Three darts players try to hit the centerof the dartboard (the so-called bull’s eye).

• Assume, one of the players is a professional, oneis a hobby player and one is a complete beginner.

• Objective: Predict who has thrown the dart,given the point where the dart hit the dartboard.

Christian Borgelt Data Mining / Intelligent Data Analysis 188

Page 48: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Causes of Errors: Bayes Error• Example: Three darts players try to hit the centerof the dartboard (the so-called em bull’s eye).

• Assume, one of the players is a professional, oneis a hobby player and one is a complete beginner.

• Objective: Predict who has thrown the dart,given the point where the dart hit the dartboard.

professional hobby player beginner

Christian Borgelt Data Mining / Intelligent Data Analysis 189

Causes of Errors: Bayes Error• Example: Three darts players try to hit the centerof the dartboard (the so-called em bull’s eye).

• Assume, one of the players is a professional, oneis a hobby player and one is a complete beginner.

• Objective: Predict who has thrown the dart,given the point where the dart hit the dartboard.

• Simple classification rule: Assumingequal frequency of the three classes,assign the class with the highest likelihood.(one-dimensional normal distributions ⇒)

• Attention: Do not confuseclassification boundarieswith class boundaries(which may not even exist). –8 –4 0 4 8

0

0.1

0.2

0.3

0.4

attribute value

prob

abili

tyde

nsity

Christian Borgelt Data Mining / Intelligent Data Analysis 190

Causes of Errors: Sample Error

• Sample / Variance Error or Scatter

◦ The sample error is caused by the fact that the given datais only an imperfect representation of the underlying distribution.

◦ According to the laws of large numbers, the sample distribution converges inprobability to the true distribution when the sample size approaches infinity.

◦ However, a finite sample can deviate significantly from the true distributionalthough the probability for such a deviation might be small.

• The bar chart on the right shows the resultfor throwing a fair die 60 times.

• In the ideal case, one would expect each ofthe numbers 1, . . . , 6 to occur 10 times.

• But for this sample, the distributiondoes not look uniform. 1 2 3 4 5 6

0

5

10

15

20

number of pips

freq

uenc

y

Christian Borgelt Data Mining / Intelligent Data Analysis 191

Causes of Errors: Sample Error

• Another source for sample errors are measurements with limited precisionand round-off errors in features derived by computations.

• Sometimes the sample is also (systematically) biased.

◦ Consider a bank that supplies loans to customers.

◦ Based on historical data available on customers who have obtained loans,the bank wants to estimate a new customer’s credit-worthiness(i.e., the probability that the customer will pay back a loan).

◦ The collected data will be biased towards better customers,because customers with a more problematic financial statushave not been granted loans.

◦ Therefore, no information is available for such customerswhether they might have paid back the loan nevertheless.

◦ In statistical terms: the sample is not representative, but biased.

◦ (Cf. also e.g. the Yalemen example on exercise sheet 1.)

Christian Borgelt Data Mining / Intelligent Data Analysis 192

Page 49: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Causes of Errors: Model Error

• A large error might be caused by a high pure error,but it might also be due to a lack of fit.

• If the set of considered models is too simple for the structure inherent in the data,no model (from this set) will yield a small error.

• Such an error is also called model error or bias error.(Because an improper choice of the model class introduces a bias into the fit.)

• The chart on the right shows a regression linefitted to data with no pure error.

• However, the data points originatefrom a quadratic and not from a linear function.

• As a consequence,there is a considerable lack of fit.

0 2 4 6 8 10

0

20

40

60

80

100

x

y

Christian Borgelt Data Mining / Intelligent Data Analysis 193

Reminder: Model Selection

• Objective: select the model that best fits the data,taking the model complexity into account.

The more complex the model, the better it usually fits the data.

x

y

0 1 2 3 4 5 6 7 80

1

2

3

4

5

6

7 black line:regression line(2 free parameters)

blue curve:7th order regression polynomial(8 free parameters)

• The blue curve fits the data points perfectly, but it is not a good model.

• On the other hand, too simple a model can lead to a lack of fit.

Christian Borgelt Data Mining / Intelligent Data Analysis 194

Causes of Errors: Algorithmic Error

• The algorithmic error is caused by the methodthat is used to fit the model or the model parameters.

• In the ideal case, if an analytical solution for the optimum of the objective functionexists, the algorithmic error is zero or only caused by numerical problems.

• However, in many cases an analytical solution cannot be providedand heuristic strategies are needed to fit the model to the data.

• Even if a model exists with a very good fit—the global optimum of the objectivefunction—the heuristic optimization strategy might only be able to find a localoptimum with a much larger error.

• This error is neither caused by the pure errornor by the error due to the lack of fit (model error).

• Most of the time, the algorithmic error will not be considered and it is assumedthat the heuristic optimization strategy is chosen well enough to find an optimumthat is at least close to the global optimum.

Christian Borgelt Data Mining / Intelligent Data Analysis 195

Machine Learning Bias and Variance

• The four types of errors that were mentioned can be grouped into two categories.

• The algorithmic and the model error can be controlled to a certain extend,since we are free to choose a suitable model and algorithm.

These errors are also called machine learning bias.

• On the other hand, we have no influence on the pure / intrinsic error or thesample error (at least if the data to be analyzed have already been collected).

These errors are also called machine learning variance.

• Note that this decomposition differs from the one commonly known in statistics,where, for example, the mean squared error of an estimator θ for a parameter θcan be decomposed in terms of the variance of the estimator and its bias:

MSE = Var(θ) + (Bias(θ))2.

Here the variance depends on the intrinsic error, i.e. on the variance of the ran-dom variable from which the sample is generated, but also on the choice of theestimator θ∗ which is considered part of the model bias in machine learning.

Christian Borgelt Data Mining / Intelligent Data Analysis 196

Page 50: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Learning Without Bias? No Free Lunch Theorem

• The different types of errors or biases have an interesting additional impacton the ability to find a suitable model for a given data set:

If we have no model bias, we will not be able to generalize.

• The model bias is actually essential to put some sort of a-priori knowledgeinto the model learning process.

• Essentially this means that we need to constrain

◦ either the types of models that are available

◦ or the way we are searching for a suitable model (or both).

• The technical reason for this need is the No Free Lunch Theorem.[Wolpert and MacReady 1997]

• Intuitively, this theorem states that if an algorithm (e.g. a machine learning or opti-mization algorithm) performs well on a certain class of problems, then it necessarilypays for that with degraded performance on the set of all remaining problems.

Christian Borgelt Data Mining / Intelligent Data Analysis 197

Model Validation

• Due to possible overfitting to the induction / training data(i.e. adaptations to features that are not regular, but accidental),the error on the training data is not too indicative of the error on new data.

• General idea of model validation:Evaluate on a hold-out data set (validation data),that is, on data not used for building / training the model.

◦ Split the data into two parts: training data and validation data(often recommended: training data 80%, validation data 20%).

◦ Train a model on the training data and evaluate it on the validation data.

• It is (highly) unlikely that the validation data exhibitsthe same accidental features as the training data.

• However, by chance, we might be lucky (unlucky) that the validation data containseasy (difficult) examples leading to an over-optimistic (-pessimistic) evaluation.

• Solution approach: repeat the split, the training and the evaluation.

Christian Borgelt Data Mining / Intelligent Data Analysis 198

Model Validation: Cross Validation

• General method to evaluate / to predict the performance of models.

• Serves the purpose to estimate the error (rate) on new example cases.

• Procedure of cross validation:

◦ Split the given data set into n so-called folds of equal size(n-fold cross validation). Often recommended: n = 10.

◦ Combine n− 1 folds into a training data set,build a classifier, and test it on the n-th fold (the hold-out fold).

◦ Do this for all n possible selections of n− 1 foldsand average the error (rates).

• Special case: leave-1-out cross validation (a.k.a. jackknife method).(use as many folds as there are example cases)

• The final classifier is learned from the full data set(in order to exploit all available information).

Christian Borgelt Data Mining / Intelligent Data Analysis 199

Model Validation: Cross Validation

• Cross validation is also a method that may be used to determine goodso-called hyper-parameters of a model building method.

• Distinction between parameters and hyper-parameters:

◦ parameter refers to parameters of a modelas it is produced by an algorithm, for example, regression coefficients;

◦ hyper-parameter refers to the parameters of a model-building method,for example, the maximum height of a decision tree, the number of treesin a random forest, the learning rate for a neural network etc.

• Hyper-parameters are commonly chosen by runninga cross validation for various choices of the hyper-parameter(s)and finally choosing the one that produced the best models(in terms of their evaluation on the validation data sets).

• A final model is built using the found values for the hyper-parameterson the whole data set (to maximize the exploitation of information).

Christian Borgelt Data Mining / Intelligent Data Analysis 200

Page 51: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Model Validation: Bootstrapping

• Bootstrapping is a resampling technique from statisticsthat does not directly evaluate the model error,but aims at estimating the variance of the estimated model parameters.

• Therefore, bootstrapping is suitable for models with real-valued parameters.

• Like in cross-validation, the model is not only computed once, but multiple times.

• For this purpose, k bootstrap samples, each of size n, are drawn randomlywith replacement from the original data set with n records.

• The model is fitted to each of these bootstrap samples,so that we obtain k estimates for the model parameters.

• Based on these k estimates the empirical standard deviation can be computedfor each parameter to provide an assessment how reliable its estimation is.

• It is also possible to compute confidence intervals for the parametersbased on bootstrapping.

Christian Borgelt Data Mining / Intelligent Data Analysis 201

Model Validation: Bootstrapping

• The figure on the right shows a data setwith n = 20 data points from whichk = 10 bootstrap samples were drawn.

• For each of the bootstrap samplesthe corresponding regression line is shown.

0 5 10 15 20

0

2

4

6

8

x

y

sample intercept slope

1 0.3801791 0.3749113

2 0.5705601 0.3763055

3 −0.2840765 0.4078726

4 0.9466432 0.3532497

5 1.4240513 0.3201722

6 0.9386061 0.3596913

7 0.6992394 0.3417433

8 0.8300100 0.3385122

9 1.1859194 0.3075218

10 0.2496341 0.4213876

mean 0.6940766 0.3601367

std. dev. 0.4927206 0.0361004

• The resulting parameter estimates forthe intercept and the slope of the regression lineare listed in the table on the left.

• The standard deviation for the slopeis much lower than for the intercept, so thatthe estimation for the slope is more reliable.

Christian Borgelt Data Mining / Intelligent Data Analysis 202

Regression

Christian Borgelt Data Mining / Intelligent Data Analysis 203

Regression

• General Idea of Regression

◦ Method of least squares

• Linear Regression

◦ An illustrative example

• Polynomial Regression

◦ Generalization to polynomial functional relationships

• Multivariate Regression

◦ Generalization to more than one function argument

• Logistic Regression

◦ Generalization to non-polynomial functional relationships

• Logistic Classification

◦ Modelling 2-class problems with a logistic function

• Robust Regression

◦ Dealing with outliers

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 204

Page 52: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Regression: Method of Least Squares

Regression is also known as Method of Least Squares. (Carl Friedrich Gauß)(also known as Ordinary Least Squares, abbreviated OLS)

Given: • A dataset ((~x1, y1), . . . , (~xn, yn)) of n data tuples(one or more input values and one output value) and

• a hypothesis about the functional relationshipbetween response and predictor values,e.g. Y = f (X) = a + bX + ε.

Desired: • A parameterization of the conjectured functionthat minimizes the sum of squared errors (“best fit”).

Depending on

• the hypothesis about the functional relationship and

• the number of arguments to the conjectured function

different types of regression are distinguished.

Christian Borgelt Data Mining / Intelligent Data Analysis 205

Reminder: Function Optimization

Task: Find values ~x = (x1, . . . , xm) such that f (~x) = f (x1, . . . , xm) is optimal.

Often feasible approach:

• A necessary condition for a (local) optimum (maximum or minimum) is thatthe partial derivatives w.r.t. the parameters vanish (Pierre de Fermat, 1607–1665).

• Therefore: (Try to) solve the equation system that results from settingall partial derivatives w.r.t. the parameters equal to zero.

Example task: Minimize f (x, y) = x2 + y2 + xy − 4x− 5y.

Solution procedure:

1. Take the partial derivatives of the objective function and set them to zero:

∂f

∂x= 2x + y − 4 = 0,

∂f

∂y= 2y + x− 5 = 0.

2. Solve the resulting (here: linear) equation system: x = 1, y = 2.

Christian Borgelt Data Mining / Intelligent Data Analysis 206

Linear Regression: General Approach

Given: • A dataset ((x1, y1), . . . , (xn, yn)) of n data tuples and

• a hypothesis about the functional relationship,e.g. Y = f (X) = a + bX + ε.

Approach: Minimize the sum of squared errors, that is,

F (a, b) =n∑

i=1

(f (xi)− yi)2 =n∑

i=1

(a + bxi − yi)2.

Necessary conditions for a minimum(also known as Fermat’s theorem, after Pierre de Fermat, 1607–1665):

∂F

∂a=

n∑

i=1

2(a + bxi − yi) = 0 and

∂F

∂b=

n∑

i=1

2(a + bxi − yi)xi = 0

Christian Borgelt Data Mining / Intelligent Data Analysis 207

Linear Regression: Example of Error Functional

0 1 2 3

0

1

2

x

y

• A very simple data set (4 points),to which a line is to be fitted.

• The error functional for linear regression

F (a, b) =n∑

i=1

(a + bxi − yi)2

(same function, two different views).

–2–1

01

23

4–1

0

1

0

10

20

30

ab

F(a,b)

–2 –1 01

23

4

–1

0

10

10

20

30

a

ˆb

F(a,b)

Christian Borgelt Data Mining / Intelligent Data Analysis 208

Page 53: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Linear Regression: Normal Equations

Result of necessary conditions: System of so-called normal equations, that is,

na +

n∑

i=1

xi

b =

n∑

i=1

yi,

n∑

i=1

xi

a +

n∑

i=1

x2i

b =

n∑

i=1

xiyi.

• Two linear equations for two unknowns a and b.

• System can be solved with standard methods from linear algebra.

• Solution is unique unless all x-values are identical(vertical lines cannot be represented as y = a + bx).

• The resulting line is called a regression line.

Christian Borgelt Data Mining / Intelligent Data Analysis 209

Linear Regression: Examplex 1 2 3 4 5 6 7 8

y 1 3 2 3 4 3 5 6

Assumption:

Y = a + bX + ε

Normal equations:

8 a + 36 b = 27,

36 a + 204 b = 146.

Solution:

y =3

4+

7

12x.

x

y

0 1 2 3 4 5 6 7 80

1

2

3

4

5

6

x

y

0 1 2 3 4 5 6 7 80

1

2

3

4

5

6

Christian Borgelt Data Mining / Intelligent Data Analysis 210

Side Note: Least Squares and Maximum Likelihood

A regression line can be interpreted as a maximum likelihood estimator:

Assumption: The data generation process can be described well by the model

Y = a +Xx + ε,

where ε is normally distributed with mean 0 and (unknown) variance σ2 (ε ∼ N (0, σ2))(σ2 independent of X , that is, same dispersion of Y for all X — homoscedasticity).

As a consequence we have

fY |X(y | x) = 1√2πσ2

· exp(−(y − (a + bx))2

2σ2

).

With this expression we can set up the likelihood function

L((x1, y1), . . . (xn, yn); a, b, σ2)

=n∏

i=1

fX(xi)fY |X(yi | xi) =n∏

i=1

fX(xi) ·1√2πσ2

· exp−(yi − (a + bxi))

2

2σ2

.

Christian Borgelt Data Mining / Intelligent Data Analysis 211

Side Note: Least Squares and Maximum Likelihood

To simplify taking the derivatives, we compute the natural logarithm:

lnL((x1, y1), . . . (xn, yn); a, b, σ2)

= lnn∏

i=1

fX(xi) ·1√2πσ2

· exp−(yi − (a + bxi))

2

2σ2

=n∑

i=1

ln fX(xi) +n∑

i=1

ln1√2πσ2

− 1

2σ2

n∑

i=1

(yi − (a + bxi))2

From this expression it is clear that (provided fX(x) is independent of a, b, and σ2)maximizing the likelihood function is equivalent to minimizing

F (a, b) =n∑

i=1

(yi − (a + bxi))2.

Interpreting the method of least squares as a maximum likelihood estimator works alsofor the generalizations to polynomials and multivariate linear functions discussed next.

Christian Borgelt Data Mining / Intelligent Data Analysis 212

Page 54: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Polynomial Regression

Generalization to polynomials

y = p(x) = a0 + a1x + . . . + amxm

Approach: Minimize the sum of squared errors, that is,

F (a0, a1, . . . , am) =n∑

i=1

(p(xi)− yi)2 =n∑

i=1

(a0 + a1xi + . . . + amxmi − yi)2

Necessary conditions for a minimum: All partial derivatives vanish, that is,

∂F

∂a0= 0,

∂F

∂a1= 0, . . . ,

∂F

∂am= 0.

Christian Borgelt Data Mining / Intelligent Data Analysis 213

Polynomial Regression

System of normal equations for polynomials

na0 +

n∑

i=1

xi

a1 + . . . +

n∑

i=1

xmi

am =

n∑

i=1

yi

n∑

i=1

xi

a0 +

n∑

i=1

x2i

a1 + . . . +

n∑

i=1

xm+1i

am =

n∑

i=1

xiyi

... ...

n∑

i=1

xmi

a0 +

n∑

i=1

xm+1i

a1 + . . . +

n∑

i=1

x2mi

am =

n∑

i=1

xmi yi,

• m + 1 linear equations for m + 1 unknowns a0, . . . , am.

• System can be solved with standard methods from linear algebra.

• Solution is unique unless the coefficient matrix is singular.

Christian Borgelt Data Mining / Intelligent Data Analysis 214

Multivariate Linear Regression

Generalization to more than one argument

z = f (x, y) = a + bx + cy

Approach: Minimize the sum of squared errors, that is,

F (a, b, c) =n∑

i=1

(f (xi, yi)− zi)2 =n∑

i=1

(a + bxi + cyi − zi)2

Necessary conditions for a minimum: All partial derivatives vanish, that is,

∂F

∂a=

n∑

i=1

2(a + bxi + cyi − zi) = 0,

∂F

∂b=

n∑

i=1

2(a + bxi + cyi − zi)xi = 0,

∂F

∂c=

n∑

i=1

2(a + bxi + cyi − zi)yi = 0.

Christian Borgelt Data Mining / Intelligent Data Analysis 215

Multivariate Linear Regression

System of normal equations for several arguments

na +

n∑

i=1

xi

b +

n∑

i=1

yi

c =

n∑

i=1

zi

n∑

i=1

xi

a +

n∑

i=1

x2i

b +

n∑

i=1

xiyi

c =

n∑

i=1

zixi

n∑

i=1

yi

a +

n∑

i=1

xiyi

b +

n∑

i=1

y2i

c =

n∑

i=1

ziyi

• 3 linear equations for 3 unknowns a, b, and c.

• System can be solved with standard methods from linear algebra.

• Solution is unique unless all data points lie on a straight line.

Christian Borgelt Data Mining / Intelligent Data Analysis 216

Page 55: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Multivariate Linear Regression

General multivariate linear case:

y = f (x1, . . . , xm) = a0 +m∑

k=1

akxk

Approach: Minimize the sum of squared errors, that is,

F (~a) = (X~a− ~y)⊤(X~a− ~y),where

X =

1 x11 . . . x1m... ... . . . ...1 xn1 . . . xnm

, ~y =

y1...yn

, and ~a =

a0a1...am

Necessary condition for a minimum:

~∇~a F (~a) = ~∇~a (X~a− ~y)⊤(X~a− ~y) = ~0

Christian Borgelt Data Mining / Intelligent Data Analysis 217

Multivariate Linear Regression

• ~∇~a F (~a) may easily be computed by remembering that the differential operator

~∇~a =(∂

∂a0, . . . ,

∂am

)

behaves formally like a vector that is “multiplied” to the sum of squared errors.

• Alternatively, one may write out the differentiation componentwise.

With the former method we obtain for the derivative:

~∇~aF (~a) = ~∇~a ((X~a− ~y)⊤(X~a− ~y))=

(~∇~a (X~a− ~y)

)⊤(X~a− ~y) +

((X~a− ~y)⊤

(~∇~a (X~a− ~y)

))⊤

=(~∇~a (X~a− ~y)

)⊤(X~a− ~y) +

(~∇~a (X~a− ~y)

)⊤(X~a− ~y)

= 2X⊤(X~a− ~y)

= 2X⊤X~a− 2X⊤~y != ~0

Christian Borgelt Data Mining / Intelligent Data Analysis 218

Multivariate Linear Regression

Necessary condition for a minimum therefore:

~∇~aF (~a) = ~∇~a (X~a− ~y)⊤(X~a− ~y)

= 2X⊤X~a− 2X⊤~y != ~0

As a consequence we obtain the system of normal equations:

X⊤X~a = X⊤~y

This system has a solution unless X⊤X is singular. If it is regular, we have

~a = (X⊤X)−1X⊤~y.

(X⊤X)−1X⊤ is called the (Moore-Penrose-)Pseudoinverse of the matrix X.

With the matrix-vector representation of the regression probleman extension to multipolynomial regression is straightforward:Simply add the desired products of powers (monomials) to the matrix X.

Christian Borgelt Data Mining / Intelligent Data Analysis 219

Mathematical Background: Logistic Function

x

y

0

12

1

0−4 −2 +2 +4

Logistic function:

y = f (x) =ymax

1 + e−a(x−x0)

Special case ymax= a = 1, x0 = 0:

y = f (x) =1

1 + e−x

Application areas of the logistic function:

• Can be used to describe saturation processes

(growth processes with finite capacity/finite resources ymax).

Derivation e.g. from a Bernoulli differential equation

f ′(x) = k · f (x) · (ymax − f (x)) (yields a = kymax)

• Can be used to describe a linear classifier(especially for two-class problems, considered later).

Christian Borgelt Data Mining / Intelligent Data Analysis 220

Page 56: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Mathematical Background: Logistic Function

Example: two-dimensional logistic function

y = f (~x) =1

1 + exp(−( x1 + x2 − 4))=

1

1 + exp(−((1, 1)(x1, x2)⊤ − 4)

)

01

23

4

01

23

4

0

1

x1

x2

y

x1

x2

0

1

2

3

4

0 1 2 3 4

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

The “contour lines” of the logistic function are parallel lines/hyperplanes.

Christian Borgelt Data Mining / Intelligent Data Analysis 221

Mathematical Background: Logistic Function

Example: two-dimensional logistic function

y = f (~x) =1

1 + exp(−(2x1 + x2 − 6))=

1

1 + exp(−((2, 1)(x1, x2)⊤ − 6)

)

01

23

4

01

23

4

0

1

x1

x2

y

x1

x2

0

1

2

3

4

0 1 2 3 4

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

The “contour lines” of the logistic function are parallel lines/hyperplanes.

Christian Borgelt Data Mining / Intelligent Data Analysis 222

Regression: Generalization, Logistic Regression

Generalization of regression to non-polynomial functions.

Simple example: y = axb

Idea: Find a transformation to the linear/polynomial case.

Transformation for the above example: ln y = ln a + b · ln x.⇒ Linear regression for the transformed data y′ = ln y and x′ = ln x.

Special case: Logistic Function (mit a0 = ~a⊤~x0)

y =ymax

1 + e−(~a⊤~x+a0)⇔ 1

y=

1 + e−(~a⊤~x+a0)

ymax⇔ ymax − y

y= e−(~a

⊤~x+a0).

Result: Apply so-called Logit Transform

z = ln

(y

ymax − y

)= ~a⊤~x + a0.

Christian Borgelt Data Mining / Intelligent Data Analysis 223

Logistic Regression: Example

Data points: x 1 2 3 4 5

y 0.4 1.0 3.0 5.0 5.6

Apply the logit transform

z = ln

(y

ymax − y

), ymax = 6.

Transformed data points: (for linear regression)

x 1 2 3 4 5

z −2.64 −1.61 0.00 1.61 2.64

The resulting regression line and therefore the desired function are

z ≈ 1.3775x− 4.133 and y ≈ 6

1 + e−(1.3775x−4.133)≈ 6

1 + e−1.3775(x−3).

Attention: Note that the error is minimized only in the transformed space!Therefore the function in the original space may not be optimal!

Christian Borgelt Data Mining / Intelligent Data Analysis 224

Page 57: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Logistic Regression: Example

x

z

1 2 3 4 5

−4

−3

−2

−1

0

1

2

3

4

x

yY = 6

0 1 2 3 4 50

1

2

3

4

5

6

The resulting regression line and therefore the desired function are

z ≈ 1.3775x− 4.133 and y ≈ 6

1 + e−(1.3775x−4.133)≈ 6

1 + e−1.3775(x−3).

Attention: Note that the error is minimized only in the transformed space!Therefore the function in the original space may not be optimal!

Christian Borgelt Data Mining / Intelligent Data Analysis 225

Multivariate Logistic Regression: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Example data were drawn from a logistic function and noise was added.(The gray “contour lines” show the ideal logistic function.)

• Reconstructing the logistic function can be reduced to a multivariate linear regres-sion by applying a logit transform to the y-values of the data points.

Christian Borgelt Data Mining / Intelligent Data Analysis 226

Multivariate Logistic Regression: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• The black “contour lines” show the resulting logistic function.Is the deviation from the ideal logistic function (gray) caused by the added noise?

• Attention: Note that the error is minimized only in the transformed space!Therefore the function in the original space may not be optimal!

Christian Borgelt Data Mining / Intelligent Data Analysis 227

Logistic Regression: Optimization in Original SpaceApproach analogous to linear/polynomial regression

Given: data set D = {(~x1, y1), . . . , (~xn, yn)} with n data points, yi ∈ (0, 1).

Simplification: Use ~x∗i = (1, xi1, . . . , xim)⊤ und ~a = (a0, a1, . . . , am)

⊤.(By the leading 1 in ~x∗i the constant a0 is captured.)

Minimize sum of squared errors / deviations:

F (~a) =n∑

i=1

(yi −

1

1 + e−~a⊤~x∗i

)2!= min .

Necessary condition for a minimum:

Gradient of the objective function F (~a) w.r.t. ~a vanishes: ~∇~a F (~a) != ~0

Problem: The resulting equation system is not linear.

Solution possibilities:

• Gradient descent on objective function F (~a).

• Root search on gradient ~∇~a F (~a). (e.g. Newton–Raphson method)

Christian Borgelt Data Mining / Intelligent Data Analysis 228

Page 58: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Reminder: Gradient Methods for Optimization

The gradient is a differential operator,that turns a scalar function into a vector field.

x

y

z

x0

y0∂z∂x

|~p∂z∂y

|~p

~∇z|~p=(x0,y0)

Illustration of the gradient ofa real-valued function z = f (x, y)at a point ~p = (x0, y0).

It is ~∇z|(x0,y0) =(∂z∂x

∣∣∣x0, ∂z∂y

∣∣∣y0

).

The gradient at a point shows the direction of the steepest ascent of the functionat this point; its length describes the steepness of the ascent.

Principle of gradient methods:Starting at a (possibly randomly chosen) initial point, make (small) stepsin (or against) the direction of the gradient of the objective functionat the current point, until a maximum (or a minimum) has been reached.

Christian Borgelt Data Mining / Intelligent Data Analysis 229

Gradient Methods: Cookbook Recipe

Idea: Starting from a randomly chosen point in the search space, make small stepsin the search space, always in the direction of the steepest ascent (or descent) of thefunction to optimize, until a (local) maximum (or minimum) is reached.

1. Choose a (random) starting point ~x(0) =(x(0)1 , . . . , x

(0)n

)⊤

2. Compute the gradient of the objective function f at the current point ~x (i):

∇~x f (~x)∣∣∣~x (i) =

(∂∂x1

f (~x)∣∣∣x(i)1

, . . . , ∂∂xn

f (~x)∣∣∣x(i)n

)⊤

3. Make a small step in the direction (or against the direction) of the gradient:

~x(i+1) = ~x (i) ± η ∇~x f(~x (i)

).

+ : gradient ascent− : gradient descent

η is a step width parameter (“learning rate” in artificial neuronal networks)

4. Repeat steps 2 and 3, until some termination criterion is satisfied.(e.g., a certain number of steps has been executed, current gradient is small)

Christian Borgelt Data Mining / Intelligent Data Analysis 230

Gradient Descent: Simple Example

Example function: f (x) =5

6x4 − 7x3 +

115

6x2 − 18x + 6,

i xi f (xi) f ′(xi) ∆xi

0 0.200 3.112 −11.147 0.1111 0.311 2.050 −7.999 0.0802 0.391 1.491 −6.015 0.0603 0.451 1.171 −4.667 0.0474 0.498 0.976 −3.704 0.0375 0.535 0.852 −2.990 0.0306 0.565 0.771 −2.444 0.0247 0.589 0.716 −2.019 0.0208 0.610 0.679 −1.681 0.0179 0.626 0.653 −1.409 0.01410 0.640 0.635

x0

1

2

3

4

5

6

0 1 2 3 4

starting point

global optimum

Gradient descent with initial value 0.2 and step width/learning rate 0.01.

Due to a proper step width/learning rate, the minimum is approached fairly quickly.

Christian Borgelt Data Mining / Intelligent Data Analysis 231

Logistic Regression: Gradient DescentWith the abbreviation f (z) = 11+e−z for the logistic function it is

~∇~a F (~a) = ~∇~an∑

i=1

(yi − f (~a⊤~x∗i ))2 = − 2n∑

i=1

(yi − f (~a⊤~x∗i )) · f ′(~a⊤~x∗i ) · ~x∗i .

Derivative of the logistic function: (cf. Bernoulli differential equation)

f ′(z) =d

dz

(1 + e−z

)−1= −

(1 + e−z

)−2 (−e−z)

=1 + e−z − 1

(1 + e−z)2=

1

1 + e−z(1− 1

1 + e−z)

= f (z) · (1− f (z)),

x

y

0

12

1

0−4 −2 +2 +4

x

y

0

12

1

0

14

−4 −2 +2 +4

Christian Borgelt Data Mining / Intelligent Data Analysis 232

Page 59: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Logistic Regression: Gradient Descent

Given: data set D = {(~x1, y1), . . . , (~xn, yn)} with n data points, yi ∈ (0, 1).

Simplification: Use ~x∗i = (1, xi1, . . . , xim)⊤ and ~a = (a0, a1, . . . , am)

⊤.

Gradient descent on the objective function F (~a):

• Choose as the initial point ~a0 the result of a logit transformand a linear regression (or merely a linear regression).

• Update of the parameters ~a:

~at+1 = ~at −η

2· ~∇~a F (~a)|~at

= ~at + η ·n∑

i=1

(yi − f (~a⊤t ~x∗i )) · f (~a⊤t ~x∗i ) · (1− f (~a⊤t ~x∗i )) · ~x∗i ,

where η is a step width parameter to be chosen by a user (e.g. η = 0.05)(in the area of artificial neural networks also called “learning rate”).

• Repeat the update step until convergence, e.g. until||~at+1 − ~at|| < τ with a chosen threshold τ (z.B. τ = 10−6).

Christian Borgelt Data Mining / Intelligent Data Analysis 233

Multivariate Logistic Regression: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Black “contour line”: logit transform and linear regression.

• Green “contour line”: gradient descent on error function in original space.

(For simplicity and clarity only the “contour lines” for y = 0.5 (inflection lines) are shown.)

Christian Borgelt Data Mining / Intelligent Data Analysis 234

Reminder: Newton–Raphson Method

• The Newton–Raphson methodis an iterative numeric algorithmto approximate a root of a function.

• Idea: use slope/direction of a tangentto the function at a current pointto find the next approximation.

• Formally:

~xt+1 = ~xt+∆~xt; ∆~xt = −f (~xt)

~∇~x f (~x)∣∣∣~xt

starting point

root

x∆x

f(x)

• The gradient describes the direction of steepest ascent of tangent (hyper-)planesto the function (in one dimension: the slope of tangents to the function).

• In one dimension (see diagram):

Solve (xt+1, 0) = (xt, f (xt))⊤ + k · (1, d

dxf (x)|xt)⊤, k ∈ IR, for xt+1.

Since 0 = f (xt) + k · ddxf (x)|xt, it is k = −f (xt)/ d

dxf (x)|xt.

Christian Borgelt Data Mining / Intelligent Data Analysis 235

Newton–Raphson Method for Finding Optima

• The standard Newton-Raphson method finds roots of functions.

• By applying it to the gradient of a function,it may be used to find optima (minima, maxima, or saddle points),because a vanishing gradient is a necessary condition for an optimum.

• In this case the update formula is

~xt+1 = ~xt +∆~xt, ∆~xt = −(~∇2~x f (~x)

∣∣∣~xt

)−1· ~∇~x f (~x)

∣∣∣~xt,

where ~∇2~x f (~x) is the so-called Hessian matrix, that is,

the matrix of second-order partial derivatives of the scalar-valued function f .

• In one dimension:

xt+1 = xt +∆xt, ∆xt = −∂f (x)∂x

∣∣∣xt

∂2f (x)∂x2

∣∣∣xt

.

• The Newton–Raphson method usually converges much faster than gradient descent(... and needs no step width parameter!).

Christian Borgelt Data Mining / Intelligent Data Analysis 236

Page 60: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Logistic Regression: Newton–Raphson

With the abbreviation f (z) = 11+e−z for the logistic function it is

~∇2~a F (~a) = ~∇~a

−2

n∑

i=1

(yi − f (~a⊤~x∗i )) · f (~a⊤~x∗i ) · (1− f (~a⊤~x∗i )) · ~x∗i

= −2 ~∇~an∑

i=1

(yif (~a

⊤~x∗i )− (yi + 1)f2(~a⊤~x∗i ) + f3(~a⊤~x∗i ))· ~x∗i

= −2n∑

i=1

(yi − 2(yi + 1)f (~a⊤~x∗i ) + 3f2(~a⊤~x∗i )

)· f ′(~a⊤~x∗i ) · ~x∗i ~x∗⊤i

where again f ′(z) = f (z) · (1− f (z)) (as derived above).

Thus we get for the update of the parameters ~a: (note: no step width η)

~at+1 = ~at −(~∇2~a F (~a)

∣∣∣~at

)−1· ~∇~a F (~a)

∣∣∣~at

with ~∇2~a F (~a)

∣∣∣~at

as shown above and ~∇~a F (~a)∣∣∣~at

as the expression in large parentheses.

Christian Borgelt Data Mining / Intelligent Data Analysis 237

Logistic Classification: Two Classes

x0

12

1

x0− 4a

x0− 2a

x0 x0+2a

x0+4a

probability

class 1

probability

class 0

Logistic function with Y = 1:

y = f (x) =1

1 + e−a(x−x0)

Interpret the logistic functionas the probability of one class.

• Conditional class probability is logistic function:~a = (a0, x1, . . . , xm)

~x∗ = (1, x1, . . . , xm)⊤

P (C = c1 | ~X = ~x) = p1(~x) = p(~x;~a) =1

1 + e−~a⊤~x∗.

• With only two classes the conditional probability of the other class is:

P (C = c0 | ~X = ~x) = p1(~x) = 1− p(~x;~a).

• Classification rule:C =

{c1, if p(~x;~a) ≥ θ,

c0, if p(~x;~a) < θ,θ = 0.5.

Christian Borgelt Data Mining / Intelligent Data Analysis 238

Logistic Classification

01

23

4

01

23

4

0

1

x1

x2

y

x1

x2

0

1

2

3

4

0 1 2 3 4

class 1

class 0

• The classes are separated at the “contour line” p(~x;~a) = θ = 0.5 (inflection line).(The classification boundary is linear, therefore linear classification.)

• Via the classification threshold θ, which need not be θ = 0.5,misclassification costs may be incorporated.

Christian Borgelt Data Mining / Intelligent Data Analysis 239

Logistic Classification: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• In finance (e.g. when assessing the credit worthiness of businesses)logistic classification is often applied in discrete spaces,that are spanned e.g. by binary attributes and expert assessments.

(e.g. assessments of the range of products, market share, growth etc.)

Christian Borgelt Data Mining / Intelligent Data Analysis 240

Page 61: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Logistic Classification: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• In such a case multiple businesses may fall onto the same grid point.

• Then probabilities may be estimated from observed credit defaults:

pdefault(~x) =#defaults(~x) + γ

#loans(~x) + 2γ(γ: Laplace correction, e.g. γ ∈ {12, 1})

Christian Borgelt Data Mining / Intelligent Data Analysis 241

Logistic Classification: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Black “contour line”: logit transform and linear regression.

• Green “contour line”: gradient descent on error function in original space.

(For simplicity and clarity only the “contour lines” for y = 0.5 (inflection lines) are shown.)

Christian Borgelt Data Mining / Intelligent Data Analysis 242

Logistic Classification: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• More frequent is the case in which at least some attributes are metricand for each point a class, but no class probability is available.

• If we assign class 0: c0 = y = 0 and class 1: c1 = y = 1,the logit transform is not applicable.

Christian Borgelt Data Mining / Intelligent Data Analysis 243

Logistic Classification: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• The logit transform becomes applicable by mapping the classes to

c1 = y = ln(

ǫ1−ǫ

)and c0 = y = ln

(1−ǫǫ

)= − ln

1−ǫ).

• The value of ǫ ∈ (0, 12) is irrelevant (i.e., the result is independent of ǫand equivalent to a linear regression with c0 = y = 0 and c1 = y = 1).

Christian Borgelt Data Mining / Intelligent Data Analysis 244

Page 62: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Logistic Classification: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Logit transform and linear regression often yield suboptimal results:Depending on the distribution of the data points relativ to a(n optimal) separatinghyperplane the computed separating hyperplane can be shifted and/or rotated.

• This can lead to (unnecessary) misclassifications!

Christian Borgelt Data Mining / Intelligent Data Analysis 245

Logistic Classification: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Black “contour line”: logit transform and linear regression.

• Green “contour line”: gradient descent on error function in original space.

(For simplicity and clarity only the “contour lines” for y = 0.5 (inflection lines) are shown.)

Christian Borgelt Data Mining / Intelligent Data Analysis 246

Logistic Classification: Maximum Likelihood Approach

A likelihood function describes the probability of observed datadepending on the parameters ~a of the (conjectured) data generating process.

Here: logistic function to describe the class probabilities.

class y = 1 occurs with probability p1(~x) = f (~a⊤~x∗),

class y = 0 occurs with probability p0(~x) = 1− f (~a⊤~x∗),with f (z) = 1

1+e−z and ~x∗ = (1, x1, . . . , xm)

⊤ and ~a = (a0, a1, . . . , am)⊤.

Likelihood function for the data set D = {(~x1, y1), . . . , ~xn, yn)} with yi ∈ {0, 1}:

L(~a) =n∏

i=1

p1(~xi)yi · p0(~xi)1−yi

=n∏

i=1

f (~a⊤~x∗i )yi · (1− f (~a⊤~x∗i ))1−yi

Maximum Likelihood Approach: Find the set of parameters ~a,which renders the occurrence of the (observed) data most likely.

Christian Borgelt Data Mining / Intelligent Data Analysis 247

Logistic Classification: Maximum Likelihood Approach

Simplification by taking the logarithm: log likelihood function

lnL(~a) =n∑

i=1

(yi · ln f (~a⊤~x∗i ) + (1− yi) · ln(1− f (~a⊤~x∗i ))

)

=n∑

i=1

yi · ln

1

1 + e−(~a⊤~x∗i )

+ (1− yi) · lne−(~a

⊤~x∗i )

1 + e−(~a⊤~x∗i )

=n∑

i=1

((yi − 1) · ~a⊤~x∗i − ln

(1 + e−(~a

⊤~x∗i )))

Necessary condition for a maximum:

Gradient of the objective function lnL(~a) w.r.t. ~a vanishes: ~∇~a lnL(~a)!= ~0

Problem: The resulting equation system is not linear.

Solution possibilities:

• Gradient descent on objective function lnL(~a).

• Root search on gradient ~∇~a lnL(~a). (e.g. Newton–Raphson method)

Christian Borgelt Data Mining / Intelligent Data Analysis 248

Page 63: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Logistic Classification: Gradient Ascent

Gradient of the log likelihood function: (mit f (z) = 11+e−z )

~∇~a lnL(~a) = ~∇~an∑

i=1

((yi − 1) · ~a⊤~x∗i − ln

(1 + e−(~a

⊤~x∗i )))

=n∑

i=1

(yi − 1) · ~x∗i +

e−(~a⊤~x∗i )

1 + e−(~a⊤~x∗i )· ~x∗i

=n∑

i=1

((yi − 1) · ~x∗i + (1− f (~a⊤~x∗i )) · ~x∗i

)

=n∑

i=1

((yi − f (~a⊤~x∗i )) · ~x∗i

)

As a comparison:

Gradient of the sum of squared errors / deviations:

~∇~a F (~a) = −2n∑

i=1

(yi − f (~a⊤~x∗i )) · f (~a⊤~x∗i ) · (1− f (~a⊤~x∗i ))︸ ︷︷ ︸additional factor: derivative of the logistic function

· ~x∗i

Christian Borgelt Data Mining / Intelligent Data Analysis 249

Logistic Classification: Gradient Ascent

Given: data set D = {(~x1, y1), . . . , (~xn, yn)} with n data points, y ∈ {0, 1}.Simplification: Use ~x∗i = (1, xi1, . . . , xim)

⊤ and ~a = (a0, a1, . . . , am)⊤.

Gradient ascent on the objective function lnL(~a):

• Choose as the initial point ~a0 the result of a logit transformand a linear regression (or merely a linear regression).

• Update of the parameters ~a:

~at+1 = ~at + η · ~∇~a lnL(~a)|~at= ~at + η ·

n∑

i=1

(yi − f (~a⊤t ~x∗i )) · ~x∗i ,

where η is a step width parameter to be chosen by a user (e.g. η = 0.01).(Comparison with gradient descent: missing factor f (~a⊤t ~x

∗i ) · (1− f (~a⊤t ~x∗i )).)

• Repeat the update step until convergence, e.g. until||~at+1 − ~at|| < τ with a chosen threshold τ (z.B. τ = 10−6).

Christian Borgelt Data Mining / Intelligent Data Analysis 250

Logistic Classification: Example

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Black “contour line”: logit transform and linear regression.

• Green “contour line”: gradient descent on error function in the original space.

• Magenta “contour line”: gradient ascent on log likelihood function.

(For simplicity and clarity only the “contour lines” for y = 0.5 (inflection lines) are shown.)

Christian Borgelt Data Mining / Intelligent Data Analysis 251

Logistic Classification: No Gap Between Classes

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• If there is no (clear) gap between the classesa logit transform and subsequent linear regressionyields (unnecessary) misclassifications even more often.

• In such a case the alternative methods are clearly preferable!

Christian Borgelt Data Mining / Intelligent Data Analysis 252

Page 64: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Logistic Classification: No Gap Between Classes

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Black “contour line”: logit transform and linear regression.

• Green “contour line”: gradient descent on error function in the original space.

• Magenta “contour line”: gradient ascent on log likelihood function.

(For simplicity and clarity only the “contour lines” for y = 0.5 (inflection lines) are shown.)

Christian Borgelt Data Mining / Intelligent Data Analysis 253

Logistic Classification: Overlapping Classes

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Even more problematic is the situation if the classes overlap(i.e., there is no perfect separating line/hyperplane).

• In such a case even the other methods cannot avoid misclassifications.

(There is no way to be better than the pure or Bayes error.)

Christian Borgelt Data Mining / Intelligent Data Analysis 254

Logistic Classification: Overlapping Classes

0

1

2

3

4

0 1 2 3 4

01

23

4 01

23

40

0.2

0.4

0.6

0.8

1

x1x 2

y

• Black “contour line”: logit transform and linear regression.

• Green “contour line”: gradient descent on error function in the original space.

• Magenta “contour line”: gradient ascent on log likelihood function.

(For simplicity and clarity only the “contour lines” for y = 0.5 (inflection lines) are shown.)

Christian Borgelt Data Mining / Intelligent Data Analysis 255

Logistic Classification: Newton–Raphson

With the abbreviation f (z) = 11+e−z for the logistic function it is

~∇2~a lnL(~a) = ~∇~a

n∑

i=1

((yi − f (~a⊤~x∗i )) · ~x∗i

)

= ~∇~an∑

i=1

((yi~x

∗i − f (~a⊤~x∗i ) · ~x∗i )

)

= −n∑

i=1

f ′(~a⊤~x∗i ) · ~x∗i ~x∗⊤i = −n∑

i=1

f (~a⊤~x∗i ) · (1− f (~a⊤~x∗i )) · ~x∗i ~x∗⊤i

where again f ′(z) = f (z) · (1− f (z)) (as derived above).

Thus we get for the update of the parameters ~a: (note: no step width η)

~at+1 = ~at −(~∇2~a lnL(~a)

∣∣∣~at

)−1· ~∇~a lnL(~a)

∣∣∣~at

= ~at +

n∑

i=1

f (~a⊤t ~x∗i ) · (1− f (~a⊤t ~x∗i )) · ~x∗i ~x∗⊤i

−1·

n∑

i=1

(yi − f (~a⊤t ~x∗i )) · ~x∗i

.

Christian Borgelt Data Mining / Intelligent Data Analysis 256

Page 65: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Robust Regression

• Solutions of (ordinary) least squares regression can be strongly affected by outliers.

The reason for this is obviously the squared error function,which weights outliers fairly heavily (quadratically).

• More robust results can usually be obtained by minimizing thesum of absolute deviations (least absolute deviations, LAD).

• However, this approach has the disadvantageof not being analytically solvable (like least squares)and thus has to be addressed with iterative methods right from the start.

• In addition, least absolute deviation solutions can be unstable in the sensethat small changes in the data can lead to “jumps” (discontinuous changes)of the solution parameters.

Instead, least squares solutions always changes “smoothly” (continuously).

• Finally, severe outliers can still have a distorting effect on the solution.

Christian Borgelt Data Mining / Intelligent Data Analysis 257

Robust Regression

• In order to improve the robustness of the procedure,more sophisticated regression methods have been developed:robust regression, which include:

◦ M-estimation and S-estimation for regression and

◦ least trimmed squares (LTS), which simply uses a subset of at least halfthe size of the data set that yields the smallest sum of squared errors.

Here, we take a closer look at M-estimators.

• We rewrite the error functional (that is, the sum of squared errors)to be minimized in the form

Fρ(a, b) =n∑

i=1

ρ(ei) =n∑

i=1

ρ(~x⊤i ~a− yi)

where ρ(ei) = e2i and ei is the (signed) error of the regression functionat the ith point, that is ei = e(xi, yi,~a) = f~a(xi)− yi,where f is the conjectured regression function family with parameters ~a.

Christian Borgelt Data Mining / Intelligent Data Analysis 258

Robust Regression: M-Estimators

• Is ρ(ei) = e2i the only reasonable choice for the function ρ? Certainly not.

• However, ρ should satisfy at least some reasonable restrictions.

◦ The function ρ should alway be positive, except for the case ei = 0.

◦ The sign of the error ei should not matter for ρ.

◦ ρ should be increasing when the absolute value of the error increases.

• These requirements can formalized in the following way:

ρ(e) ≥ 0, ρ(0) = 0,ρ(e) = ρ(−e), ρ(ei) ≥ ρ(ej) if |ei| ≥ |ej|.

• Parameter estimation (here the estimation of the parameter vector ~a)is based on an objective function of the form

Fρ(a, b) =n∑

i=1

ρ(ei) =n∑

i=1

ρ(~x⊤i ~a− yi)

and an error measure satisfying the above conditions is called an M-estimator.

Christian Borgelt Data Mining / Intelligent Data Analysis 259

Robust Regression: M-Estimators

• Parameter estimation (here the estimation of the parameter vector ~a)based on an objective function of the form

Fρ(a, b) =n∑

i=1

ρ(ei) =n∑

i=1

ρ(~x⊤i ~a− yi)

and an error measure satisfying the above conditions is called an M-estimator.

• Examples of such estimators are:

Method ρ(e)

Least squares e2

Huber

{12e

2 if |e| ≤ k,

k|e| − 12k

2 if |e| > k.

Tukey’s bisquare

k26

(1−

(1−

(ek

)2)3), if |e| ≤ k,

k26 , if |e| > k.

Christian Borgelt Data Mining / Intelligent Data Analysis 260

Page 66: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Robust Regression

• In order to understand the more general setting of an error measure ρ,it is useful to consider the derivative ψ = ρ′.

• Taking the derivatives of the objective function

Fρ(a, b) =n∑

i=1

ρ(ei) =n∑

i=1

ρ(~x⊤i ~a− yi)

with respect to the parameters ai, we obtain a system of (m + 1) equations

n∑

i=1

ψi(~x⊤i ~a− yi)~x⊤i = 0.

• Defining w(e) = ψ(e)/e and wi = w(ei), the system of linear equationscan be rewritten in the form

n∑

i=1

ψi(~x⊤i ~a− yi)ei

· ei · ~x⊤i =n∑

i=1

wi · (yi − x⊤i b) · x⊤i = 0.

Christian Borgelt Data Mining / Intelligent Data Analysis 261

Robust Regression

• Solving this system of linear equations corresponds to solvinga standard least squares problem with (non-fixed) weights in the form

∑ni=1wie

2i .

• However, the weights wi depend on the residuals ei, the residuals depend on thecoefficients ai, and the coefficients depend on the weights.

• Therefore, it is in general not possible to provide an explicit solution.

• Instead of an analytical solution, the following iteration scheme is applied:

1. Choose an initial solution ~a(0),for instance the standard least squares solution setting all weights to wi = 1.

2. In each iteration step t, calculate the residuals e(t−1) and the correspondingweights w(t−1) = w

(e(t−1)

)determined by the previous step.

3. Solve the weighted least squares problem∑ni=1wie

2i which leads to

~a(t) =(X⊤W(t−1)X

)−1X⊤W(t−1)~y,

where W stands for a diagonal matrix with weights wi on the diagonal.

Christian Borgelt Data Mining / Intelligent Data Analysis 262

Robust Regression

• The error measures and the weights are related as follows:

Method w(e)

Least squares 1

Huber

{1, if |e| ≤ k,k/|e|, if |e| > k.

Tukey’s bisquare

(1−

(ek

)2)2, if |e| ≤ k,

0, if |e| > k.

• Note that the weights are an additional result of the procedure(beyond the actually desired regression function).

• They provide information which data points may be considered as outliers(those with low weights, as this indicates that they have not been fitted well).

• Note also that the weights may be plotted even for high-dimensional data sets(using some suitable arrangement of the data points, e.g., sorted by weight).

Christian Borgelt Data Mining / Intelligent Data Analysis 263

Robust Regression

(ordinary) least squares

–6 –4 –2 0 2 4 60

10

20

30

40

e

ρ(e)

error

–6 –4 –2 0 2 4 60

0.2

0.4

0.6

0.8

1

e

w

weight

Huber

–6 –4 –2 0 2 4 60

2

4

6

8

e

ρ1.5(e)

error

–6 –4 –2 0 2 4 60

0.2

0.4

0.6

0.8

1

ew

1.5(e)

weight

Tukey’s bisquare

–6 –4 –2 0 2 4 60

1

2

3

e

ρ4.5(e)

error

–6 –4 –2 0 2 4 60

0.2

0.4

0.6

0.8

1

e

w4.5(e)

weight

Christian Borgelt Data Mining / Intelligent Data Analysis 264

Page 67: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Robust Regression

• The (ordinary) least squares error increases in a quadratic mannerwith increasing distance. The weights are always constant.

This means that extreme outliers will have full influenceon the regression coefficients and can corrupt the result completely.

• In the more robust approach byHuber the change of the error measure ρ switchesfrom a quadratic increase for small errorsto a linear increase for larger errors.

As a result, only data points with small errors will have full influenceon the regression coefficients. For extreme outliers the weights tend to zero.

• Tukey’s bisquare approach is even more drastic than Huber’s.For larger errors the error measure ρ does not increase at all, but remains constant.As a consequence, the weights for outliers drop to zeroif they are too far away from the regression curve.

This means that extreme outliers have no influence on the regression curve at all.

Christian Borgelt Data Mining / Intelligent Data Analysis 265

Robust Regression: Example

0 1 2 3 4 5

–6

–4

–2

0

2

4

x

y

1 2 3 4 5 6 7 8 9 10 110

0.2

0.4

0.6

0.8

1

data point index

regressionweight

• There is one outlier that leads to the red regression linethat neither fits the outlier nor the other points.

• With robust regression, for instance based on Huber’s ρ-function,we obtain the blue regression line that simply ignores the outlier.

• An additional result are the computed weights for the data points.In this way, outliers can be identified by robust regression.

Christian Borgelt Data Mining / Intelligent Data Analysis 266

Summary Regression

• Minimize the Sum of Squared Errors

◦ Write the sum of squared errorsas a function of the parameters to be determined.

• Exploit Necessary Conditions for a Minimum

◦ Partial derivatives w.r.t. the parameters to determine must vanish.

• Solve the System of Normal Equations

◦ The best fit parameters are the solution of the system of normal equations.

• Non-polynomial Regression Functions

◦ Find a transformation to the multipolynomial case.

◦ Logistic regression can be used to solve two class classification problems.

• Robust Regression

◦ Reduce the influence of outliers by using different error measures.

Christian Borgelt Data Mining / Intelligent Data Analysis 267

Bayes Classifiers

Christian Borgelt Data Mining / Intelligent Data Analysis 268

Page 68: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Bayes Classifiers

• Probabilistic Classification and Bayes’ Rule

• Naive Bayes Classifiers

◦ Derivation of the classification formula

◦ Probability estimation and Laplace correction

◦ Simple examples of naive Bayes classifiers

◦ A naive Bayes classifier for the Iris data

• Full Bayes Classifiers

◦ Derivation of the classification formula

◦ Comparison to naive Bayes classifiers

◦ A simple example of a full Bayes classifier

◦ A full Bayes classifier for the Iris data

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 269

Probabilistic Classification

• A classifier is an algorithm that assigns a class from a predefined set to a case orobject, based on the values of descriptive attributes.

• An optimal classifier maximizes the probability of a correct class assignment.

◦ Let C be a class attribute with dom(C) = {c1, . . . , cnC},which occur with probabilities pi, 1 ≤ i ≤ nC .

◦ Let qi be the probability with which a classifier assigns class ci.(qi ∈ {0, 1} for a deterministic classifier)

◦ The probability of a correct assignment is

P (correct assignment) =nC∑

i=1

piqi.

◦ Therefore the best choice for the qi is

qi =

{1, if pi = max

nCk=1 pk,

0, otherwise.

Christian Borgelt Data Mining / Intelligent Data Analysis 270

Probabilistic Classification

• Consequence: An optimal classifier should assign the most probable class.

• This argument does not change if we take descriptive attributes into account.

◦ Let U = {A1, . . . , Am} be a set of descriptive attributeswith domains dom(Ak), 1 ≤ k ≤ m.

◦ Let A1 = a1, . . . , Am = am be an instantiation of the attributes.

◦ An optimal classifier should assign the class ci for which

P (C = ci | A1 = a1, . . . , Am = am) =

maxnCj=1 P (C = cj | A1 = a1, . . . , Am = am)

• Problem: We cannot store a class (or the class probabilities) for everypossible instantiation A1 = a1, . . . , Am = am of the descriptive attributes.(The table size grows exponentially with the number of attributes.)

• Therefore: Simplifying assumptions are necessary.

Christian Borgelt Data Mining / Intelligent Data Analysis 271

Bayes’ Rule and Bayes’ Classifiers

• Bayes’ rule is a formula that can be used to “invert” conditional probabilities:Let X and Y be events, P (X) > 0. Then

P (Y | X) =P (X | Y ) · P (Y )

P (X).

• Bayes’ rule follows directly from the definition of conditional probability:

P (Y | X) =P (X ∩ Y )

P (X)and P (X | Y ) =

P (X ∩ Y )

P (Y ).

• Bayes’ classifiers: Compute the class probabilities as

P (C = ci | A1 = a1, . . . , Am = am) =

P (A1 = a1, . . . , Am = am | C = ci) · P (C = ci)

P (A1 = a1, . . . , Am = am).

• Looks unreasonable at first sight: Even more probabilities to store.

Christian Borgelt Data Mining / Intelligent Data Analysis 272

Page 69: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Naive Bayes Classifiers

Naive Assumption:The descriptive attributes are conditionally independent given the class.

Bayes’ Rule:

P (C = ci | ω) =P (A1 = a1, . . . , Am = am | C = ci) · P (C = ci)

P (A1 = a1, . . . , Am = am) ← p0

Chain Rule of Probability:

P (C = ci | ω) =P (C = ci)

p0·m∏

k=1

P (Ak = ak |A1 = a1, . . . , Ak−1 = ak−1, C = ci)

Conditional Independence Assumption:

P (C = ci | ω) =P (C = ci)

p0·m∏

k=1

P (Ak = ak | C = ci)

Christian Borgelt Data Mining / Intelligent Data Analysis 273

Reminder: Chain Rule of Probability

• Based on the product rule of probability:

P (A ∧B) = P (A | B) · P (B)

(Multiply definition of conditional probability with P (B).)

• Multiple application of the product rule yields:

P (A1, . . . , Am) = P (Am | A1, . . . , Am−1) · P (A1, . . . , Am−1)= P (Am | A1, . . . , Am−1)· P (Am−1 | A1, . . . , Am−2) · P (A1, . . . , Am−2)= ...

=m∏

k=1

P (Ak | A1, . . . , Ak−1)

• The scheme works also if there is already a condition in the original expression:

P (A1, . . . , Am | C) =m∏

i=1

P (Ak | A1, . . . , Ak−1, C)

Christian Borgelt Data Mining / Intelligent Data Analysis 274

Conditional Independence

• Reminder: stochastic independence (unconditional)

P (A ∧ B) = P (A) · P (B)

(Joint probability is the product of the individual probabilities.)

• Comparison to the product rule

P (A ∧B) = P (A | B) · P (B)

shows that this is equivalent to

P (A | B) = P (A)

• The same formulae hold conditionally, i.e.

P (A ∧B | C) = P (A | C) · P (B | C) and

P (A | B,C) = P (A | C).

• Conditional independence allows us to cancel some conditions.

Christian Borgelt Data Mining / Intelligent Data Analysis 275

Conditional Independence: An Example

t t

t

t

t

t

t

ttt t

tt

t

ttt

t

ttt

tt

t

t tt

t

t

t

t

t

ttt

tt

ttt t

t

t

t

tt t

ttt

t

tt t

t

tt

tt

tt

t

t

t

t ttt

t

tt

t tt

tt

t

t

ttt

t t

tt

t

t

t

tt

t t t

t

t ttt

t

t

tt t

t

t tt

ttt

tt

tt

t tt

t

t

tt t

t

ttt

t

tt

tt

t t

t

tt

t ttt t t

t t

t

tt t

tt tt

t

t

t

tt

t

t

tt

tt

t

ttt

tt

t

tt

tt

tt

t

t

tt

t

tt

ttt

tt

tt

t

t ttt

tt

t

ttGroup 1

t

t

t

t

tt

tt

tt

t

tt

t

t

tt

t

t

ttt

tt

t t ttt

t

t t

t

tt

tt

t

t

tt

tt

t

t

t

t

tt

tt

t

t

tt

t

tt

t

t t

t t

ttt t

tt t t

tt t

tt

t

t

tt

tttt

tt t

t

tt

ttt

t

ttt

t

t t

tt

tt

t tt

t

tt

t

t t t

ttt

tttt

tt

tt

t

t t

t

tt

ttt

t t tt

t

tt t

tt

t

ttt

ttt

t

t

t

t

tt

t

tt

t t

t

ttt

t

t

t

tt

t tt

t

tt

tt

t

tt

tttt

tt

t

t

t

t

tt

tt

t

t

tt

Group 2

Christian Borgelt Data Mining / Intelligent Data Analysis 276

Page 70: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Conditional Independence: An Example

t t

t

t

t

t

t

ttt t

tt

t

ttt

t

ttt

tt

t

t tt

t

t

t

t

t

ttt

tt

ttt t

t

t

t

tt t

ttt

t

tt t

t

tt

tt

tt

t

t

t

t ttt

t

tt

t tt

tt

t

t

ttt

t t

tt

t

t

t

tt

t t t

t

t ttt

t

t

tt t

t

t tt

ttt

tt

tt

t tt

t

t

tt t

t

ttt

t

tt

tt

t t

t

tt

t ttt t t

t t

t

tt t

tt tt

t

t

t

tt

t

t

tt

tt

t

ttt

tt

t

tt

tt

tt

t

t

tt

t

tt

ttt

tt

tt

t

t ttt

tt

t

ttGroup 1

Christian Borgelt Data Mining / Intelligent Data Analysis 277

Conditional Independence: An Example

t

t

t

t

tt

tt

tt

t

tt

t

t

tt

t

t

ttt

tt

t t ttt

t

t t

t

tt

tt

t

t

tt

tt

t

t

t

t

tt

tt

t

t

tt

t

tt

t

t t

t t

ttt t

tt t t

tt t

tt

t

t

tt

tttt

tt t

t

tt

ttt

t

ttt

t

t t

tt

tt

t tt

t

tt

t

t t t

ttt

tttt

tt

tt

t

t t

t

tt

ttt

t t tt

t

tt t

tt

t

ttt

ttt

t

t

t

t

tt

t

tt

t t

t

ttt

t

t

t

tt

t tt

t

tt

tt

t

tt

tttt

tt

t

t

t

t

tt

tt

t

t

tt

Group 2

Christian Borgelt Data Mining / Intelligent Data Analysis 278

Naive Bayes Classifiers

• Consequence: Manageable amount of data to store.Store distributions P (C = ci) and ∀1 ≤ k ≤ m : P (Ak = ak | C = ci).

• It is not necessary to compute p0 explicitely, because it can be computed implicitlyby normalizing the computed values to sum 1.

Estimation of Probabilities:

• Nominal/Symbolic Attributes

P (Ak = ak | C = ci) =#(Ak = ak, C = ci) + γ

#(C = ci) + nAkγ

γ is called Laplace correction.

γ = 0: Maximum likelihood estimation.

Common choices: γ = 1 or γ = 12.

Christian Borgelt Data Mining / Intelligent Data Analysis 279

Naive Bayes Classifiers

Estimation of Probabilities:

• Metric/Numeric Attributes: Assume a normal distribution.

f (Ak = ak | C = ci) =1√

2πσk(ci)exp

(−(ak − µk(ci))

2

2σ2k(ci)

)

• Estimate of mean value

µk(ci) =1

#(C = ci)

#(C=ci)∑

j=1

ak(j)

• Estimate of variance

σ2k(ci) =1

ξ

#(C=ci)∑

j=1

(ak(j)− µk(ci))2

ξ = #(C = ci) : Maximum likelihood estimationξ = #(C = ci)− 1: Unbiased estimation

Christian Borgelt Data Mining / Intelligent Data Analysis 280

Page 71: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Naive Bayes Classifiers: Simple Example 1

No Sex Age Blood pr. Drug

1 male 20 normal A2 female 73 normal B3 female 37 high A4 male 33 low B5 female 48 high A6 male 29 normal A7 female 52 normal B8 male 42 low B9 male 61 normal B10 female 30 normal A11 female 26 low B12 male 54 high A

P (Drug) A B

0.5 0.5

P (Sex | Drug) A B

male 0.5 0.5female 0.5 0.5

P (Age | Drug) A B

µ 36.3 47.8

σ2 161.9 311.0

P (Blood Pr. | Drug) A B

low 0 0.5normal 0.5 0.5high 0.5 0

A simple database and estimated (conditional) probability distributions.

Christian Borgelt Data Mining / Intelligent Data Analysis 281

Naive Bayes Classifiers: Simple Example 1

d(Drug A | male, 61, normal)

= c1 · P (Drug A) · P (male | Drug A) · f (61 | Drug A) · P (normal | Drug A)

≈ c1 · 0.5 · 0.5 · 0.004787 · 0.5 = c1 · 5.984 · 10−4 = 0.219

f (Drug B | male, 61, normal)

= c1 · P (Drug B) · P (male | Drug B) · f (61 | Drug B) · P (normal | Drug B)

≈ c1 · 0.5 · 0.5 · 0.017120 · 0.5 = c1 · 2.140 · 10−3 = 0.781

f (Drug A | female, 30, normal)

= c2 · P (Drug A) · P (female | Drug A) · f (30 | Drug A) · P (normal | Drug A)

≈ c2 · 0.5 · 0.5 · 0.027703 · 0.5 = c2 · 3.471 · 10−3 = 0.671

f (Drug B | female, 30, normal)

= c2 · P (Drug B) · P (female | Drug B) · f (30 | Drug B) · P (normal | Drug B)

≈ c2 · 0.5 · 0.5 · 0.013567 · 0.5 = c2 · 1.696 · 10−3 = 0.329

Christian Borgelt Data Mining / Intelligent Data Analysis 282

Naive Bayes Classifiers: Simple Example 2

• 100 data points, 2 classes

• Small squares: mean values

• Inner ellipses:one standard deviation

• Outer ellipses:two standard deviations

• Classes overlap:classification is not perfect

Naive Bayes Classifier

Christian Borgelt Data Mining / Intelligent Data Analysis 283

Naive Bayes Classifiers: Simple Example 3

• 20 data points, 2 classes

• Small squares: mean values

• Inner ellipses:one standard deviation

• Outer ellipses:two standard deviations

• Attributes are not conditionallyindependent given the class

Naive Bayes Classifier

Christian Borgelt Data Mining / Intelligent Data Analysis 284

Page 72: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Reminder: The Iris Data

pictures not available in online version

• Collected by Edgar Anderson on the Gaspe Peninsula (Canada).

• First analyzed by Ronald Aylmer Fisher (famous statistician).

• 150 cases in total, 50 cases per Iris flower type.

• Measurements of sepal length and width and petal length and width (in cm).

• Most famous data set in pattern recognition and data analysis.

Christian Borgelt Data Mining / Intelligent Data Analysis 285

Naive Bayes Classifiers: Iris Data

• 150 data points, 3 classes

Iris setosa (red)Iris versicolor (green)Iris virginica (blue)

• Shown: 2 out of 4 attributes

sepal lengthsepal widthpetal length (horizontal)petal width (vertical)

• 6 misclassificationson the training data(with all 4 attributes) Naive Bayes Classifier

Christian Borgelt Data Mining / Intelligent Data Analysis 286

Full Bayes Classifiers

• Restricted to metric/numeric attributes (only the class is nominal/symbolic).

• Simplifying Assumption:Each class can be described by a multivariate normal distribution.

f (A1 = a1, . . . , Am = am | C = ci)

=1√

(2π)m|Σi|exp

(−12(~a− ~µi)⊤Σ−1i (~a− ~µi)

)

~µi: mean value vector for class ci

Σi: covariance matrix for class ci

• Intuitively: Each class has a bell-shaped probability density.

• Naive Bayes classifiers: Covariance matrices are diagonal matrices.(Details about this relation are given below.)

Christian Borgelt Data Mining / Intelligent Data Analysis 287

Full Bayes Classifiers

Estimation of Probabilities:

• Estimate of mean value vector

~µi =1

#(C = ci)

#(C=ci)∑

j=1

~a(j)

• Estimate of covariance matrix

Σi =1

ξ

#(C=ci)∑

j=1

(~a(j)− ~µi

) (~a(j)− ~µi

)⊤

ξ = #(C = ci) : Maximum likelihood estimationξ = #(C = ci)− 1: Unbiased estimation

~x⊤ denotes the transpose of the vector ~x.

~x~x⊤ is the so-called outer product or matrix product of ~x with itself.

Christian Borgelt Data Mining / Intelligent Data Analysis 288

Page 73: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Comparison of Naive and Full Bayes Classifiers

Naive Bayes classifiers for metric/numeric data are equivalentto full Bayes classifiers with diagonal covariance matrices:

f (A1 = a1, . . . , Am = am | C = ci)

=1√

(2π)m|Σi|· exp

(−12(~a− ~µi)⊤Σ−1i (~a− ~µi)

)

=1√

(2π)m∏mk=1 σ

2i,k

· exp(−12(~a− ~µi)⊤ diag

(σ−2i,1 , . . . , σ

−2i,m

)(~a− ~µi)

)

=1

∏mk=1

√2πσ2i,k

· exp−1

2

m∑

k=1

(ak − µi,k)2σ2i,k

=m∏

k=1

1√2πσ2i,k

· exp−(ak − µi,k)

2

2σ2i,k

=

m∏

k=1

f (Ak = ak | C = ci),

where f (Ak = ak | C = ci) are the density functions of a naive Bayes classifier.

Christian Borgelt Data Mining / Intelligent Data Analysis 289

Comparison of Naive and Full Bayes Classifiers

Naive Bayes Classifier Full Bayes Classifier

Christian Borgelt Data Mining / Intelligent Data Analysis 290

Full Bayes Classifiers: Iris Data

• 150 data points, 3 classes

Iris setosa (red)Iris versicolor (green)Iris virginica (blue)

• Shown: 2 out of 4 attributes

sepal lengthsepal widthpetal length (horizontal)petal width (vertical)

• 2 misclassificationson the training data(with all 4 attributes) Full Bayes Classifier

Christian Borgelt Data Mining / Intelligent Data Analysis 291

Tree-Augmented Naive Bayes Classifiers

• A naive Bayes classifier can be seen as a special Bayesian network.

• Intuitively, Bayesian networks are a graphical language for expressing conditionalindependence statements: A directed acyclic graph encodes, by a vertex separationcriterion, which conditional independence statements hold in the joint probabilitydistribution on the space spanned by the vertex attributes.

Definition (d-separation):Let ~G = (V, ~E) be a directed acyclic graph and X , Y , and Z three disjoint subsets ofvertices. Z d-separates X and Y in ~G, written 〈X | Z | Y 〉 ~G, iff there is no pathfrom a vertex in X to a vertex in Y along which the following two conditions hold:

1. every vertex with converging edges (from its predecessor and its successor on thepath) either is in Z or has a descendant in Z,

2. every other vertex is not in Z.

A path satisfying the conditions above is said to be active, otherwise it is said to beblocked (by Z); so separation means that all paths are blocked.

Christian Borgelt Data Mining / Intelligent Data Analysis 292

Page 74: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Tree-Augmented Naive Bayes Classifiers

C

A1

A2

A3

A4 An

· · ·

C

A1

A2

A3

A4 An

· · ·

• If in a directed acyclic graph all paths from a vertex set X to a vertex set Yare blocked by a vertex set Z (according to d-separation), this expresses that theconditional independence X ⊥⊥ Y | Z holds in the probability distribution that isdescribed by a Bayesina network having this graph structure.

• A star-like network, with the class attribute in the middle, represents a naive Bayesclassifier: All paths are blocked by the class attribute C.

• The strong conditional independence assumptions can be mitigated by allowingfor additional edges between attributes. Restricting these edges to a (directed)tree allows for efficient learning (tree-augmented naive Bayes classifiers).

Christian Borgelt Data Mining / Intelligent Data Analysis 293

Summary Bayes Classifiers

• Probabilistic Classification: Assign the most probable class.

• Bayes’ Rule: “Invert” the conditional class probabilities.

• Naive Bayes Classifiers

◦ Simplifying Assumption:Attributes are conditionally independent given the class.

◦ Can handle nominal/symbolic as well as metric/numeric attributes.

• Full Bayes Classifiers

◦ Simplifying Assumption:Each class can be described by a multivariate normal distribution.

◦ Can handle only metric/numeric attributes.

• Tree-Augmented Naive Bayes Classifiers

◦ Mitigate the strong conditional independence assumptions.

Christian Borgelt Data Mining / Intelligent Data Analysis 294

Decision and Regression Trees

Christian Borgelt Data Mining / Intelligent Data Analysis 295

Decision and Regression Trees

• Classification with a Decision Tree

• Top-down Induction of Decision Trees

◦ A simple example

◦ The general algorithm

◦ Attribute selection measures

◦ Treatment of numeric attributes and missing values

• Pruning Decision Trees

◦ General approaches

◦ A simple example

• Regression Trees

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 296

Page 75: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

A Very Simple Decision Tree

Assignment of a drug to a patient:

Blood pressure

AgeDrug A Drug B

Drug A Drug B

normalhigh low

≤ 40 > 40

Christian Borgelt Data Mining / Intelligent Data Analysis 297

Classification with a Decision Tree

Recursive Descent:

• Start at the root node.

• If the current node is an leaf node:

◦ Return the class assigned to the node.

• If the current node is an inner node:

◦ Test the attribute associated with the node.

◦ Follow the branch labeled with the outcome of the test.

◦ Apply the algorithm recursively.

Intuitively: Follow the path corresponding to the case to be classified.

Christian Borgelt Data Mining / Intelligent Data Analysis 298

Classification in the Example

Assignment of a drug to a patient:

Blood pressure

AgeDrug A Drug B

Drug A Drug B

normalhigh low

≤ 40 > 40

Christian Borgelt Data Mining / Intelligent Data Analysis 299

Classification in the Example

Assignment of a drug to a patient:

Blood pressure

AgeDrug A Drug B

Drug A Drug B

normalhigh low

≤ 40 > 40

Christian Borgelt Data Mining / Intelligent Data Analysis 300

Page 76: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Classification in the Example

Assignment of a drug to a patient:

Blood pressure

AgeDrug A Drug B

Drug A Drug B

normal

≤ 40

high low

> 40

Christian Borgelt Data Mining / Intelligent Data Analysis 301

Induction of Decision Trees

• Top-down approach

◦ Build the decision tree from top to bottom(from the root to the leaves).

• Greedy Selection of a Test Attribute

◦ Compute an evaluation measure for all attributes.

◦ Select the attribute with the best evaluation.

• Divide and Conquer / Recursive Descent

◦ Divide the example cases according to the values of the test attribute.

◦ Apply the procedure recursively to the subsets.

◦ Terminate the recursion if – all cases belong to the same class

– no more test attributes are available

Christian Borgelt Data Mining / Intelligent Data Analysis 302

Induction of a Decision Tree: Example

Patient database

• 12 example cases

• 3 descriptive attributes

• 1 class attribute

Assignment of drug

(without patient attributes)

always drug A or always drug B:

50% correct (in 6 of 12 cases)

No Gender Age Blood pr. Drug

1 male 20 normal A2 female 73 normal B3 female 37 high A4 male 33 low B5 female 48 high A6 male 29 normal A7 female 52 normal B8 male 42 low B9 male 61 normal B10 female 30 normal A11 female 26 low B12 male 54 high A

Christian Borgelt Data Mining / Intelligent Data Analysis 303

Induction of a Decision Tree: Example

Gender of the patient

• Division w.r.t. male/female.

Assignment of drug

male: 50% correct (in 3 of 6 cases)

female: 50% correct (in 3 of 6 cases)

total: 50% correct (in 6 of 12 cases)

No Gender Drug

1 male A6 male A12 male A4 male B8 male B9 male B

3 female A5 female A10 female A2 female B7 female B11 female B

Christian Borgelt Data Mining / Intelligent Data Analysis 304

Page 77: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Induction of a Decision Tree: Example

Age of the patient

• Sort according to age.

• Find best age split.here: ca. 40 years

Assignment of drug

≤ 40: A 67% correct (in 4 of 6 cases)

> 40: B 67% correct (in 4 of 6 cases)

total: 67% correct (in 8 of 12 cases)

No Age Drug

1 20 A11 26 B6 29 A10 30 A4 33 B3 37 A

8 42 B5 48 A7 52 B12 54 A9 61 B2 73 B

Christian Borgelt Data Mining / Intelligent Data Analysis 305

Induction of a Decision Tree: Example

Blood pressure of the patient

• Division w.r.t. high/normal/low.

Assignment of drug

high: A 100% correct (in 3 of 3 cases)

normal: 50% correct (in 3 of 6 cases)

low: B 100% correct (in 3 of 3 cases)

total: 75% correct (in 9 of 12 cases)

No Blood pr. Drug

3 high A5 high A12 high A

1 normal A6 normal A10 normal A2 normal B7 normal B9 normal B

4 low B8 low B11 low B

Christian Borgelt Data Mining / Intelligent Data Analysis 306

Induction of a Decision Tree: Example

Current Decision Tree:

Blood pressure

?Drug A Drug B

normalhigh low

Christian Borgelt Data Mining / Intelligent Data Analysis 307

Induction of a Decision Tree: Example

Blood pressure and gender

• Only patientswith normal blood pressure.

• Division w.r.t. male/female.

Assignment of drug

male: A 67% correct (2 of 3)

female: B 67% correct (2 of 3)

total: 67% correct (4 of 6)

No Blood pr. Gender Drug

3 high A5 high A12 high A

1 normal male A6 normal male A9 normal male B

2 normal female B7 normal female B10 normal female A

4 low B8 low B11 low B

Christian Borgelt Data Mining / Intelligent Data Analysis 308

Page 78: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Induction of a Decision Tree: Example

Blood pressure and age

• Only patientswith normal blood pressure.

• Sort according to age.

• Find best age split.here: ca. 40 years

Assignment of drug

≤ 40: A 100% correct (3 of 3)

> 40: B 100% correct (3 of 3)

total: 100% correct (6 of 6)

No Blood pr. Age Drug

3 high A5 high A12 high A

1 normal 20 A6 normal 29 A10 normal 30 A

7 normal 52 B9 normal 61 B2 normal 73 B

11 low B4 low B8 low B

Christian Borgelt Data Mining / Intelligent Data Analysis 309

Result of Decision Tree Induction

Assignment of a drug to a patient:

Blood pressure

AgeDrug A Drug B

Drug A Drug B

normalhigh low

≤ 40 > 40

Christian Borgelt Data Mining / Intelligent Data Analysis 310

Decision Tree Induction: Notation

S a set of case or object descriptions

C the class attribute

A(1), . . . , A(m) other attributes (index dropped in the following)

dom(C) = {c1 , . . . , cnC}, nC : number of classes

dom(A) = {a1, . . . , anA}, nA: number of attribute values

N.. total number of case or object descriptions i.e. N.. = |S|Ni. absolute frequency of the class ci

N.j absolute frequency of the attribute value aj

Nij absolute frequency of the combination of the class ci and the attribute value aj.It is Ni. =

∑nA

j=1Nij and N.j =∑nC

i=1Nij.

pi. relative frequency of the class ci, pi. =Ni.

N..

p.j relative frequency of the attribute value aj, p.j =N.j

N..

pij relative frequency of the combination of class ci and attribute value aj, pij =Nij

N..

pi|j relative frequency of the class ci in cases having attribute value aj, pi|j =Nij

N.j= pij

p.j

Christian Borgelt Data Mining / Intelligent Data Analysis 311

Decision Tree Induction: General Algorithm

function grow tree (S : set of cases) : node;begin

best v := WORTHLESS;for all untested attributes A do

compute frequencies Nij, Ni., N.j for 1 ≤ i ≤ nC and 1 ≤ j ≤ nA;compute value v of an evaluation measure using Nij, Ni., N.j;if v > best v then best v := v; best A := A; end;

endif best v = WORTHLESSthen create leaf node x;

assign majority class of S to x;else create test node x;

assign test on attribute best A to x;for all a ∈ dom(best A) do x.child[a] := grow tree(S|best A=a); end;

end;return x;

end;

Christian Borgelt Data Mining / Intelligent Data Analysis 312

Page 79: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Evaluation Measures

• Evaluation measure used in the above example:rate of correctly classified example cases.

◦ Advantage: simple to compute, easy to understand.

◦ Disadvantage: works well only for two classes.

• If there are more than two classes, the rate of misclassified example casesneglects a lot of the available information.

◦ Only the majority class—that is, the class occurring most oftenin (a subset of) the example cases—is really considered.

◦ The distribution of the other classes has no influence. However, a good choicehere can be important for deeper levels of the decision tree.

• Therefore: Study also other evaluation measures. Here:

◦ Information gain and its various normalizations.

◦ χ2 measure (well-known in statistics).

Christian Borgelt Data Mining / Intelligent Data Analysis 313

An Information-theoretic Evaluation Measure

Information Gain (Kullback and Leibler 1951, Quinlan 1986)

Based on Shannon Entropy H = −n∑

i=1

pi log2 pi (Shannon 1948)

Igain(C,A) = H(C) − H(C|A)

=

︷ ︸︸ ︷

−nC∑

i=1

pi. log2 pi. −

︷ ︸︸ ︷nA∑

j=1

p.j

nC∑

i=1

pi|j log2 pi|j

H(C) Entropy of the class distribution (C: class attribute)

H(C|A) Expected entropy of the class distributionif the value of the attribute A becomes known

H(C)−H(C|A) Expected entropy reduction or information gain

Christian Borgelt Data Mining / Intelligent Data Analysis 314

Interpretation of Shannon Entropy

• Let S = {s1, . . . , sn} be a finite set of alternatives having positive probabilitiesP (si), i = 1, . . . , n, satisfying

∑ni=1 P (si) = 1.

• Shannon Entropy:

H(S) = −n∑

i=1

P (si) log2 P (si)

• Intuitively: Expected number of yes/no questions that have to beasked in order to determine the obtaining alternative.

◦ Suppose there is an oracle, which knows the obtaining alternative,but responds only if the question can be answered with “yes” or “no”.

◦ A better question scheme than asking for one alternative after the other caneasily be found: Divide the set into two subsets of about equal size.

◦ Ask for containment in an arbitrarily chosen subset.

◦ Apply this scheme recursively → number of questions bounded by ⌈log2 n⌉.

Christian Borgelt Data Mining / Intelligent Data Analysis 315

Question/Coding Schemes

P (s1) = 0.10, P (s2) = 0.15, P (s3) = 0.16, P (s4) = 0.19, P (s5) = 0.40

Shannon entropy: −∑i P (si) log2 P (si) = 2.15 bit/symbol

Linear Traversal

s4, s5

s3, s4, s5

s2, s3, s4, s5

s1, s2, s3, s4, s5

0.10 0.15 0.16 0.19 0.40s1 s2 s3 s4 s51 2 3 4 4

Code length: 3.24 bit/symbolCode efficiency: 0.664

Equal Size Subsets

s1, s2, s3, s4, s5

0.25 0.75s1, s2 s3, s4, s5

0.59s4, s5

0.10 0.15 0.16 0.19 0.40s1 s2 s3 s4 s52 2 2 3 3

Code length: 2.59 bit/symbolCode efficiency: 0.830

Christian Borgelt Data Mining / Intelligent Data Analysis 316

Page 80: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Question/Coding Schemes

• Splitting into subsets of about equal size can lead to a bad arrangement of thealternatives into subsets → high expected number of questions.

• Good question schemes take the probability of the alternatives into account.

• Shannon-Fano Coding (1948)

◦ Build the question/coding scheme top-down.

◦ Sort the alternatives w.r.t. their probabilities.

◦ Split the set so that the subsets have about equal probability(splits must respect the probability order of the alternatives).

• Huffman Coding (1952)

◦ Build the question/coding scheme bottom-up.

◦ Start with one element sets.

◦ Always combine those two sets that have the smallest probabilities.

Christian Borgelt Data Mining / Intelligent Data Analysis 317

Question/Coding Schemes

P (s1) = 0.10, P (s2) = 0.15, P (s3) = 0.16, P (s4) = 0.19, P (s5) = 0.40

Shannon entropy: −∑i P (si) log2 P (si) = 2.15 bit/symbol

Shannon–Fano Coding (1948)

s1, s2, s3, s4, s5

0.25

0.41

s1, s2

s1, s2, s30.59s4, s5

0.10 0.15 0.16 0.19 0.40s1 s2 s3 s4 s53 3 2 2 2

Code length: 2.25 bit/symbolCode efficiency: 0.955

Huffman Coding (1952)

s1, s2, s3, s4, s5

0.60s1, s2, s3, s4

0.25 0.35s1, s2 s3, s4

0.10 0.15 0.16 0.19 0.40s1 s2 s3 s4 s53 3 3 3 1

Code length: 2.20 bit/symbolCode efficiency: 0.977

Christian Borgelt Data Mining / Intelligent Data Analysis 318

Question/Coding Schemes

• It can be shown that Huffman coding is optimal if we have to determine theobtaining alternative in a single instance.(No question/coding scheme has a smaller expected number of questions.)

• Only if the obtaining alternative has to be determined in a sequence of (indepen-dent) situations, this scheme can be improved upon.

• Idea: Process the sequence not instance by instance, but combine two, threeor more consecutive instances and ask directly for the obtaining combination ofalternatives.

• Although this enlarges the question/coding scheme, the expected number of ques-tions per identification is reduced (because each interrogation identifies the ob-taining alternative for several situations).

• However, the expected number of questions per identification cannot be made ar-bitrarily small. Shannon showed that there is a lower bound, namely the Shannonentropy.

Christian Borgelt Data Mining / Intelligent Data Analysis 319

Interpretation of Shannon Entropy

P (s1) =12, P (s2) =

14, P (s3) =

18, P (s4) =

116, P (s5) =

116

Shannon entropy: −∑i P (si) log2 P (si) = 1.875 bit/symbol

If the probability distribution allows for aperfect Huffman code (code efficiency 1),the Shannon entropy can easily be inter-preted as follows:

−∑

i

P (si) log2 P (si)

=∑

i

P (si)︸ ︷︷ ︸

occurrenceprobability

· log21

P (si)︸ ︷︷ ︸path length

in tree

.

In other words, it is the expected numberof needed yes/no questions.

Perfect Question Scheme

s4, s5

s3, s4, s5

s2, s3, s4, s5

s1, s2, s3, s4, s5

12

14

18

116

116

s1 s2 s3 s4 s51 2 3 4 4

Code length: 1.875 bit/symbolCode efficiency: 1

Christian Borgelt Data Mining / Intelligent Data Analysis 320

Page 81: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Other Information-theoretic Evaluation Measures

Normalized Information Gain

• Information gain is biased towards many-valued attributes.

• Normalization removes / reduces this bias.

Information Gain Ratio (Quinlan 1986 / 1993)

Igr(C,A) =Igain(C,A)

HA=

Igain(C,A)

−∑nAj=1 p.j log2 p.j

Symmetric Information Gain Ratio (Lopez de Mantaras 1991)

I(1)sgr(C,A) =

Igain(C,A)

HACor I

(2)sgr(C,A) =

Igain(C,A)

HA +HC

Christian Borgelt Data Mining / Intelligent Data Analysis 321

Bias of Information Gain

• Information gain is biased towards many-valued attributes,i.e., of two attributes having about the same information content it tends to selectthe one having more values.

• The reasons are quantization effects caused by the finite number of example cases(due to which only a finite number of different probabilities can result in estima-tions) in connection with the following theorem:

• Theorem: Let A, B, and C be three attributes with finite domains and lettheir joint probability distribution be strictly positive, i.e., ∀a ∈ dom(A) : ∀b ∈dom(B) : ∀c ∈ dom(C) : P (A = a,B = b, C = c) > 0. Then

Igain(C,AB) ≥ Igain(C,B),

with equality obtaining only if the attributes C and A are conditionally indepen-dent given B, i.e., if P (C = c | A = a,B = b) = P (C = c | B = b).

(A detailed proof of this theorem can be found, for example, in [Borgelt and Kruse 2002], p. 311ff.)

Christian Borgelt Data Mining / Intelligent Data Analysis 322

A Statistical Evaluation Measure

χ2 Measure

• Compares the actual joint distributionwith a hypothetical independent distribution.

• Uses absolute comparison.

• Can be interpreted as a difference measure.

χ2(C,A) =nC∑

i=1

nA∑

j=1

N..(pi.p.j − pij)2

pi.p.j

• Side remark: Information gain can also be interpreted as a difference measure.

Igain(C,A) =nC∑

i=1

nA∑

j=1

pij log2pijpi.p.j

Christian Borgelt Data Mining / Intelligent Data Analysis 323

Treatment of Numeric Attributes

General Approach: Discretization

• Preprocessing I

◦ Form equally sized or equally populated intervals.

• During the tree construction

◦ Sort the example cases according to the attribute’s values.

◦ Construct a binary symbolic attribute for every possible split(values: “≤ threshold” and “> threshold”).

◦ Compute the evaluation measure for these binary attributes.

◦ Possible improvements: Add a penalty depending on the number of splits.

• Preprocessing II / Multisplits during tree construction

◦ Build a decision tree using only the numeric attribute.

◦ Flatten the tree to obtain a multi-interval discretization.

Christian Borgelt Data Mining / Intelligent Data Analysis 324

Page 82: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Treatment of Numeric Attributes

So-called “oblique” decision treesare able to find the yellow line.

• Problem: If the class boundary is obliquein the space spanned by two or more nu-meric attributes, decision trees constructa step function as the decision boundary.

• Green: data points of class ABlue: data points of class BYellow: actual class boundaryRed: decision boundary

built by a decision treeGray: subdivision of the space

used by a decision tree(threshold values)

• Note: the complex decision boundaryeven produces an error!

Christian Borgelt Data Mining / Intelligent Data Analysis 325

Treatment of Numeric Attributes

So-called “oblique” decision treesare able to find the yellow line.

• For the data set on the preceding slide adecision tree builds a proper step functionas the decision boundary. Although sub-optimal, this may still be acceptable.

• Unfortunately, other data point config-urations can lead to strange anomalies,which do not approximate the actual de-cision boundary well.

• Green: data points of class ABlue: data points of class BYellow: actual class boundaryRed: decision boundary

built by a decision treeGray: subdivision of the space

used by a decision tree

Christian Borgelt Data Mining / Intelligent Data Analysis 326

Treatment of Missing Values

Induction

• Weight the evaluation measure with the fraction of cases with known values.

◦ Idea: The attribute provides information only if it is known.

• Try to find a surrogate test attribute with similar properties(CART, Breiman et al. 1984)

• Assign the case to all branches, weighted in each branch with the relative frequencyof the corresponding attribute value (C4.5, Quinlan 1993).

Classification

• Use the surrogate test attribute found during induction.

• Follow all branches of the test attribute, weighted with their relative numberof cases, aggregate the class distributions of all leaves reached, and assign themajority class of the aggregated class distribution.

Christian Borgelt Data Mining / Intelligent Data Analysis 327

Pruning Decision Trees

Pruning serves the purpose

• to simplify the tree (improve interpretability),

• to avoid overfitting (improve generalization).

Basic ideas:

• Replace “bad” branches (subtrees) by leaves.

• Replace a subtree by its largest branch if it is better.

Common approaches:

• Limiting the number of leaf cases

• Reduced error pruning

• Pessimistic pruning

• Confidence level pruning

• Minimum description length pruning

Christian Borgelt Data Mining / Intelligent Data Analysis 328

Page 83: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Limiting the Number of Leaf Cases

• A decision tree may be grown until either the set of sample cases is class-pureor the set of descriptive attributes is exhausted.

• However, this may lead to leaves that capture only very few,in extreme cases even just a single sample case.

• Thus a decision tree may become very similar to a 1-nearest-neighbor classifier.

• In order to prevent such results, it is common to let a userspecify a minimum number of sample cases per leaf.

• In such an approach, splits are usually limited to binary splits.(nominal attributes: usually one attribute value against all others)

• A split is then adopted only if on both sides of the splitat least the minimum number of sample cases are present.

• Note that this approach is not an actual pruning method,as it is already applied during induction, not after.

Christian Borgelt Data Mining / Intelligent Data Analysis 329

Reduced Error Pruning

• Classify a set of new example cases with the decision tree.(These cases must not have been used for the induction!)

• Determine the number of errors for all leaves.

• The number of errors of a subtree is the sum of the errors of all of its leaves.

• Determine the number of errors for leaves that replace subtrees.

• If such a leaf leads to the same or fewer errors than the subtree,replace the subtree by the leaf.

• If a subtree has been replaced,recompute the number of errors of the subtrees it is part of.

Advantage: Very good pruning, effective avoidance of overfitting.

Disadvantage: Additional example cases needed.

Christian Borgelt Data Mining / Intelligent Data Analysis 330

Pessimistic Pruning

• Classify a set of example cases with the decision tree.(These cases may or may not have been used for the induction.)

• Determine the number of errors for all leaves andincrease this number by a fixed, user-specified amount r.

• The number of errors of a subtree is the sum of the errors of all of its leaves.

• Determine the number of errors for leaves that replace subtrees(also increased by r).

• If such a leaf leads to the same or fewer errors than the subtree,replace the subtree by the leaf and recompute subtree errors.

Advantage: No additional example cases needed.

Disadvantage: Number of cases in a leaf has no influence.

Christian Borgelt Data Mining / Intelligent Data Analysis 331

Confidence Level Pruning

• Like pessimistic pruning, but the number of errors is computed as follows:

◦ See classification in a leaf as a Bernoulli experiment (error / no error).

◦ Estimate an interval for the error probability based on a user-specified confi-dence level α.(use approximation of the binomial distribution by a normal distribution)

◦ Increase error number to the upper level of the confidence intervaltimes the number of cases assigned to the leaf.

◦ Formal problem: Classification is not a random experiment.

Advantage: No additional example cases needed, good pruning.

Disadvantage: Statistically dubious foundation.

Christian Borgelt Data Mining / Intelligent Data Analysis 332

Page 84: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Pruning a Decision Tree: A Simple Example

Pessimistic Pruning with r = 0.8 and r = 0.4:

c1: 13, c2: 7

c1: 5, c2: 2 c1: 6, c2: 2 c1: 2, c2: 3

a1 a2 a3

leaf:

r = 0.8:

r = 0.4:

7.0 errors

7.8 errors (prune subtree)

7.4 errors (keep subtree)

2.8 errors

2.4 errors

2.8 errors

2.4 errors

2.8 errors

2.4 errors

total: 6.0 errors

r = 0.8:

r = 0.4:

8.4 errors

7.2 errors

Christian Borgelt Data Mining / Intelligent Data Analysis 333

Reminder: The Iris Data

pictures not available in online version

• Collected by Edgar Anderson on the Gaspe Peninsula (Canada).

• First analyzed by Ronald Aylmer Fisher (famous statistician).

• 150 cases in total, 50 cases per Iris flower type.

• Measurements of sepal length and width and petal length and width (in cm).

• Most famous data set in pattern recognition and data analysis.

Christian Borgelt Data Mining / Intelligent Data Analysis 334

Decision Trees: An Example

A decision tree for the Iris data(induced with information gain ratio, unpruned)

Christian Borgelt Data Mining / Intelligent Data Analysis 335

Decision Trees: An Example

A decision tree for the Iris data(pruned with confidence level pruning, α = 0.8, and pessimistic pruning, r = 2)

• Left: 7 instead of 11 nodes, 4 instead of 2 misclassifications.

• Right: 5 instead of 11 nodes, 6 instead of 2 misclassifications.

• The right tree is “minimal” for the three classes.

Christian Borgelt Data Mining / Intelligent Data Analysis 336

Page 85: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Regression Trees

• Target variable is not a class,but a numeric quantity.

• Simple regression trees:predict constant values in leaves.(blue lines)

• More complex regression trees:predict linear functions in leaves.(red line)

x

y

30 60

x: input variable, y: target variable

Christian Borgelt Data Mining / Intelligent Data Analysis 337

Regression Trees: Attribute Selection

a1 a2

distributions ofthe target value

split w.r.t.a test attribute

• The variance / standard deviation is compared tothe variance / standard deviation in the branches.

• The attribute that yields the highest reduction is selected.

Christian Borgelt Data Mining / Intelligent Data Analysis 338

Regression Trees: An Example

A regression tree for the Iris data (petal width)(induced with reduction of sum of squared errors)

Christian Borgelt Data Mining / Intelligent Data Analysis 339

Summary Decision and Regression Trees

• Decision Trees are Classifiers with Tree Structure

◦ Inner node: Test of a descriptive attribute

◦ Leaf node: Assignment of a class

• Induction of Decision Trees from Data

(Top-Down Induction of Decision Trees, TDIDT)

◦ Divide and conquer approach / recursive descent

◦ Greedy selection of the test attributes

◦ Attributes are selected based on an evaluation measure,e.g. information gain, χ2 measure

◦ Recommended: Pruning of the decision tree

• Numeric Target: Regression Trees

Christian Borgelt Data Mining / Intelligent Data Analysis 340

Page 86: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

k-Nearest Neighbors

Christian Borgelt Data Mining / Intelligent Data Analysis 341

k-Nearest Neighbors

• Basic Principle and Simple Examples

• Ingredients of k-Nearest Neighbors

◦ Distance Metric

◦ Number of Neighbors

◦ Weighting Function for the Neighbors

◦ Prediction Function

• Weighting with Kernel Functions

• Locally Weighted Polynomial Regression

• Implementation Aspects

• Feature/Attribute Weights

• Data Set Reduction and Prototype Building

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 342

k-Nearest Neighbors: Principle

• The nearest neighbor algorithm [Cover and Hart 1967] is one of the simplestand most natural classification and numeric prediction methods.

• It derives the class labels or the (numeric) target values of new input objectsfrom the most similar training examples,where similarity is measured by distance in the feature space.

• The prediction is computed by a majority vote of the nearest neighborsor by averaging their (numeric) target values.

• The number k of neighbors to be taken into accountis a parameter of the algorithm, the best choice of whichdepends on the data and the prediction task.

• In a basic nearest neighbor approach only one neighbor object,namely the closest one, is considered,and its class or target value is directly transferred to the query object.

Christian Borgelt Data Mining / Intelligent Data Analysis 343

k-Nearest Neighbors: Principle

• Constructing nearest neighbor classifiers and numeric predictorsis a special case of instance-based learning [Aha et al. 1991].

• As such, it is a lazy learning method in the sense that it is not triedto construct a model that generalizes beyond the training data(as eager learning methods do).

• Rather, the training examples are merely stored.

• Predictions for new cases are derived directly from these stored examplesand their (known) classes or target values,usually without any intermediate model construction.

• (Partial) Exception: lazy decision trees construct from the stored casesthe single path in the decision tree along which the query object is passed down.

• This can improve on standard decision trees in the presence of missing values.

• However, this comes at the price of higher classification costs.

Christian Borgelt Data Mining / Intelligent Data Analysis 344

Page 87: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

k-Nearest Neighbors: Simple Examples

input

output

• In both example cases it is k = 1.

• Classification works with a Voronoi tesselation of the data space.

• Numeric prediction leads to a piecewise constant function.

• Using more than one neighbor changes the classification/prediction.

Christian Borgelt Data Mining / Intelligent Data Analysis 345

Delaunay Triangulations and Voronoi Diagrams

• Dots represent data points

• Left: Delaunay TriangulationThe circle through the corners of a triangle does not contain another point.

• Right: Voronoi Diagram / TesselationMidperpendiculars of the Delaunay triangulation: boundaries of the regionsof points that are closest to the enclosed data points (Voronoi cells).

Christian Borgelt Data Mining / Intelligent Data Analysis 346

k-nearest Neighbors: Simple Examples

input

output

• Note: neither the Voronoi tessellation nor the piecewise constant function areactually computed in the learning process; no model is built at training time.

• The prediction is determined only in response to a query for the class or targetvalue of a new input object, namely by finding the closest neighbor of the queryobject and then transferring its class or target value. learned models.

Christian Borgelt Data Mining / Intelligent Data Analysis 347

Using More Than One Neighbor

• A straightforward generalization of the nearest neighbor approach is to use not justthe one closest, but the k nearest neighbors (usually abbreviated as k-NN).

• If the task is classification, the prediction is then determined by a majority voteamong these k neighbors (breaking ties arbitrarily).

• If the task is numeric prediction, the average of the target valuesof these k neighbors is computed.

• Not surprisingly, using more than one neighbor improves the robustnessof the algorithm, since it is not so easily fooled by individual training instancesthat are labeled incorrectly or are outliers for a class(that is, data points that have an unusual location for the class assigned to them).

• Outliers for the complete data set, on the other hand,do not affect nearest neighbor predictors much, becausethey can only change the prediction for data points that should not occuror should occur only very rarely (provided the rest of the data is representative).

Christian Borgelt Data Mining / Intelligent Data Analysis 348

Page 88: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Using More Than One Neighbor

• However, using too many neighbors can reduce the capability of the algorithmas it may smooth the classification boundaries or the interpolationtoo much to yield good results.

• As a consequence, apart from the core choice of the distance functionthat determines which training examples are the nearest,the choice of the number of neighbors to consider is crucial.

• Once multiple neighbors are considered, further extensions become possible.

• For example, the (relative) influence of a neighbor on the predictionmay be made dependent on its distance from the query point(distance weighted k-nearest neighbors).

• Or the prediction may be computed from a local model thatis constructed on the fly for a given query point (i.e. from its nearest neighbors)rather than by a simple majority or averaging rule.

Christian Borgelt Data Mining / Intelligent Data Analysis 349

k-Nearest Neighbors: Basic Ingredients

• Distance MetricThe distance metric, together with a possible task-specific scaling or weighting ofthe attributes, determines which of the training examples are nearest to a querydata point and thus selects the training example(s) used to compute a prediction.

• Number of NeighborsThe number of neighbors of the query point that are considered can range fromonly one (the basic nearest neighbor approach) through a few (like k-nearest neigh-bor approaches) to, in principle, all data points as an extreme case.

• Weighting Function for the NeighborsIf multiple neighbors are considered, it is plausible that closer (and thus more sim-ilar) neighbors should have a stronger influence on the prediction result. This canbe expressed by a weighting function yielding higher values for smaller distances.

• Prediction FunctionIf multiple neighbors are considered, one needs a procedure to compute the pre-diction from the (generally differing) classes or target values of these neighbors,since they may differ and thus may not yield a unique prediction directly.

Christian Borgelt Data Mining / Intelligent Data Analysis 350

k-Nearest Neighbors: More Than One Neighbor

input

output

3-nearest neighbor predictor,using a simple averagingof the target valuesof the nearest neighbors.

Note that the prediction is stilla piecewise constant function.

• The main effect of the number k of considered neighbors ishow much the class boundaries or the numeric prediction is smoothed.

• If only one neighbor is considered, the prediction is constantin the Voronoi cells of the training data set and meeting the data points.

Christian Borgelt Data Mining / Intelligent Data Analysis 351

k-Nearest Neighbors: Number of Neighbors

• If only one neighbor is considered, the prediction is constantin the Voronoi cells of the training data set.

• This makes the prediction highly susceptible to the deteriorating effectsof incorrectly labeled instances or outliers w.r.t. their class, because a singledata point with the wrong class spoils the prediction in its whole Voronoi cell.

• Considering several neighbors (k > 1) mitigates this problem,since neighbors having the correct class can override the influence of an outlier.

• However, choosing a very large k is also not generally advisable,because it can prevent the classifier from being able to properly approximatenarrow class regions or narrow peaks or valleys in a numeric target function.

• The example of 3-nearest neighbor prediction on the preceding slide(using a simple averaging of the target values of these nearest neighbors)already shows the smoothing effect (especially at the borders of the input range).

• The interpolation deviates considerably from the data points.

Christian Borgelt Data Mining / Intelligent Data Analysis 352

Page 89: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

k-Nearest Neighbors: Number of Neighbors

• A common method to automatically determine an appropriate valuefor the number k of neighbors is cross-validation.

• The training data set is divided into r cross-validation foldsof (approximately) equal size.

• The fold sizes may differ by one data point,to account for the fact that the total number of training examplesmay not be divisible by r, the number of folds.

• Then r classification or prediction experiments are performed:each combination of r − 1 folds is once chosen as the training set, with whichthe remaining fold is classified or the (numeric) target value is predicted,using all numbers k of neighbors from a user-specified range.

• The classification accurracy or the prediction error is aggregated,for the same value k, over these experiments.

• Finally the number k of neighbors that yields the lowest aggregated error is chosen.

Christian Borgelt Data Mining / Intelligent Data Analysis 353

k-Nearest Neighbors: Weighting

• Approaches that weight the considered neighbors differentlybased on their distance to the query point are known asdistance-weighted k-nearest neighbor or(for numeric targets) locally weighted regression orlocally weighted scatterplot smoothing (LOWESS or LOESS).

• Such weighting is mandatory in the extreme casein which all n training examples are used as neighbors,because otherwise only the majority class or the global averageof the target values can be predicted.

• However, it is also recommended for k < n, since it can,at least to some degree, counteract the smoothing effect of a large k,because the excess neighbors are likely to be farther awayand thus will influence the prediction less.

• It should be noted though, that distance-weighted k-NNis not a way of avoiding the need to find a good valuefor the number k of neighbors.

Christian Borgelt Data Mining / Intelligent Data Analysis 354

k-Nearest Neighbors: Weighting

• A typical example of a weighting function for the nearest neighbors is the so-calledtricubic weighting function, which is defined as

w(si, q, k) =

1−

(d(si, q)

dmax(q, k)

)33

.

• q is the query point,

si is (input vector of) the i-th nearest neighbor of q in the training data set,

k is the number of considered neighbors,

d is employed distance function, and

dmax(q, k) is the maximum distance betweenany two points from the set {q, s1, . . . , sk},that is, dmax(q, k) = maxa,b∈{q,s1,...,sk} d(a, b).

• The function w yields the weight with which the target valueof the i-th nearest neighbor si of q enters the prediction computation.

Christian Borgelt Data Mining / Intelligent Data Analysis 355

k-Nearest Neighbors: Weighting

input

output

2-nearest neighbor predictor,using a distance-weighted averagingof the nearest neighbors.

This ensures that the predictionmeets the data points.

• Note that the interpolation is mainly linear(because two nearest neighbors are used),except for some small plateaus close to the data points.

• These result from the weighting, and certain jumps at pointswhere the two closest neighbors are on the same side of the query point.

Christian Borgelt Data Mining / Intelligent Data Analysis 356

Page 90: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

k-Nearest Neighbors: Weighting

• An alternative approach to distance-weighted k-NN consists in abandoningthe requirement of a predetermined number of nearest neighbors.

• Rather a data point is weighted with a kernel regression K that is definedon its distance d to the query point and that satisfies the following properties:(1) K(d) ≥ 0, (2) K(0) = 1 (or at least that K has its mode at 0), and(3) K(d) decreases monotonously for d→∞.

• In this case all training examples for which the kernel function yieldsa non-vanishing value w.r.t. a given query point are used for the prediction.

• Since the density of training examples may, of course, differfor different regions of the feature space, this may lead to a differentnumber of neighbors being considered, depending on the query point.

• If the kernel function has an infinite support(that is, does not vanish for any finite argument value),all data points are considered for any query point.

Christian Borgelt Data Mining / Intelligent Data Analysis 357

k-Nearest Neighbors: Weighting

• By using such a kernel function, we try to mitigate the problem of choosing a goodvalue for the number K of neighbors, which is now taken care of by the fact thatinstances that are farther away have a smaller influence on the prediction result.

• On the other hand, we now face the problem of having to decide how quicklythe influence of a data point should decline with increasing distance,which is analogous to choosing the right number of neighborsand can be equally difficult to solve.

• Examples of kernel functions with a finite support, given as a radius σ around thequery point within which training examples are considered, are

Krect(d) = τ (d ≤ σ),

Ktriangle(d) = τ (d ≤ σ) · (1− d/σ),Ktricubic(d) = τ (d ≤ σ) · (1− d3/σ3)3,

where τ (φ) is 1 if φ is true and 0 otherwise.

Christian Borgelt Data Mining / Intelligent Data Analysis 358

k-Nearest Neighbors: Weighting

• A typical kernel function with infinite support is the Gaussian function

Kgauss(d) = exp

(− d2

2σ2

),

where d is the distance of the training example to the query point andσ2 is a parameter that determines the spread of the Gaussian function.

• The advantage of a kernel with infinite support is thatthe prediction function is smooth (has no jumps) if the kernel is smooth,because then a training case does not suddenly enter the predictionif a query point is moved by an infinitesimal amount,but its influence rises smoothly in line with the kernel function.

• One also does not have to choose a number of neighbors.

• However, the disadvantage is, as already pointed out,that one has to choose an appropriate radius σ for the kernel function,which can be more difficult to choose than an appropriate number of neighbors.

Christian Borgelt Data Mining / Intelligent Data Analysis 359

k-Nearest Neighbors: Weighting

input

output

Kernel weighted regression,using a Gaussian kernel function.

This ensures that the predictionis smooth, though possiblynot very close tothe training data points.

• Note that the regression function is smooth, because the kernel function is smoothand always refers to all data points as neighbors, so that no jumps occur due to achange in the set of nearest neighbors.

• The price one has to pay is an increased computational cost, since the kernelfunction has to be evaluated for all data points, not only for the nearest neighbors.

Christian Borgelt Data Mining / Intelligent Data Analysis 360

Page 91: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

k-Nearest Neighbors: Implementation

• A core issue of implementing nearest neighbor predictionis the data structure used to store the training examples.

• In a naive implementation they are simply stored as a list,which requires merely O(n) time, where n is the number of training examples.

• However, though fast at training time, this approachhas the serious drawback of being very slow at execution time,because a linear traversal of all training examples is neededto find the nearest neighbor(s), requiring O(nm) time,where m is the dimensionality of the data.

• As a consequence, this approach becomes quickly infeasiblewith a growing number of training examples or for high-dimensional data.

• Better approaches rely on data structures like a kd-tree(short for k-dimensional tree, where the k here refers to the number of dimensions,not the number of neighbors), an R- or R∗-tree, a UB-tree etc.

Christian Borgelt Data Mining / Intelligent Data Analysis 361

k-Nearest Neighbors: Prediction Function

• The most straightforward choices for the prediction functionare a simple (weighted) majority vote for classification ora simple (weighted) average for numeric prediction.

• However, especially for numeric prediction,one may also consider more complex prediction functions,like building a local regression model from the neighbors(usually with a linear function or a low-degree polynomial),thus arriving at locally weighted polynomial regression.

• The prediction is then computed from this local model.

• Not surprisingly, distance weighting may also be used in such a setting.

• Such an approach should be employed with a larger number of neighbors,so that a change of the set of nearest neighborsleads to less severe changes of the local regression line.

(Although there will still be jumps of the predicted value in this case, they are just less high.)

Christian Borgelt Data Mining / Intelligent Data Analysis 362

k-Nearest Neighbors: Locally Weighted Regression

input

output

4-nearest neighbor distance-weightedlocally linear regression(using a tricubic weighting function).

Although linear regression is used,the nearest neighbors do not enterwith unit weight!

• Note how the distance weighting leads to deviationsfrom straight lines between the data points.

• Note also the somewhat erratic behavior of the resulting regression function(jumps at points where the set of nearest neighbors changes).This will be less severe, the larger the number of neighbors.

Christian Borgelt Data Mining / Intelligent Data Analysis 363

k-Nearest Neighbors: Locally Weighted Regression

• Locally weighted regression is usually applied with simple regression polynomials:

◦ most of the time linear,

◦ rarely quadratic,

◦ basically never any higher order.

• The reason is that the local character of the regressionis supposed to take care of the global shape of the function,so that the regression function is not needed to model it.

• The advantage of locally weighted polynomial regression is that no globalregression function, derived from some data generation model, needs to be found.

• This makes the method applicable to a broad range of prediction problems.

• Its disadvantages are that its prediction can be less reliablein sparsely sampled regions of the feature space, wherethe locally employed regression function is stretched to a larger areaand thus may fit the actual target function badly.

Christian Borgelt Data Mining / Intelligent Data Analysis 364

Page 92: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

k-Nearest Neighbors: Implementation

• With such data structures the query timecan be reduced to O(log n) per query data point.

• The time to store the training examples(that is, the time to construct an efficient access structure for them)is, of course, worse than for storing them in a simple list.

• However, with a good data structure and algorithmit is usually acceptably longer.

• For example, a kd-tree is constructed by iterative bisectionsin different dimensions that split the set of data points (roughly) equally.

• As a consequence, constructing it from n training examplestakes O(n log n) time if a linear time algorithmfor finding the median in a dimension is employed.

• Whether such an approach pays off, depends also on the expected numberof query points compared to the number of training data points.

Christian Borgelt Data Mining / Intelligent Data Analysis 365

Feature Weights

• It is crucial for the success of a nearest neighbor approachthat a proper distance function is chosen.

• A very simple and natural way of adapting a distance functionto the needs of the prediction problem is to use distance weights,thus giving certain features a greater influence than others.

• If prior information is available about which features are most informative w.r.t.the target, this information can be incorporated directly into the distance function.

• However, one may also try to determine appropriate feature weights automatically.

• The simplest approach is to start with equal feature weightsand to modify them iteratively in a hill climbing fashion:

◦ apply a (small) random modification to the feature weights,

◦ check with cross validation whether this improves the prediction quality;

◦ if it does, accept the new weights, otherwise keep the old.

◦ Repeat until some termination criterion is met.

Christian Borgelt Data Mining / Intelligent Data Analysis 366

Data Set Reduction and Prototype Building

• A core problem of nearest neighbor approaches is to quickly find the nearest neigh-bors of a given query point.

• This becomes an important practical problem if the training data set is large andpredictions must be computed (very) quickly.

• In such a case one may try to reduce the set of training examples in a preprocessingstep, so that a set of relevant or prototypical data points is found, which yieldsbasically the same prediction quality.

• Note that this set may or may not be a subset of the training examples, dependingon whether the algorithm used to construct this set merely samples from thetraining examples or constructs new data points if necessary.

• Note also that there are usually no or only few actually redundant data points,which can be removed without affecting the prediction at all.

• This is obvious for the numerical case and a 1-nearest neighbor classifier, but alsoholds for a k-nearest neighbor classifier with k > 1, because any removal of datapoints may change the vote at some point and potentially the classification.

Christian Borgelt Data Mining / Intelligent Data Analysis 367

Data Set Reduction and Prototype Building

• A straightforward approach is based on a simple iterative merge scheme:

◦ At the beginning each training example is considered as a prototype.

◦ Then successively two nearest prototypes are mergedas long as the prediction quality on some hold-out test data set is not reduced.

◦ Prototypes can be merged, for example, by simply computing a weighted sum,with the relative weights determined by how many original training examplesa prototype represents.

◦ This is similar to hierarchical agglomerative clustering.

• More sophisticated approaches may employ, for example, genetic algorithms orany other method for solving a combinatorial optimization problem.

• This is possible, because the task of finding prototypes can be viewed as the taskto find a subset of the training examples that yields the best prediction quality(on a given test data set, not the training data set):finding best subsets is a standard combinatorial optimization problem.

Christian Borgelt Data Mining / Intelligent Data Analysis 368

Page 93: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Summary k-Nearest Neighbors

• Predict with Target Values of k Nearest Neighbors

◦ classification: majority vote

◦ numeric prediction: average value

• Special Case of Instance-based Learning

◦ method is easy to understand

◦ intuitive and plausible prediction principle

◦ lazy learning: no model is constructed

• Ingredients of k-Nearest Neighbors

◦ Distance Metric / Feature Weights

◦ Number of Neighbors

◦ Weighting Function for the Neighbors

◦ Prediction Function

Christian Borgelt Data Mining / Intelligent Data Analysis 369

Multi-layer Perceptrons

Christian Borgelt Data Mining / Intelligent Data Analysis 370

Multi-layer Perceptrons

• Biological Background

• Threshold Logic Units

◦ Definition, Geometric Interpretation, Linear Separability

◦ Training Threshold Logic Units, Limitations

◦ Networks of Threshold Logic Units

• Multilayer Perceptrons

◦ Definition of Multilayer Perceptrons

◦ Why Non-linear Activation Functions?

◦ Function Approximation

◦ Training with Gradient Descent

◦ Training Examples and Variants

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 371

Biological Background

Diagram of a typical myelinated vertebrate motoneuron (source: Wikipedia, Ruiz-Villarreal 2007),showing the main parts involved in its signaling activity like the dendrites, the axon, and the synapses.

Christian Borgelt Data Mining / Intelligent Data Analysis 372

Page 94: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Biological Background

Structure of a prototypical biological neuron (simplified)

nucleus

axon

myelin sheath

cell body(soma)

terminal button

synapse

dendrites

Christian Borgelt Data Mining / Intelligent Data Analysis 373

Biological Background

(Very) simplified description of neural information processing

• Axon terminal releases chemicals, called neurotransmitters.

• These act on the membrane of the receptor dendrite to change its polarization.(The inside is usually 70mV more negative than the outside.)

• Decrease in potential difference: excitatory synapseIncrease in potential difference: inhibitory synapse

• If there is enough net excitatory input, the axon is depolarized.

• The resulting action potential travels along the axon.(Speed depends on the degree to which the axon is covered with myelin.)

• When the action potential reaches the terminal buttons,it triggers the release of neurotransmitters.

Christian Borgelt Data Mining / Intelligent Data Analysis 374

(Personal) Computers versus the Human Brain

Personal Computer Human Brain

processing units 1 CPU, 2–10 cores

1010 transistors1–2 graphics cards/GPUs,

103 cores/shaders

1010 transistors 1011 neurons

storage capacity 1010 bytes main memory (RAM) 1011 neurons

1012 bytes external memory 1014 synapses

processing speed 10−9 seconds > 10−3 seconds109 operations per second < 1000 per second

bandwidth 1012 bits/second 1014 bits/second

neural updates 106 per second 1014 per second

Christian Borgelt Data Mining / Intelligent Data Analysis 375

(Personal) Computers versus the Human Brain

• The processing/switching time of a neuron is relatively large (> 10−3 seconds),but updates are computed in parallel.

• A serial simulation on a computer takes several hundred clock cycles per update.

Advantages of Neural Networks:

• High processing speed due to massive parallelism.

• Fault Tolerance:Remain functional even if (larger) parts of a network get damaged.

• “Graceful Degradation”:gradual degradation of performance if an increasing number of neurons fail.

• Well suited for inductive learning(learning from examples, generalization from instances).

It appears to be reasonable to try to mimic or to recreate these advantagesby constructing artificial neural networks.

Christian Borgelt Data Mining / Intelligent Data Analysis 376

Page 95: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Threshold Logic Units

A Threshold Logic Unit (TLU) is a processing unit for numbers with n inputsx1, . . . , xn and one output y. The unit has a threshold θ and each input xi isassociated with a weight wi. A threshold logic unit computes the function

y =

1, ifn∑

i=1

wixi ≥ θ,

0, otherwise.

θ

x1

xn

y

w1

wn

TLUs mimic the thresholding behavior of biological neurons in a (very) simple fashion.

Christian Borgelt Data Mining / Intelligent Data Analysis 377

Threshold Logic Units: Geometric Interpretation

Threshold logic unit for x1 ∧ x2.

4

x1

x2

y

3

2

x1

x2

0 1

0

1

01

Threshold logic unit for x2 → x1.

−1

x1

x2

y

2

−2

x1

x2

0 1

0

10

1

Christian Borgelt Data Mining / Intelligent Data Analysis 378

Threshold Logic Units: Limitations

The biimplication problem x1 ↔ x2: There is no separating line.

x1 x2 y

0 0 11 0 00 1 01 1 1

x1

x2

0 1

0

1

Formal proof by reductio ad absurdum :

since (0, 0) 7→ 1: 0 ≥ θ, (1)since (1, 0) 7→ 0: w1 < θ, (2)since (0, 1) 7→ 0: w2 < θ, (3)since (1, 1) 7→ 1: w1 + w2 ≥ θ. (4)

(2) and (3): w1 + w2 < 2θ. With (4): 2θ > θ, or θ > 0. Contradiction to (1).

Christian Borgelt Data Mining / Intelligent Data Analysis 379

Linear Separability

Definition: Two sets of points in a Euclidean space are called linearly separable,iff there exists at least one point, line, plane or hyperplane (depending on the dimensionof the Euclidean space), such that all points of the one set lie on one side and all pointsof the other set lie on the other side of this point, line, plane or hyperplane (or on it).That is, the point sets can be separated by a linear decision function. Formally:Two sets X, Y ⊂ IRm are linearly separable iff ~w ∈ IRm and θ ∈ IR exist such that

∀~x ∈ X : ~w⊤~x < θ and ∀~y ∈ Y : ~w⊤~y ≥ θ.

• Boolean functions define two points sets, namely the set of points that aremapped to the function value 0 and the set of points that are mapped to 1.⇒ The term “linearly separable” can be transferred to Boolean functions.

• As we have seen, conjunction and implication are linearly separable(as are disjunction, NAND, NOR etc.).

• The biimplication is not linearly separable(and neither is the exclusive or (XOR)).

Christian Borgelt Data Mining / Intelligent Data Analysis 380

Page 96: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Linear Separability

Definition: A set of points in a Euclidean space is called convex if it is non-emptyand connected (that is, if it is a region) and for every pair of points in it every pointon the straight line segment connecting the points of the pair is also in the set.

Definition: The convex hull of a set of points X in a Euclidean space is thesmallest convex set of points that contains X . Alternatively, the convex hull of aset of points X is the intersection of all convex sets that contain X .

Theorem: Two sets of points in a Euclidean space are linearly separableif and only if their convex hulls are disjoint (that is, have no point in common).

• For the biimplication problem, the convex hulls are the diagonal line segments.

• They share their intersection point and are thus not disjoint.

• Therefore the biimplication is not linearly separable.

Christian Borgelt Data Mining / Intelligent Data Analysis 381

Threshold Logic Units: Limitations

Total number and number of linearly separable Boolean functions(On-Line Encyclopedia of Integer Sequences, oeis.org, A001146 and A000609):

inputs Boolean functions linearly separable functions

1 4 42 16 143 256 1044 65,536 1,8825 4,294,967,296 94,5726 18,446,744,073,709,551,616 15,028,134

n 2(2n) no general formula known

• For many inputs a threshold logic unit can compute almost no functions.

• Networks of threshold logic units are needed to overcome the limitations.

Christian Borgelt Data Mining / Intelligent Data Analysis 382

Networks of Threshold Logic Units

Solving the biimplication problem with a network.

Idea: logical decomposition x1 ↔ x2 ≡ (x1 → x2) ∧ (x2 → x1)

−1

−1

3

x1

x2

−2

−2

2

2

2

2

y = x1 ↔ x2

computes y1 = x1 → x2

computes y2 = x2 → x1

computes y = y1 ∧ y2

Christian Borgelt Data Mining / Intelligent Data Analysis 383

Networks of Threshold Logic Units

Solving the biimplication problem: Geometric interpretation

x1

x2

0 1

0

1

a

d c

b

g2

g1

01

01

=⇒

y1

y2

0 1

0

1b

d

acg3

10

• The first layer computes new Boolean coordinates for the points.

• After the coordinate transformation the problem is linearly separable.

Christian Borgelt Data Mining / Intelligent Data Analysis 384

Page 97: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Representing Arbitrary Boolean Functions

Algorithm: Let y = f (x1, . . . , xn) be a Boolean function of n variables.

(i) Represent the given function f (x1, . . . , xn) in disjunctive normal form. That is,determine Df = C1∨ . . .∨Cm, where all Cj are conjunctions of n literals, that is,Cj = lj1 ∧ . . . ∧ ljn with lji = xi (positive literal) or lji = ¬xi (negative literal).

(ii) Create a neuron for each conjunction Cj of the disjunctive normal form(having n inputs — one input for each variable), where

wji =

{+2, if lji = xi,−2, if lji = ¬xi,

and θj = n− 1 +1

2

n∑

i=1

wji.

(iii) Create an output neuron (having m inputs — one input for each neuronthat was created in step (ii)), where

w(n+1)k = 2, k = 1, . . . ,m, and θn+1 = 1.

Remark: weights are set to ±2 instead of ±1 in order to ensure integer thresholds.

Christian Borgelt Data Mining / Intelligent Data Analysis 385

Representing Arbitrary Boolean Functions

Example:ternary Boolean function:

x1 x2 x3 y Cj

0 0 0 01 0 0 1 x1 ∧ x2 ∧ x30 1 0 01 1 0 00 0 1 01 0 1 00 1 1 1 x1 ∧ x2 ∧ x31 1 1 1 x1 ∧ x2 ∧ x3

Df = C1 ∨ C2 ∨ C3

One conjunction for each rowwhere the output y is 1 withliterals according to input values.

First layer (conjunctions):

C1 =x1 ∧ x2 ∧ x3

C2 =x1 ∧ x2 ∧ x3

C3 =x1 ∧ x2 ∧ x3

Second layer (disjunction):

C1

C2C3

Df = C1 ∨ C2 ∨ C3

Christian Borgelt Data Mining / Intelligent Data Analysis 386

Representing Arbitrary Boolean Functions

Example:ternary Boolean function:

x1 x2 x3 y Cj

0 0 0 01 0 0 1 x1 ∧ x2 ∧ x30 1 0 01 1 0 00 0 1 01 0 1 00 1 1 1 x1 ∧ x2 ∧ x31 1 1 1 x1 ∧ x2 ∧ x3

Df = C1 ∨ C2 ∨ C3

One conjunction for each rowwhere the output y is 1 withliterals according to input value.

Resulting network of threshold logic units:

x1

x2

x3

1

3

5

1 y

2

−22

−22

2

−22

2

2

2

2

C1 = x1 ∧ x2 ∧ x3

C2 = x1 ∧ x2 ∧ x3

C3 = x1 ∧ x2 ∧ x3

Df = C1 ∨ C2 ∨ C3

Christian Borgelt Data Mining / Intelligent Data Analysis 387

Training Threshold Logic Units

• Geometric interpretation provides a way to construct threshold logic unitswith 2 and 3 inputs, but:

◦ Not an automatic method (human visualization needed).

◦ Not feasible for more than 3 inputs.

• General idea of automatic training:

◦ Start with random values for weights and threshold.

◦ Determine the error of the output for a set of training patterns.

◦ Error is a function of the weights and the threshold: e = e(w1, . . . , wn, θ).

◦ Adapt weights and threshold so that the error becomes smaller.

◦ Iterate adaptation until the error vanishes.

Christian Borgelt Data Mining / Intelligent Data Analysis 388

Page 98: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Training Threshold Logic Units: Delta Rule

Formal Training Rule: Let ~x = (x1, . . . , xn)⊤ be an input vector of a threshold

logic unit, o the desired output for this input vector and y the actual output of thethreshold logic unit. If y 6= o, then the threshold θ and the weight vector ~w =(w1, . . . , wn)

⊤ are adapted as follows in order to reduce the error:

θ(new) = θ(old) + ∆θ with ∆θ = −η(o− y),∀i ∈ {1, . . . , n} : w

(new)i = w

(old)i + ∆wi with ∆wi = η(o− y)xi,

where η is a parameter that is called learning rate. It determines the severity of theweight changes. This procedure is calledDelta Rule orWidrow–Hoff Procedure[Widrow and Hoff 1960].

• Online Training: Adapt parameters after each training pattern.

• Batch Training: Adapt parameters only at the end of each epoch,that is, after a traversal of all training patterns.

Christian Borgelt Data Mining / Intelligent Data Analysis 389

Training Threshold Logic Units: Convergence

Convergence Theorem: Let L = {(~x1, o1), . . . (~xm, om)} be a set of trainingpatterns, each consisting of an input vector ~xi ∈ IRn and a desired output oi ∈ {0, 1}.Furthermore, let L0 = {(~x, o) ∈ L | o = 0} and L1 = {(~x, o) ∈ L | o = 1}.If L0 and L1 are linearly separable, that is, if ~w ∈ IRn and θ ∈ IR exist such that

∀(~x, 0) ∈ L0 : ~w⊤~x < θ and

∀(~x, 1) ∈ L1 : ~w⊤~x ≥ θ,

then online as well as batch training terminate.

• The algorithms terminate only when the error vanishes.

• Therefore the resulting threshold and weights must solve the problem.

• For not linearly separable problems the algorithms do not terminate(oscillation, repeated computation of same non-solving ~w and θ).

Christian Borgelt Data Mining / Intelligent Data Analysis 390

Training Threshold Logic Units: Delta Rule

Turning the threshold value into a weight:

θ

x1

x2

xn

yw2

wn

w1

n∑

i=1

wixi ≥ θ

0

x1

x2

xn

yw2

wn

x0+1 =−1

w1

w0 = −θ+θ

n∑

i=1

wixi − θ ≥ 0

Christian Borgelt Data Mining / Intelligent Data Analysis 391

Training Threshold Logic Units: Delta Rule

Formal Training Rule (with threshold turned into a weight):Let ~x = (x0 = 1, x1, . . . , xn)

⊤ be an (extended) input vector of a threshold logic unit,o the desired output for this input vector and y the actual output of the thresholdlogic unit. If y 6= o, then the (extended) weight vector ~w = (w0 = −θ, w1, . . . , wn)

⊤is adapted as follows in order to reduce the error:

∀i ∈ {0, . . . , n} : w(new)i = w

(old)i +∆wi with ∆wi = η(o− y)xi,

where η is a parameter that is called learning rate. It determines the severity of theweight changes. This procedure is calledDelta Rule orWidrow–Hoff Procedure[Widrow and Hoff 1960].

• Note that with extended input and weight vectors, there is only one update rule(no distinction of threshold and weights).

• Note also that the (extended) input vector may be ~x = (x0 = −1, x1, . . . , xn)⊤and the corresponding (extended) weight vector ~w = (w0 = +θ, w1, . . . , wn)

⊤.

Christian Borgelt Data Mining / Intelligent Data Analysis 392

Page 99: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Training Networks of Threshold Logic Units

• Single threshold logic units have strong limitations:They can only compute linearly separable functions.

• Networks of threshold logic unitscan compute arbitrary Boolean functions.

• Training single threshold logic units with the delta rule is easy and fastand guaranteed to find a solution if one exists.

• Networks of threshold logic units cannot be trained, because

◦ there are no desired values for the neurons of the first layer(s),

◦ the problem can usually be solved with several different functionscomputed by the neurons of the first layer(s) (non-unique solution).

• When this situation became clear,neural networks were first seen as a “research dead end”.

Christian Borgelt Data Mining / Intelligent Data Analysis 393

General Neural Networks

Basic graph theoretic notions

A (directed) graph is a pair G = (V,E) consisting of a (finite) set V of verticesor nodes and a (finite) set E ⊆ V × V of edges.

We call an edge e = (u, v) ∈ E directed from vertex u to vertex v.

Let G = (V,E) be a (directed) graph and u ∈ V a vertex.Then the vertices of the set

pred(u) = {v ∈ V | (v, u) ∈ E}are called the predecessors of the vertex uand the vertices of the set

succ(u) = {v ∈ V | (u, v) ∈ E}are called the successors of the vertex u.

Christian Borgelt Data Mining / Intelligent Data Analysis 394

General Neural Networks

General definition of a neural network

An (artificial) neural network is a (directed) graph G = (U,C),whose vertices u ∈ U are called neurons or units andwhose edges c ∈ C are called connections.

The set U of vertices is partitioned into

• the set Uin of input neurons,

• the set Uout of output neurons, and

• the set Uhidden of hidden neurons.

It isU = Uin ∪ Uout ∪ Uhidden,

Uin 6= ∅, Uout 6= ∅, Uhidden ∩ (Uin ∪ Uout) = ∅.

Christian Borgelt Data Mining / Intelligent Data Analysis 395

General Neural Networks

Each connection (v, u) ∈ C possesses a weight wuv andeach neuron u ∈ U possesses three (real-valued) state variables:

• the network input netu,

• the activation actu, and

• the output outu.

Each input neuron u ∈ Uin also possesses a fourth (real-valued) state variable,

• the external input extu.

Furthermore, each neuron u ∈ U possesses three functions:

• the network input function f(u)net : IR2| pred(u)|+κ1(u) → IR,

• the activation function f(u)act : IRκ2(u) → IR, and

• the output function f(u)out : IR→ IR,

which are used to compute the values of the state variables.

Christian Borgelt Data Mining / Intelligent Data Analysis 396

Page 100: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Structure of a Generalized Neuron

A generalized neuron is a simple numeric processor

uoutv1 = inuv1wuv1

outvn = inuvnwuvn

f(u)net netu

f(u)act actu

f(u)out outu

extu

σ1, . . . , σl θ1, . . . , θk

Christian Borgelt Data Mining / Intelligent Data Analysis 397

General Neural Networks

Types of (artificial) neural networks:

• If the graph of a neural network is acyclic,it is called a feed-forward network.

• If the graph of a neural network contains cycles (backward connections),it is called a recurrent network.

Representation of the connection weights as a matrix:

u1 u2 . . . ur

wu1u1 wu1u2 . . . wu1urwu2u1 wu2u2 wu2ur

... ...wuru1 wuru2 . . . wurur

u1u2...ur

Christian Borgelt Data Mining / Intelligent Data Analysis 398

Multi-layer Perceptrons

An r-layer perceptron is a neural network with a graph G = (U,C)that satisfies the following conditions:

(i) Uin ∩ Uout = ∅,

(ii) Uhidden = U(1)hidden ∪ · · · ∪ U

(r−2)hidden,

∀1 ≤ i < j ≤ r − 2 : U(i)hidden ∩ U

(j)hidden = ∅,

(iii) C ⊆(Uin × U (1)

hidden

)∪(⋃r−3

i=1 U(i)hidden × U

(i+1)hidden

)∪(U(r−2)hidden × Uout

)

or, if there are no hidden neurons (r = 2, Uhidden = ∅),C ⊆ Uin × Uout.

• Feed-forward network with strictly layered structure.

Christian Borgelt Data Mining / Intelligent Data Analysis 399

Multi-layer Perceptrons

General structure of a multi-layer perceptron

xn

x2

x1

ym

y2

y1

Uin U(1)hidden U

(2)hidden U

(r−2)hidden

Uout

Christian Borgelt Data Mining / Intelligent Data Analysis 400

Page 101: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Multi-layer Perceptrons

• The network input function of each hidden neuron and of each output neuron isthe weighted sum of its inputs, that is,

∀u ∈ Uhidden ∪ Uout : f(u)net (~wu,

~inu) = ~w⊤u ~inu =∑

v∈pred (u)wuv outv .

• The activation function of each hidden neuron is a so-calledsigmoid function, that is, a monotonically increasing function

f : IR→ [0, 1] with limx→−∞ f (x) = 0 and lim

x→∞ f (x) = 1.

• The activation function of each output neuron is either also a sigmoid function ora linear function, that is,

fact(net, θ) = α net−θ.

Only the step function is a neurobiologically plausible activation function.

Christian Borgelt Data Mining / Intelligent Data Analysis 401

Sigmoid Activation Functions

step function:

fact(net, θ) =

{1, if net ≥ θ,0, otherwise.

net0

12

1

θ

semi-linear function:

fact(net, θ) =

{1, if net > θ + 1

2 ,

0, if net < θ − 12 ,

(net−θ) + 12 , otherwise.

net0

12

1

θθ − 12

θ + 12

sine until saturation:

fact(net, θ) =

1, if net > θ + π2 ,

0, if net < θ − π2 ,

sin(net−θ)+12 , otherwise.

net0

12

1

θθ − π2

θ + π2

logistic function:

fact(net, θ) =1

1 + e−(net−θ)

net0

12

1

θθ − 4 θ − 2 θ + 2 θ + 4

Christian Borgelt Data Mining / Intelligent Data Analysis 402

Sigmoid Activation Functions

• All sigmoid functions on the previous slide are unipolar,that is, they range from 0 to 1.

• Sometimes bipolar sigmoid functions are used (ranging from −1 to +1),like the hyperbolic tangent (tangens hyperbolicus).

hyperbolic tangent:

fact(net, θ) = tanh(net−θ)

=e(net−θ) − e−(net−θ)e(net−θ) + e−(net−θ)

=1− e−2(net−θ)1 + e−2(net−θ)

=2

1 + e−2(net−θ)− 1

net

1

0

−1

θθ − 2 θ − 1 θ + 1 θ + 2

Christian Borgelt Data Mining / Intelligent Data Analysis 403

Multi-layer Perceptrons: Weight Matrices

Let U1 = {v1, . . . , vm} and U2 = {u1, . . . , un} be the neurons of two consecutivelayers of a multi-layer perceptron.

Their connection weights are represented by an n×m matrix

W =

wu1v1 wu1v2 . . . wu1vmwu2v1 wu2v2 . . . wu2vm... ... ...wunv1 wunv2 . . . wunvm

,

where wuivj = 0 if there is no connection from neuron vj to neuron ui.

Advantage: The computation of the network input can be written as

~netU2 = W · ~inU2 = W · ~outU1where ~netU2 = (netu1, . . . , netun)

⊤ and ~inU2 =~outU1 = (outv1, . . . , outvm)

⊤.

Christian Borgelt Data Mining / Intelligent Data Analysis 404

Page 102: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Why Non-linear Activation Functions?

With weight matrices we have for two consecutive layers U1 and U2

~netU2 = W · ~inU2 = W · ~outU1.If the activation functions are linear, that is,

fact(net, θ) = α net−θ.the activations of the neurons in the layer U2 can be computed as

~actU2 = Dact · ~netU2 − ~θ,where

• ~actU2 = (actu1, . . . , actun)⊤ is the activation vector,

• Dact is an n× n diagonal matrix of the factors αui, i = 1, . . . , n, and

• ~θ = (θu1, . . . , θun)⊤ is a bias vector.

Christian Borgelt Data Mining / Intelligent Data Analysis 405

Why Non-linear Activation Functions?

If the output function is also linear, it is analogously

~outU2 = Dout · ~actU2 − ~ξ,where

• ~outU2 = (outu1, . . . , outun)⊤ is the output vector,

• Dout is again an n× n diagonal matrix of factors, and

• ~ξ = (ξu1, . . . , ξun)⊤ a bias vector.

Combining these computations we get

~outU2 = Dout ·(Dact ·

(W · ~outU1

)− ~θ

)− ~ξ

and thus~outU2 = A12 · ~outU1 +~b12

with an n×m matrix A12 and an n-dimensional vector ~b12.

Christian Borgelt Data Mining / Intelligent Data Analysis 406

Why Non-linear Activation Functions?

Therefore we have

~outU2 = A12 · ~outU1 +~b12and

~outU3 = A23 · ~outU2 +~b23for the computations of two consecutive layers U2 and U3.

These two computations can be combined into

~outU3 = A13 · ~outU1 +~b13,

where A13 = A23 ·A12 and ~b13 = A23 ·~b12 +~b23.

Result: With linear activation and output functions any multi-layer perceptroncan be reduced to a two-layer perceptron.

Christian Borgelt Data Mining / Intelligent Data Analysis 407

Multi-layer Perceptrons: Function Approximation

• Up to now: representing and learning Boolean functions f : {0, 1}n → {0, 1}.• Now: representing and learning real-valued functions f : IRn → IR.

General idea of function approximation:

• Approximate a given function by a step function.

• Construct a neural network that computes the step function.

x

y

x1 x2 x3 x4

y0

y1

y2

y3y4

Christian Borgelt Data Mining / Intelligent Data Analysis 408

Page 103: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Multi-layer Perceptrons: Function Approximation

x y

x1

x2

x3

x4

1

1

1

id

1

1

1

1

−2

2

−2

2

−2

2

y3

y2

y1

A neural network that computes the step function shown on the preceding slide.According to the input value only one step is active at any time.The output neuron has the identity as its activation and output functions.

Christian Borgelt Data Mining / Intelligent Data Analysis 409

Multi-layer Perceptrons: Function Approximation

Theorem: Any Riemann-integrable function can be approximatedwith arbitrary accuracy by a four-layer perceptron.

• But: Error is measured as the area between the functions.

• More sophisticated mathematical examination allows a stronger assertion:With a three-layer perceptron any continuous function can be approximatedwith arbitrary accuracy (error: maximum function value difference).

Christian Borgelt Data Mining / Intelligent Data Analysis 410

Multi-layer Perceptrons as Universal Approximators

Universal Approximation Theorem [Hornik 1991]:

Let ϕ(·) be a continuous, bounded and nonconstant function,let X denote an arbitrary compact subset of IRm, andlet C(X) denote the space of continuous functions on X .

Given any function f ∈ C(X) and ε > 0, there exists an integer N , real constantsvi, θi ∈ IR and real vectors ~wi ∈ IRm, i = 1, . . . , N , such that we may define

F (~x) =N∑

i=1

vi ϕ(~w⊤i ~x− θi

)

as an approximate realization of the function f where f is independent of ϕ. That is,

|F (~x)− f (~x)| < ε

for all ~x ∈ X . In other words, functions of the form F (~x) are dense in C(X).

Note that it is not the shape of the activation function, but the layered structure ofthe feedforward network that renders multi-layer perceptrons universal approximators.

Christian Borgelt Data Mining / Intelligent Data Analysis 411

Multi-layer Perceptrons: Function Approximation

x

y

x1 x2 x3 x4

y0

y1

y2

y3y4

x

y

x1 x2 x3 x4

∆y1

∆y2

∆y3

∆y4

10

10

10

10 ·∆y4

·∆y3

·∆y2

·∆y1

By using relative step heightsone layer can be saved.

Christian Borgelt Data Mining / Intelligent Data Analysis 412

Page 104: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Multi-layer Perceptrons: Function Approximation

x y

x1

x2

x3

x4

id

1

1

1

1

∆y4

∆y3

∆y2

∆y1

A neural network that computes the step function shown on the preceding slide.The output neuron has the identity as its activation and output functions.

Christian Borgelt Data Mining / Intelligent Data Analysis 413

Multi-layer Perceptrons: Function Approximation

x

y

x1 x2 x3 x4

y0

y1

y2

y3y4

x

y

x1 x2 x3 x4

∆y1

∆y2

∆y3

∆y4

10

10

10

10 ·∆y4

·∆y3

·∆y2

·∆y1

By using semi-linear functions theapproximation can be improved.

Christian Borgelt Data Mining / Intelligent Data Analysis 414

Multi-layer Perceptrons: Function Approximation

x y

θ1

θ2

θ3

θ4

id

1∆x

1∆x

1∆x

1∆x

∆y4

∆y3

∆y2

∆y1

θi =xi∆x

∆x = xi+1 − xi

A neural network that computes the step function shown on the preceding slide.The output neuron has the identity as its activation and output functions.

Christian Borgelt Data Mining / Intelligent Data Analysis 415

Training Multi-layer Perceptrons: Gradient Descent

• Problem of logistic regression: Works only for two-layer perceptrons.

• More general approach: gradient descent.

• Necessary condition: differentiable activation and output functions.

x

y

z

x0

y0∂z∂x

|~p∂z∂y

|~p

~∇z|~p=(x0,y0)

Illustration of the gradient of a real-valued function z = f (x, y) at a point (x0, y0).

It is ~∇z|(x0,y0) =(∂z∂x|x0, ∂z∂y |y0

). (~∇ is a differential operator called “nabla” or “del”.)

Christian Borgelt Data Mining / Intelligent Data Analysis 416

Page 105: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Gradient Descent: Formal Approach

General Idea: Approach the minimum of the error function in small steps.

Error function:

e =∑

l∈Lfixede(l) =

v∈Uoutev =

l∈Lfixed

v∈Uoute(l)v ,

Form gradient to determine the direction of the step(here and in the following: extended weight vector ~wu = (−θu, wup1, . . . , wupn)):

~∇~wue =∂e

∂ ~wu=

(− ∂e

∂θu,∂e

∂wup1, . . . ,

∂e

∂wupn

).

Exploit the sum over the training patterns:

~∇~wue =∂e

∂ ~wu=

∂ ~wu

l∈Lfixede(l) =

l∈Lfixed

∂e(l)

∂ ~wu.

Christian Borgelt Data Mining / Intelligent Data Analysis 417

Gradient Descent: Formal Approach

Single pattern error depends on weights only through the network input:

~∇~wue(l) =

∂e(l)

∂ ~wu=

∂e(l)

∂ net(l)u

∂ net(l)u

∂ ~wu.

Since net(l)u = ~w⊤u ~in

(l)u (note: extended input vector ~in

(l)u =

(1, in

(l)p1u, . . . , in

(l)pnu

)),

we have for the second factor

∂ net(l)u

∂ ~wu= ~in

(l)u .

For the first factor we consider the error e(l) for the training pattern l = (~ı (l), ~o (l)):

e(l) =∑

v∈Uoute(l)u =

v∈Uout

(o(l)v − out

(l)v

)2,

that is, the sum of the errors over all output neurons.

Christian Borgelt Data Mining / Intelligent Data Analysis 418

Gradient Descent: Formal Approach

Therefore we have

∂e(l)

∂ net(l)u

=∂∑v∈Uout

(o(l)v − out

(l)v

)2

∂ net(l)u

=∑

v∈Uout

∂(o(l)v − out

(l)v

)2

∂ net(l)u

.

Since only the actual output out(l)v of an output neuron v depends on the network

input net(l)u of the neuron u we are considering, it is

∂e(l)

∂ net(l)u

= −2∑

v∈Uout

(o(l)v − out

(l)v

)∂ out

(l)v

∂ net(l)u︸ ︷︷ ︸

δ(l)u

,

which also introduces the abbreviation δ(l)u for the important sum appearing here.

Christian Borgelt Data Mining / Intelligent Data Analysis 419

Gradient Descent: Formal Approach

Distinguish two cases: • The neuron u is an output neuron.

• The neuron u is a hidden neuron.

In the first case we have

∀u ∈ Uout : δ(l)u =

(o(l)u − out

(l)u

)∂ out

(l)u

∂ net(l)u

Therefore we have for the gradient

∀u ∈ Uout : ~∇~wue(l)u =

∂e(l)u

∂ ~wu= −2

(o(l)u − out

(l)u

)∂ out

(l)u

∂ net(l)u

~in(l)u

and thus for the weight change

∀u ∈ Uout : ∆~w(l)u = −η

2~∇~wue

(l)u = η

(o(l)u − out

(l)u

)∂ out

(l)u

∂ net(l)u

~in(l)u .

Christian Borgelt Data Mining / Intelligent Data Analysis 420

Page 106: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Gradient Descent: Formal Approach

Exact formulae depend on the choice of the activation and the output function,since it is

out(l)u = fout( act

(l)u ) = fout(fact( net

(l)u )).

Consider the special case with

• output function is the identity,

• activation function is logistic, that is, fact(x) =1

1+e−x .

The first assumption yields

∂ out(l)u

∂ net(l)u

=∂ act

(l)u

∂ net(l)u

= f ′act( net(l)u ).

Christian Borgelt Data Mining / Intelligent Data Analysis 421

Gradient Descent: Formal Approach

For a logistic activation function we have

f ′act(x) =d

dx

(1 + e−x

)−1= −

(1 + e−x

)−2 (−e−x)

=1 + e−x − 1

(1 + e−x)2=

1

1 + e−x(1− 1

1 + e−x)

= fact(x) · (1− fact(x)),and therefore

f ′act( net(l)u ) = fact( net

(l)u ) ·

(1− fact( net(l)u )

)= out

(l)u

(1− out

(l)u

).

The resulting weight change is therefore

∆~w(l)u = η

(o(l)u − out

(l)u

)out

(l)u

(1− out

(l)u

)~in(l)u ,

which makes the computations very simple.

Christian Borgelt Data Mining / Intelligent Data Analysis 422

Gradient Descent: Formal Approach

logistic activation function:

fact(net(l)u ) =

1

1 + e− net(l)u

net0

12

1

0−4 −2 +2 +4

derivative of logistic function:

f ′act(net(l)u ) = fact(net

(l)u ) · (1− fact(net(l)u ))

net0

12

1

0

14

−4 −2 +2 +4

• If a logistic activation function is used (shown on left), the weight changes are

proportional to λ(l)u = out

(l)u

(1− out

(l)u

)(shown on right; see preceding slide).

• Weight changes are largest, and thus the training speed highest, in the vicinity

of net(l)u = 0. Far away from net

(l)u = 0, the gradient becomes (very) small

(“saturation regions”) and thus training (very) slow.

Christian Borgelt Data Mining / Intelligent Data Analysis 423

Reminder: Two-dimensional Logistic Function

Example logistic function for two arguments x1 and x2:

y =1

1 + exp(4− x1 − x2)=

1

1 + exp(4− (1, 1)⊤(x1, x2)

)

01

23

4

01

23

4

0

1

x1

x2

y

x1

x2

0

1

2

3

4

0 1 2 3 4

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

The blue lines show where the logistic function has a certain value in {0.1, . . . , 0.9}.

Christian Borgelt Data Mining / Intelligent Data Analysis 424

Page 107: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Error Backpropagation

Consider now: The neuron u is a hidden neuron, that is, u ∈ Uk, 0 < k < r − 1.

The output out(l)v of an output neuron v depends on the network input net

(l)u

only indirectly through the successor neurons succ(u) = {s ∈ U | (u, s) ∈ C}= {s1, . . . , sm} ⊆ Uk+1, namely through their network inputs net

(l)s .

We apply the chain rule to obtain

δ(l)u =

v∈Uout

s∈succ(u)(o(l)v − out

(l)v )

∂ out(l)v

∂ net(l)s

∂ net(l)s

∂ net(l)u

.

Exchanging the sums yields

δ(l)u =

s∈succ(u)

v∈Uout(o(l)v − out

(l)v )

∂ out(l)v

∂ net(l)s

∂ net

(l)s

∂ net(l)u

=∑

s∈succ(u)δ(l)s

∂ net(l)s

∂ net(l)u

.

Christian Borgelt Data Mining / Intelligent Data Analysis 425

Error Backpropagation

Consider the network input

net(l)s = ~w⊤s ~in

(l)s =

p∈pred(s)wsp out

(l)p

− θs,

where one element of ~in(l)s is the output out

(l)u of the neuron u. Therefore it is

∂ net(l)s

∂ net(l)u

=

p∈pred(s)wsp

∂ out(l)p

∂ net(l)u

− ∂θs

∂ net(l)u

= wsu∂ out

(l)u

∂ net(l)u

,

The result is the recursive equation (error backpropagation)

δ(l)u =

s∈succ(u)δ(l)s wsu

∂ out

(l)u

∂ net(l)u

.

Christian Borgelt Data Mining / Intelligent Data Analysis 426

Error Backpropagation

The resulting formula for the weight change is

∆~w(l)u = −η

2~∇~wue

(l) = η δ(l)u ~in

(l)u = η

s∈succ(u)δ(l)s wsu

∂ out

(l)u

∂ net(l)u

~in(l)u .

Consider again the special case with

• output function is the identity,

• activation function is logistic.

The resulting formula for the weight change is then

∆~w(l)u = η

s∈succ(u)δ(l)s wsu

out

(l)u (1− out

(l)u ) ~in

(l)u .

Christian Borgelt Data Mining / Intelligent Data Analysis 427

Error Backpropagation: Cookbook Recipe

∀u ∈ Uin :out

(l)u = ext

(l)u

forwardpropagation:

∀u ∈ Uhidden ∪ Uout :out

(l)u =

(1 + exp

(−∑p∈pred(u)wup out

(l)p

))−1

• logisticactivationfunction

• implicitbias value

xn

x2

x1

ym

y2

y1

∀u ∈ Uhidden :δ(l)u =

(∑s∈succ(u) δ

(l)s wsu

)λ(l)u

backwardpropagation:

∀u ∈ Uout :δ(l)u =

(o(l)u − out

(l)u

)λ(l)u

error factor:

λ(l)u = out

(l)u

(1− out

(l)u

)activationderivative:

weightchange:

∆w(l)up = η δ

(l)u out

(l)p

Christian Borgelt Data Mining / Intelligent Data Analysis 428

Page 108: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Gradient Descent: Examples

Gradient descent training for the negation ¬x

θx w yx y

0 11 0

error for x = 0

–4 –2 0 2 4

–4–2

02

4 1

21

2

θ

w

e

error for x = 1

–4 –2 0 2 4

–4–2

02

4 1

21

2

θ

w

e

sum of errors

–4 –2 0 2 4

–4–2

02

4 1

21

2

θ

w

e

Note: error for x = 0 and x = 1 is effectively the squared logistic activation function!

Christian Borgelt Data Mining / Intelligent Data Analysis 429

Gradient Descent: Examples

epoch θ w error

0 3.00 3.50 1.30720 3.77 2.19 0.98640 3.71 1.81 0.97060 3.50 1.53 0.95880 3.15 1.24 0.937100 2.57 0.88 0.890120 1.48 0.25 0.725140 −0.06 −0.98 0.331160 −0.80 −2.07 0.149180 −1.19 −2.74 0.087200 −1.44 −3.20 0.059220 −1.62 −3.54 0.044

Online Training

epoch θ w error

0 3.00 3.50 1.29520 3.76 2.20 0.98540 3.70 1.82 0.97060 3.48 1.53 0.95780 3.11 1.25 0.934100 2.49 0.88 0.880120 1.27 0.22 0.676140 −0.21 −1.04 0.292160 −0.86 −2.08 0.140180 −1.21 −2.74 0.084200 −1.45 −3.19 0.058220 −1.63 −3.53 0.044

Batch Training

Christian Borgelt Data Mining / Intelligent Data Analysis 430

Gradient Descent: Examples

Visualization of gradient descent for the negation ¬x

Online Trainingθ

w

−4 −2 0 2 4−4

−2

0

2

4

Batch Trainingθ

w

−4 −2 0 2 4−4

−2

0

2

4

Batch Training

–4 –2 0 2 4

–4–2

02

4 1

21

2

θ

w

e

• Training is obviously successful.

• Error cannot vanish completely due to the properties of the logistic function.

Christian Borgelt Data Mining / Intelligent Data Analysis 431

Gradient Descent: Examples

Example function: f (x) =5

6x4 − 7x3 +

115

6x2 − 18x + 6,

i xi f (xi) f ′(xi) ∆xi

0 0.200 3.112 −11.147 0.0111 0.211 2.990 −10.811 0.0112 0.222 2.874 −10.490 0.0103 0.232 2.766 −10.182 0.0104 0.243 2.664 −9.888 0.0105 0.253 2.568 −9.606 0.0106 0.262 2.477 −9.335 0.0097 0.271 2.391 −9.075 0.0098 0.281 2.309 −8.825 0.0099 0.289 2.233 −8.585 0.00910 0.298 2.160

x0

1

2

3

4

5

6

0 1 2 3 4

Gradient descent with initial value 0.2 and learning rate 0.001.

Christian Borgelt Data Mining / Intelligent Data Analysis 432

Page 109: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Gradient Descent: Examples

Example function: f (x) =5

6x4 − 7x3 +

115

6x2 − 18x + 6,

i xi f (xi) f ′(xi) ∆xi

0 1.500 2.719 3.500 −0.8751 0.625 0.655 −1.431 0.3582 0.983 0.955 2.554 −0.6393 0.344 1.801 −7.157 1.7894 2.134 4.127 0.567 −0.1425 1.992 3.989 1.380 −0.3456 1.647 3.203 3.063 −0.7667 0.881 0.734 1.753 −0.4388 0.443 1.211 −4.851 1.2139 1.656 3.231 3.029 −0.75710 0.898 0.766

x0

1

2

3

4

5

6

0 1 2 3 4

starting point

Gradient descent with initial value 1.5 and learning rate 0.25.

Christian Borgelt Data Mining / Intelligent Data Analysis 433

Gradient Descent: Examples

Example function: f (x) =5

6x4 − 7x3 +

115

6x2 − 18x + 6,

i xi f (xi) f ′(xi) ∆xi

0 2.600 3.816 −1.707 0.0851 2.685 3.660 −1.947 0.0972 2.783 3.461 −2.116 0.1063 2.888 3.233 −2.153 0.1084 2.996 3.008 −2.009 0.1005 3.097 2.820 −1.688 0.0846 3.181 2.695 −1.263 0.0637 3.244 2.628 −0.845 0.0428 3.286 2.599 −0.515 0.0269 3.312 2.589 −0.293 0.01510 3.327 2.585

x0

1

2

3

4

5

6

0 1 2 3 4

Gradient descent with initial value 2.6 and learning rate 0.05.

Christian Borgelt Data Mining / Intelligent Data Analysis 434

Gradient Descent: Variants

Weight update rule:

w(t + 1) = w(t) + ∆w(t)

Standard backpropagation:

∆w(t) = −η2∇we(t)

Manhattan training:

∆w(t) = −η sgn(∇we(t)).

Fixed step width (grid), only sign of gradient (direction) is evaluated.

Momentum term:

∆w(t) = −η2∇we(t) + β ∆w(t− 1),

Part of previous change is added, may lead to accelerated training (β ∈ [0.5, 0.95]).

Christian Borgelt Data Mining / Intelligent Data Analysis 435

Gradient Descent: Variants

Self-adaptive error backpropagation:

ηw(t) =

c− · ηw(t− 1), if ∇we(t) · ∇we(t− 1) < 0,c+ · ηw(t− 1), if ∇we(t) · ∇we(t− 1) > 0

∧ ∇we(t− 1) · ∇we(t− 2) ≥ 0,ηw(t− 1), otherwise.

Resilient error backpropagation:

∆w(t) =

c− ·∆w(t− 1), if ∇we(t) · ∇we(t− 1) < 0,c+ ·∆w(t− 1), if ∇we(t) · ∇we(t− 1) > 0

∧ ∇we(t− 1) · ∇we(t− 2) ≥ 0,∆w(t− 1), otherwise.

Typical values: c− ∈ [0.5, 0.7] and c+ ∈ [1.05, 1.2].

Christian Borgelt Data Mining / Intelligent Data Analysis 436

Page 110: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Gradient Descent: Variants

Quickpropagation e

w

w(t+1) w(t) w(t−1)m

e(t)

e(t−1)

apex

w

∇we

w(t+1) w(t) w(t−1)

∇we(t)

∇we(t−1)

0The weight update rule can bederived from the triangles:

∆w(t) =∇we(t)

∇we(t− 1)−∇we(t)·∆w(t− 1).

Christian Borgelt Data Mining / Intelligent Data Analysis 437

Gradient Descent: Examples

epoch θ w error

0 3.00 3.50 1.29520 3.76 2.20 0.98540 3.70 1.82 0.97060 3.48 1.53 0.95780 3.11 1.25 0.934100 2.49 0.88 0.880120 1.27 0.22 0.676140 −0.21 −1.04 0.292160 −0.86 −2.08 0.140180 −1.21 −2.74 0.084200 −1.45 −3.19 0.058220 −1.63 −3.53 0.044

without momentum term

epoch θ w error

0 3.00 3.50 1.29510 3.80 2.19 0.98420 3.75 1.84 0.97130 3.56 1.58 0.96040 3.26 1.33 0.94350 2.79 1.04 0.91060 1.99 0.60 0.81470 0.54 −0.25 0.49780 −0.53 −1.51 0.21190 −1.02 −2.36 0.113100 −1.31 −2.92 0.073110 −1.52 −3.31 0.053120 −1.67 −3.61 0.041

with momentum term (β = 0.9)

Christian Borgelt Data Mining / Intelligent Data Analysis 438

Gradient Descent: Examples

without momentum termθ

w

−4 −2 0 2 4−4

−2

0

2

4

with momentum termθ

w

−4 −2 0 2 4−4

−2

0

2

4

with momentum term

–4 –2 0 2 4

–4–2

02

4 1

21

2

θ

w

e

• Dots show position every 20 (without momentum term)or every 10 epochs (with momentum term).

• Learning with a momentum term (β = 0.9) is about twice as fast.

Christian Borgelt Data Mining / Intelligent Data Analysis 439

Gradient Descent: Examples

Example function: f (x) =5

6x4 − 7x3 +

115

6x2 − 18x + 6,

i xi f (xi) f ′(xi) ∆xi

0 0.200 3.112 −11.147 0.0111 0.211 2.990 −10.811 0.0212 0.232 2.771 −10.196 0.0293 0.261 2.488 −9.368 0.0354 0.296 2.173 −8.397 0.0405 0.337 1.856 −7.348 0.0446 0.380 1.559 −6.277 0.0467 0.426 1.298 −5.228 0.0468 0.472 1.079 −4.235 0.0469 0.518 0.907 −3.319 0.04510 0.562 0.777

x0

1

2

3

4

5

6

0 1 2 3 4

Gradient descent with initial value 0.2, learning rate 0.001and momentum term β = 0.9.

Christian Borgelt Data Mining / Intelligent Data Analysis 440

Page 111: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Gradient Descent: Examples

Example function: f (x) =5

6x4 − 7x3 +

115

6x2 − 18x + 6,

i xi f (xi) f ′(xi) ∆xi

0 1.500 2.719 3.500 −1.0501 0.450 1.178 −4.699 0.7052 1.155 1.476 3.396 −0.5093 0.645 0.629 −1.110 0.0834 0.729 0.587 0.072 −0.0055 0.723 0.587 0.001 0.0006 0.723 0.587 0.000 0.0007 0.723 0.587 0.000 0.0008 0.723 0.587 0.000 0.0009 0.723 0.587 0.000 0.00010 0.723 0.587

x0

1

2

3

4

5

6

0 1 2 3 4

Gradient descent with initial value 1.5, inital learning rate 0.25,and self-adapting learning rate (c+ = 1.2, c− = 0.5).

Christian Borgelt Data Mining / Intelligent Data Analysis 441

Other Extensions of Error Backpropagation

Flat Spot Elimination:

∆w(t) = −η2∇we(t) + ζ

• Eliminates slow learning in saturation region of logistic function (ζ ≈ 0.1).

• Counteracts the decay of the error signals over the layers.

Weight Decay:

∆w(t) = −η2∇we(t)− ξ w(t),

• Helps to improve the robustness of the training results (ξ ≤ 10−3).• Can be derived from an extended error function penalizing large weights:

e∗ = e +ξ

2

u∈Uout∪Uhidden

(θ2u +

p∈pred(u)w2up

).

Christian Borgelt Data Mining / Intelligent Data Analysis 442

Number of Hidden Neurons

• Note that the approximation theorem only states that there existsa number of hidden neurons and weight vectors ~v and ~wi and thresholds θi,but not how they are to be chosen for a given ε of approximation accuracy.

• For a single hidden layer the following rule of thumb is popular:

number of hidden neurons = (number of inputs + number of outputs) / 2

• Better, though computationally expensive approach:

◦ Randomly split the given data into two subsets of (about) equal size,the training data and the validation data.

◦ Train multi-layer perceptrons with different numbers of hidden neuronson the training data and evaluate them on the validation data.

◦ Repeat the random split of the data and training/evaluation many timesand average the results over the same number of hidden neurons.Choose the number of hidden neurons with the best average error.

◦ Train a final multi-layer perceptron on the whole data set.

Christian Borgelt Data Mining / Intelligent Data Analysis 443

Number of Hidden Neurons

Principle of training data/validation data approach:

• Underfitting: If the number of neurons in the hidden layer is too small, themulti-layer perceptron may not be able to capture the structure of the relationshipbetween inputs and outputs precisely enough due to a lack of parameters.

• Overfitting: With a larger number of hidden neurons a multi-layer perceptronmay adapt not only to the regular dependence between inputs and outputs, butalso to the accidental specifics (errors and deviations) of the training data set.

• Overfitting will usually lead to the effect that the error a multi-layer perceptronyields on the validation data will be (possibly considerably) greater than the errorit yields on the training data.

The reason is that the validation data set is likely distorted in a different fashionthan the training data, since the errors and deviations are random.

• Minimizing the error on the validation data by properly choosing the number ofhidden neurons prevents both under- and overfitting.

Christian Borgelt Data Mining / Intelligent Data Analysis 444

Page 112: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Number of Hidden Neurons: Avoid Overfitting

• Objective: select the model that best fits the data,taking the model complexity into account.

The more complex the model, the better it usually fits the data.

x

y

0 1 2 3 4 5 6 7 80

1

2

3

4

5

6

7 black line:regression line(2 free parameters)

blue curve:7th order regression polynomial(8 free parameters)

• The blue curve fits the data points perfectly, but it is not a good model.

Christian Borgelt Data Mining / Intelligent Data Analysis 445

Number of Hidden Neurons: Cross Validation

• The described method of iteratively splitting the data into training and validationdata may be referred to as cross validation.

• However, this term is more often used for the following specific procedure:

◦ The given data set is split into n parts or subsets (also called folds)of about equal size (so-called n-fold cross validation).

◦ If the output is nominal (also sometimes called symbolic or categorical), thissplit is done in such a way that the relative frequency of the output values inthe subsets/folds represent as well as possible the relative frequencies of thesevalues in the data set as a whole. This is also called stratification (derivedfrom the Latin stratum : layer, level, tier).

◦ Out of these n data subsets (or folds) n pairs of training and validation dataset are formed by using one fold as a validation data set while the remainingn− 1 folds are combined into a training data set.

Christian Borgelt Data Mining / Intelligent Data Analysis 446

Number of Hidden Neurons: Cross Validation

• The advantage of the cross validation method is that one random split of the datayields n different pairs of training and validation data set.

• An obvious disadvantage is that (except for n = 2) the size of the training and thetest data set are considerably different, which makes the results on the validationdata statistically less reliable.

• It is therefore only recommended for sufficiently large data sets or sufficientlysmall n, so that the validation data sets are of sufficient size.

• Repeating the split (either with n = 2 or greater n) has the advantage that oneobtains many more training and validation data sets, leading to more reliablestatistics (here: for the number of hidden neurons).

• The described approaches fall into the category of resampling methods.

• Other well-known statistical resampling methods are bootstrap, jackknife,subsampling and permutation test.

Christian Borgelt Data Mining / Intelligent Data Analysis 447

Avoiding Overfitting: Alternatives

• An alternative way to prevent overfitting is the following approach:

◦ During training the performance of the multi-layer perceptron is evaluatedafter each epoch (or every few epochs) on a validation data set.

◦ While the error on the training data set should always decrease with eachepoch, the error on the validation data set should, after decreasing initially aswell, increase again as soon as overfitting sets in.

◦ At this moment training is terminated and either the current state or (if avail-able) the state of the multi-layer perceptron, for which the error on the vali-dation data reached a minimum, is reported as the training result.

• Furthermore a stopping criterion may be derived from the shape of the error curveon the training data over the training epochs, or the network is trained only for afixed, relatively small number of epochs (also known as early stopping).

• Disadvantage: these methods stop the training of a complex network early enough,rather than adjust the complexity of the network to the “correct” level.

Christian Borgelt Data Mining / Intelligent Data Analysis 448

Page 113: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Multi-layer Perceptrons

• Biological Background

• Threshold Logic Units

◦ Definition, Geometric Interpretation, Linear Separability

◦ Training Threshold Logic Units, Limitations

◦ Networks of Threshold Logic Units

• Multilayer Perceptrons

◦ Definition of Multilayer Perceptrons

◦ Why Non-linear Activation Functions?

◦ Function Approximation

◦ Training with Gradient Descent

◦ Training Examples and Variants

• Core Idea: Mimic Biological Neural Networks

Christian Borgelt Data Mining / Intelligent Data Analysis 449

Ensemble Methods

Christian Borgelt Data Mining / Intelligent Data Analysis 450

Ensemble Methods

• Fundamental Ideas

◦ Combine Multiple Classifiers/Predictors

◦ Why Do Ensemble Methods Work?

• Some Popular Ensemble Methods

◦ Bayesian Voting

◦ Bagging

◦ Random Subspace Selection

◦ Injecting Randomness

◦ Boosting (especially AdaBoost)

◦ Mixture of Experts

◦ Stacking

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 451

Ensemble Methods: Fundamental Ideas

• It is well known from psychological studies of problem solving activities (but alsohighly plausible in itself) that a committee of (human) experts with different, butcomplementary skills usually produces better solutions than any individual.

• Ensemble methods combine several predictors (classifiers or numeric predictors) toimprove the prediction quality over the performance of the individual predictors.

• Instead of using a single model to predict the target value, we employ an ensembleof predictors and combine their predictions in order to obtain a joint prediction.

• The core ingredients of ensemble methods are a procedure to constructdifferent predictors and a rule how to combine their results.

Depending on the choices that are made for these two ingredients,a large variety of different ensemble methods has been suggested.

• While usually yielding higher accuracy than individual models,the fact that sometimes very large ensembles are employed makes the ensembleprediction mechanism difficult to interpret (even if the elements are simple).

Christian Borgelt Data Mining / Intelligent Data Analysis 452

Page 114: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Ensemble Methods: Fundamental Ideas

• A necessary and sufficient condition for an ensemble to out-perform the individualsis that the predictors are reasonably accurate and diverse.

• Technically, a predictor is already called (reasonably) accurate if it predictsthe correct target value for a new input object better than random guessing.

Hence this is a pretty weak requirement that is easy to meet in practice.

• Two predictors are called diverse if they do not make the same mistakes.

That this requirement is essential is obvious: if the predictors always madethe same mistakes, no improvement could possibly result from combining them.

• Consider the extreme case that the predictors in the ensemble are all identical:the combined prediction is necessarily the same as that of any individual predictor—regardless of how the individual predictions are combined.

• However, if the errors made by the individual predictors are uncorrelated,their combination will reduce these errors.

Christian Borgelt Data Mining / Intelligent Data Analysis 453

Ensemble Methods: Fundamental Ideas

• If we combine classifiers making independent mistakes by majority voting,the ensemble yields a wrong result only if more than half of the classifiersmisclassify an input object, thus improving over the individuals.

• For instance, for 5 independent classifiers for a two-class problem, each havingan error probability of 0.3, the probability that 3 or more yield a wrong result is

5∑

i=3

(5

i

)· 0.3i · 0.75−i = 0.08748.

• Note, however, that this holds only for the ideal case that the classifiersare fully independent, which is usually not the case in practice.

• Fortunately, though, improvements are also achieved if the dependenceis sufficiently weak, although the gains are naturally smaller.

• Note also that even in the ideal case no gains result (but rather a degradation)if the error probability of an individual classifier exceeds 0.5, which substantiatesthe requirement that the individual predictors should be accurate.

Christian Borgelt Data Mining / Intelligent Data Analysis 454

Why Do Ensemble Methods Work?

• According to [Dietterich 2000] there are basically three reasons why ensemblemethods work: statistical, computational, and representational.

• Statistical Reason:The statistical reason is that in practice any learning method has to workon a finite data set and thus may not be able to identify the correct predictor,even if this predictor lies within the set of models that the learning method can,in principle, return as a result. Rather it is to be expected that there are severalpredictors that yield similar accuracy.

• Since there is thus no sufficiently clear evidence which model is the correct or bestone, there is a certain risk that the learning method selects a suboptimal model.

• By removing the requirement to produce a single model,it becomes possible to “average” over many or even all of the good models.

• This reduces the risk of excluding the best predictorand the influence of actually bad models.

Christian Borgelt Data Mining / Intelligent Data Analysis 455

Why Do Ensemble Methods Work?

• According to [Dietterich 2000] there are basically three reasons why ensemblemethods work: statistical, computational, and representational.

• Computational Reason:The computational reason refers to the fact thatlearning algorithms usually cannot traverse the complete model space,but must use certain heuristics (greedy, hill climbing, gradient descent etc.)in order to find a model.

• Since these heuristics may yield suboptimal models(for example, local minima of the error function),a suboptimal model may be chosen.

• However, if several models constructed with heuristicsare combined in an ensemble, the result may be a better approximationof the true dependence between the inputs and the target variable.

Christian Borgelt Data Mining / Intelligent Data Analysis 456

Page 115: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Why Do Ensemble Methods Work?

• According to [Dietterich 2000] there are basically three reasons why ensemblemethods work: statistical, computational, and representational.

• Representational Reason:The representational reason is that for basically all learning methods,even the most flexible ones, the class of models that can be learned is limitedand thus it may be that the true model cannot be represented accurately.

• By combining several models in a predictor ensemble, the model space can beenriched, that is, the ensemble may be able to represent a dependence betweenthe inputs and the target variable that cannot be expressed by any of the individualmodels the learning method is able to produce.

• From a representational point of view, ensemble methods make it possible to reducethe bias of a learning algorithm by extending its model space, while the statisticaland computational reasons indicate that they can also reduce the variance.

• In this sense, ensemble methods are able to severthe usual link between bias and variance.

Christian Borgelt Data Mining / Intelligent Data Analysis 457

Ensemble Methods: Bayesian Voting

• In pure Bayesian voting the set of all possible modelsin a user-defined hypothesis space is enumerated to form the ensemble.

• The predictions of the individual models are combinedweighted with the posterior probability of the model given the training data.

That is, models that are unlikely to be correct given the data have a low influenceon the ensemble prediction, models that are likely have a high influence.

• The likelihood of the model given the data can often be computed as

P (M | D) ∝ P (D |M)P (M),

where M is the model, D the data, P (M) the prior probability of the model(often assumed to be the same for all models),and P (D |M) the data likelihood given the model.

• Theoretically, Bayesian voting is the optimal combination method,because all possible models are considered andtheir relative influence reflects their likelihood given the data.

Christian Borgelt Data Mining / Intelligent Data Analysis 458

Ensemble Methods: Bayesian Voting

• Theoretically, Bayesian voting is the optimal combination method,because all possible models are considered andtheir relative influence reflects their likelihood given the data.

• In practice, however, it suffers from several drawbacks:

◦ It is rarely possible to actually enumerate all models in the hypothesis spacethat is (implicitly) defined by a learning method.

For example, even if we restrict the tree size,it is usually infeasible to enumerate all decision treesthat could be constructed for a given classification problem.

◦ In order to overcome this problem, model sampling methods are employed,which ideally should select a model with a probability that correspondsto their likelihood given the data.

◦ However, most such methods are biased andthus usually do not yield a representative sample of the total set of models,sometimes seriously degrading the ensemble performance.

Christian Borgelt Data Mining / Intelligent Data Analysis 459

Ensemble Methods: Bagging

• The method of bagging (bootstrap aggregating) predictorscan be applied with basically any learning algorithm.

• The basic idea is to select a single learning algorithm(most studied in this respect are decision tree inducers) and to learn several modelsby providing it each time with a different random sample of the training data.

• The sampling is carried out with replacement (bootstrapping)with the sample size commonly chosen as n(1− 1/e) ≈ 0.632n,(where n is the number of training samples).

• Especially if the learning algorithm is unstable(like decision tree inducers, where a small change of the datacan lead to a considerably different decision tree),the resulting models will usually be fairly diverse,thus satisfying one of the conditions needed for ensemble methods to work.

• The predictions of the individual models are then combined by simplemajority voting or by averaging them (with the same weight for each model).

Christian Borgelt Data Mining / Intelligent Data Analysis 460

Page 116: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Ensemble Methods: Bagging

• Bagging effectively yields predictions from an “average model”,even though this model does not exist in simple form —it may not even lie in the hypothesis space of the learning algorithm.

• It has been shown that bagging reduces the risk of overfittingthe training data (because each subsample has different special properties)and thus produces very robust predictions.

• Experiments show that bagging yields very good resultsespecially for noisy data sets, where the sampling seems to be highly effectiveto avoid any adaptation to the noise data points.

• A closely related alternative to bagging are cross-validated committees.

• Instead of resampling the training data with replacement (bootstrapping)to generate the predictors of an ensemble,the predictors learned during a cross validation runare combined with equal weights in a majority vote or by averaging.

Christian Borgelt Data Mining / Intelligent Data Analysis 461

Ensemble Methods: Random Subspace Selection

• While bagging obtains a set of diverse predictorsby randomly varying the training data, random subspace selectionemploys a random selection of the features for this purpose.

• That is, all data points are used in each training run,but the features the model construction algorithm can use are randomly selected.

• With a learning algorithm like a decision tree inducer(for which random subspace selection was first proposed),the available features may even be varied each time a split has to be chosen,so that the whole decision tree can potentially use all features.

• Combining random subspace selection with bagging is a highly effectiveand strongly recommended method if accuracy is the main goal.

• Applied to decision trees this method has been named random forests,which is known to be one of the most accurate classification methods to date.

• However, the often huge number of trees destroys the advantagethat decision trees are easy to interpret and can be checked for plausibility.

Christian Borgelt Data Mining / Intelligent Data Analysis 462

Ensemble Methods: Injecting Randomness

• Both bagging and random subspace selection employ random processesin order to obtain diverse predictors.

• This approach can of course be generalized to the principle ofinjecting randomness into the learning process.

◦ Bagging: select training data set randomly

◦ Random Subspace Selection: select feature set randomly

• For example, such an approach is very natural and straightforwardfor artificial neural networks:different initialization of the connection weightsoften yield different learning results (different local optima),which may then be used as the members of an ensemble.

• Alternatively, the network structure can be modified,for example, by randomly deleting a certain fraction of the connectionsbetween two consecutive layers.

Christian Borgelt Data Mining / Intelligent Data Analysis 463

Ensemble Methods: Boosting

• Boosting constructs predictors progressively, with the prediction resultsof the model learned last influencing the construction of the next model.

• Like bagging, boosting varies the training data. However, instead of drawingrandom samples, boosting always works on the complete training data set,and maintains and manipulates a data point weight for each training example.

• For low noise data, boosting clearly outperforms baggingand random subspace selection in experimental studies.

• However, if the training data contains noise, the performance of boosting candegrade quickly, because it tends to focus on the noise data points (which arenecessarily difficult to classify and thus receive high weights after fairly few steps).

• As a consequence, boosting overfits the data.For noisy data bagging and random subspace selection yield much better results.

• Boosting is usually described for classification problems with two classes,which are assumed to be coded by 1 and −1.

Christian Borgelt Data Mining / Intelligent Data Analysis 464

Page 117: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Ensemble Methods: AdaBoost

• The best-known boosting approach is AdaBoost and works as follows:

• Initially, all data point weights are equal andtherefore set to wi = 1/n, i = 1, . . . n, where n is the size of the data set.

• After a predictorMt has been constructed in step t using the current weights wi,t,i = 1, . . . , n, it is applied to the training data and

et =

∑ni=1wi,t · yi ·Mt(~xi)∑n

i=1wi,tand αt =

1

2ln(1− et1 + et

)

are computed, where ~xi is the input vector, yi ∈ {−1, 1} the class of the i-thtraining example, and Mt(~xi) the prediction of the model for the input ~xi.

• The data point weights are then updated according to

wi,t+1 = c · wi,t · exp(−αtyiMt(~xi)),

where c is a normalization constant chosen in such a way that∑ni=1wi,t+1 = 1.

Christian Borgelt Data Mining / Intelligent Data Analysis 465

Ensemble Methods: AdaBoost

• The procedure of learning a predictor and updating the data point weightsis repeated a user-specified number of times tmax.

• The constructed ensemble classifies new data points by majority voting,with each model Mt weighted with αt.

• That is, the joint prediction is

Mjoint(~xi) = sign

tmax∑

t=1

αtMt(~xi)

.

• Since there is no convergence guarantee and the performance of the ensembleclassifier can even degrade after a certain number of steps, the inflection point ofthe error curve over t is often chosen as the ensemble size.

• Reminder: if the training data contains noise, the performance of boosting candegrade quickly, because it tends to focus on the noise data points (which arenecessarily difficult to classify and thus receive high weights after fairly few steps).As a consequence, boosting overfits the data.

Christian Borgelt Data Mining / Intelligent Data Analysis 466

Ensemble Methods: Mixture of Experts

• In the approach referred to as mixture of experts the individual predictorsto combine are assumed as already given, for example, selected by a user.

• They may be, for instance, results of different learning algorithms, like a decisiontree, neural networks with different network structure, a support vector machine,etc. — whatever the user sees as promising to solve the application task.

• Alternatively, they may be the set of models obtainedfrom any of the ensemble methods described so far.

• The focus is then placed on finding an optimal ruleto combine the predictions of the individual models.

• For classification tasks, for example, the input to this combination rule arethe probability distributions over the classes that the individual classifiers yield.

• Note that this requires more than simple (weighted) majority voting,which only asks each classifier for its best guess of the class of a new input object:each classifier must assign a probability to each class.

Christian Borgelt Data Mining / Intelligent Data Analysis 467

Ensemble Methods: Mixture of Experts

• The most common rules to combine such class probabilities are

◦ the so-called sum rule, which simply averages, for each class,the probabilities provided by the individual classifiers and

◦ the so-called product rule, which assumes conditional independenceof the classifiers given the class and therefore multiplies,for each class, the probabilities provided by the different classifiers.

• In both cases the class with the largest sum or productis chosen as the prediction of the ensemble.

• Experiments show that the sum rule is usually preferable,likely because due to the product a class that is seen as(very) unlikely by a single classifier has little chance of being predicted,even if several other classifiers assign a high probability to it.

• Both the sum rule and the product rule can be seen as special casesof a general family of combination rules that are known as f -means.Other such rules include Dempster–Shafer combination and rank based rules.

Christian Borgelt Data Mining / Intelligent Data Analysis 468

Page 118: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Ensemble Methods: Stacking

• Like a mixture of experts, stacking takes the set of predictors as already givenand focuses on combining their individual predictions.

• The core idea is to view the outputs of the predictors as new features andto use a learning algorithm to find a model that combines them optimally.

• Technically, a new data table is set up with one row for each training example,the columns of which contain the predictions of the different (level-1) modelsfor training example.In addition, a final column states the true classes.

• With this new training data set a (level-2) model is learned,the output of which is the prediction of the ensemble.

• Note that the level-2 model may be of the same or of a different typethan the level-1 models.

• For example, the output of several regression trees (e.g. a random forest)may be combined with a linear regression, or with a neural network.

Christian Borgelt Data Mining / Intelligent Data Analysis 469

Ensemble Methods: Summary

• Fundamental Ideas

◦ Combine Multiple Classifiers/Predictors

◦ Why Do Ensemble Methods Work?

• Some Popular Ensemble Methods

◦ Bayesian Voting

◦ Bagging

◦ Random Subspace Selection

◦ Injecting Randomness

◦ Boosting (especially AdaBoost)

◦ Mixture of Experts

◦ Stacking

• Ingredients: Predictor Construction + Combination Rule

Christian Borgelt Data Mining / Intelligent Data Analysis 470

Clustering

Christian Borgelt Data Mining / Intelligent Data Analysis 471

Clustering

• General Idea of Clustering

◦ Similarity and distance measures

• Prototype-based Clustering

◦ Classical c-means (or k-means) clustering

◦ Learning vector quantization (“online” c-means clustering)

◦ Fuzzy c-means clustering

◦ Expectation maximization for Gaussian mixtures

• Hierarchical Agglomerative Clustering

◦ Merging clusters: Dendrograms

◦ Measuring the distance of clusters

◦ Choosing the clusters

• Summary

Christian Borgelt Data Mining / Intelligent Data Analysis 472

Page 119: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

General Idea of Clustering

• Goal: Arrange the given data tuples into classes or clusters.

• Data tuples assigned to the same cluster should be as similar as possible.

• Data tuples assigned to different clusters should be as dissimilar as possible.

• Similarity is most often measured with the help of a distance function.(The smaller the distance, the more similar the data tuples.)

• Often: restriction to data points in IRm (although this is not mandatory).

d : IRm× IRm → IR+0 is a distance function if it satisfies ∀~x, ~y, ~z ∈ IRm :

(i) d(~x, ~y) = 0 ⇔ ~x = ~y,

(ii) d(~x, ~y) = d(~y, ~x) (symmetry),

(iii) d(~x, ~z) ≤ d(~x, ~y) + d(~y, ~z) (triangle inequality).

Christian Borgelt Data Mining / Intelligent Data Analysis 473

Distance Functions

Illustration of distance functions: Minkowski Family

dk(~x, ~y) = k

√√√√n∑

i=1

|xi − yi|k =

n∑

i=1

|xi − yi|k

1k

Well-known special cases from this family are:

k = 1 : Manhattan or city block distance,k = 2 : Euclidean distance (the only isotropic distance),k →∞ : maximum distance, i.e. d∞(~x, ~y) = max ni=1|xi − yi|.

k = 1 k = 2 k →∞

Christian Borgelt Data Mining / Intelligent Data Analysis 474

c-Means Clustering (a.k.a. k-Means Clustering)

• Choose a number c (or k) of clusters to be found (user input).

• Initialize the cluster centers randomly(for instance, by randomly selecting c data points — more details later).

• Data point assignment:Assign each data point to the cluster center that is closest to it(i.e. closer than any other cluster center).

• Cluster center update:Compute new cluster centers as the mean vectors of the assigned data points.(Intuitively: center of gravity if each data point has unit weight.)

• Repeat these two steps (data point assignment and cluster center update)until the clusters centers do not change anymore (convergence).

• It can be shown that this scheme must converge,i.e., the update of the cluster centers cannot go on forever.

Christian Borgelt Data Mining / Intelligent Data Analysis 475

c-Means Clustering: Example

Data set to cluster.

Choose c = 3 clusters.(From visual inspection, can bedifficult to determine in general.)

Initial position of cluster centers.

Randomly selected data points.(Alternative methods includee.g. latin hypercube sampling)

Christian Borgelt Data Mining / Intelligent Data Analysis 476

Page 120: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Delaunay Triangulations and Voronoi Diagrams

• Dots represent cluster centers (quantization vectors).

• Left: Delaunay Triangulation(The circle through the corners of a triangle does not contain another point.)

• Right: Voronoi Diagram(Midperpendiculars of the Delaunay triangulation: boundaries of the regionsof points that are closest to the enclosed cluster center (Voronoi cells)).

Christian Borgelt Data Mining / Intelligent Data Analysis 477

Delaunay Triangulations and Voronoi Diagrams

• Delaunay Triangulation: simple triangle (shown in grey on the left)

• Voronoi Diagram: midperpendiculars of the triangle’s edges(shown in blue on the left, in grey on the right)

Christian Borgelt Data Mining / Intelligent Data Analysis 478

c-Means Clustering: Example

Christian Borgelt Data Mining / Intelligent Data Analysis 479

c-Means Clustering: Local Minima

• Clustering is successful in this example:The clusters found are those that would have been formed intuitively.

• Convergence is achieved after only 5 steps.(This is typical: convergence is usually very fast.)

• However: The clustering result is fairly sensitive to the initial positionsof the cluster centers (see examples on next slides).

• With a bad initialization clustering may fail(the alternating update process gets stuck in a local minimum).

• Fuzzy c-means clustering and the estimation of a mixture of Gaussiansare much more robust (to be discussed later).

• Research issue: Can we determine the number of clusters automatically?(Some approaches exists, resampling is most successful.)

Christian Borgelt Data Mining / Intelligent Data Analysis 480

Page 121: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

c-Means Clustering: Local Minima

Christian Borgelt Data Mining / Intelligent Data Analysis 481

c-Means Clustering: Local Minima

0 1 2 3 4 5 6 7 8 90

1

2

3

4

5

6

7

0 1 2 3 4 5 6 7 8 90

1

2

3

4

5

6

7

A simple data set with three clusters and 300 data points (100 per cluster).

Result of a successful c-means clustering (left) and a local optimum (right).

Red diamonds mark cluster centers.

In an unsuccessful clustering, actual clusters are split or merged.

Christian Borgelt Data Mining / Intelligent Data Analysis 482

c-Means Clustering: Formal Description

• We are given a data set X = {~x1, . . . , ~xn} with n data points.

Each data point is an m-dimensional real-valued vector,that is, ∀j; 1 ≤ j ≤ n : ~xj = (xj1, . . . , xjm) ∈ Rm.

• These data points are to be grouped into c clusters,each of which is described by a prototype ci, i = 1, . . . , c.

The set of all prototypes is denoted by C = {c1, . . . , cc}.

• We (first) confine ourselves here to cluster prototypes that consist merelyof a cluster center, that is, ∀i; 1 ≤ i ≤ c : ci = ~ci = (ci1, . . . , cim) ∈ Rm.

• The assignment of data points to cluster centers is encoded as a c× n matrixU = (uij)1≤i≤c;1≤j≤n, which is often called the partition matrix.

• In the crisp case, a matrix element uij ∈ {0, 1} states whether data point ~xjbelongs to cluster ~ci or not.

In the fuzzy case (discussed later), uij ∈ [0, 1] states the degree to which ~xjbelongs to ~ci (degree of membership).

Christian Borgelt Data Mining / Intelligent Data Analysis 483

c-Means Clustering: Formal Description

• We confine ourselves (first) to the (squared) Euclidean distance as the measurefor the distance between a data point ~xj and a cluster center ~ci, that is,

d2ij = d2(~ci, ~xj) = (~xj − ~ci)⊤(~xj − ~ci) =m∑

k=1

(xjk − cik)2.

• The objective of (hard) c-means clustering is to minimize the objective function

J(X,C,U) =c∑

i=1

n∑

j=1

uij d2ij

under the constraints

◦ ∀j; 1 ≤ j ≤ n : ∀i; 1 ≤ i ≤ c : uij ∈ {0, 1} and◦ ∀j; 1 ≤ j ≤ n :

∑ci=1 uij = 1.

⇒ hard/crisp data point assignment:each data point is assigned to one cluster and one cluster only.

(“Fuzzy” and probabilistic data point assignments are considered later.)

Christian Borgelt Data Mining / Intelligent Data Analysis 484

Page 122: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

c-Means Clustering: Formal Description

• Since the minimum cannot be found directly using analytical means,an alternating optimization scheme is employed.

• At the beginning the cluster centers are initialized (discussed in more detail later).

• Then the two steps of partition matrix update (data point assignment)and cluster center update are iterated until convergence,that is, until the cluster centers do not change anymore.

• The partition matrix update assigns each data point ~xj to the cluster ci,the center ~ci of which is closest to it:

uij =

{1, if i = argminck=1 d

2kj,

0, otherwise.

• The cluster center update recomputes each cluster center as the meanof the data points that were assigned to it, that is,

~ci =

∑nj=1 uij ~xj∑nj=1 uij

.

Christian Borgelt Data Mining / Intelligent Data Analysis 485

Cluster Center Initialization

• Random Data Points (this was assumed up to now)

◦ Choose c data points uniformly at random without replacement.

Advantages:

◦ Very simple and efficient(time complexity O(c), no distance computations needed).

Disadvantages:

◦ Prone to the local optimum problem:Often leads to fairly bad clustering results.

◦ May actually be less efficient than other initialization methods,because it usually requires more update steps until convergence.

◦ Repeating the initialization (and clustering) several times helps,but results are usually still inferior compared to other methods.

Christian Borgelt Data Mining / Intelligent Data Analysis 486

Cluster Center Initialization

• Maximin Initialization [Hathaway, Bezdek, and Huband 2006]

◦ Choose first cluster center uniformly at random from the data points.

◦ For the remaining centers always choose the data point that hasthe maximum minimum distance to the already chosen cluster centers.

◦ Formally: For 0 < k ≤ c, define ∀j; 1 ≤ j ≤ n : dj(k) = minki=1 dij.

Then choose ~ck+1 = ~xℓ where ℓ = argmaxnj=1 dj(k).

Advantages:

◦ Cluster centers are guaranteed to have some distance from each other.

◦ Guarantees a fairly good coverage of the data points.(Reduces the tendency to find local optima.)

Disadvantages:

◦ Tends to choose outliers/extreme data points as cluster centers.

Christian Borgelt Data Mining / Intelligent Data Analysis 487

Cluster Center Initialization

• Maximin Initialization

◦ A naive implementation (following the above formal description)needs O(nc) distance computations (time complexity O(ncm)).

◦ An improved computation relies on the following simple insight:

∀r; 1 ≤ r ≤ k : dj(k) ≤ drj and ∀I ⊆ {1, . . . , k} : dj(k) ≤ minr∈I

drj.

◦ For t ∈ {1, . . . , n}, define dk(t) = maxtj=1 dj(k).

If dk(t) > dt+1(s) for some s ≤ k,

then ~xt+1 will certainly not be chosen as the next cluster center.

◦ Implementation: for each data point ~xj, note sj and dj(sj).

◦ Traverse the data points and in each step update t and dk(t).

◦ As long as st+1 < k and dt+1(st+1) > dk(t) (possible maximin point),

set dt+1(st+1 + 1) = min{dt+1(st+1), d(st+1+1)j} and increment st+1.

Finally compute dk(t + 1) accordingly.

Christian Borgelt Data Mining / Intelligent Data Analysis 488

Page 123: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Cluster Center Initialization

• Maximin Initialization: Python code (using NumPy)

ctrs[0] = data[npr.randint(n))] # choose first cluster center randomly

dsts = np.array([dist(ctrs[0], x) for x in data])

cids = np.zeros(n, dtype=int) # init. highest used cluster indices

for i in range(1,c): # select the remaining clusters

dmax = m = 0 # init. max. distance and corresp. index

for j in range(n): # traverse the data points

if dsts[j] <= dmax: # if less than current maximum,

continue # data point will not be selected

while cids[j] < i-1: # traverse skipped clusters

cids[j] += 1 # go to the next cluster

d = dist(ctrs[cids[j]], data[j])

if d < dsts[j]: # if less than known distance,

dsts[j] = d # update the minimum distance

if d < dmax: # if less than current maximum,

break # data point will not be selected

if dsts[j] > dmax: # if larger than current maximum

dmax = dsts[j] # note new maximum distance and

m = j # corresponding data point index

dsts[m] = 0.0 # mark the data point as selected

ctrs[i] = data[m] # and add it to the set of centers

Christian Borgelt Data Mining / Intelligent Data Analysis 489

Cluster Center Initialization

• kmeans++ (or cmeans++) Initialization [Arthur and Vassilvitskii 2007]

◦ Choose first cluster center uniformly at random from the data points.

◦ For the remaining centers sample data points according to the squared distancea data point has to its closest already chosen cluster center.

◦ Formally: For 1 ≤ k ≤ c, define ∀j; 1 ≤ j ≤ n : dj(k) = minki=1 dij.

Then sample ~ck+1 from the data points according to Pk+1(~xj) =d2j(k)∑nr=1 d

2r(k)

.

Advantages:

◦ Selects, with fairly high probability, cluster centers that have some distancefrom each otherand thus centers that cover the data fairly well.

◦ Less likely to select outliers/extreme data points than maximin.

Disadvantages:

◦ High costs: needs O(nc) distance computations (time complexity O(ncm)).

Christian Borgelt Data Mining / Intelligent Data Analysis 490

Cluster Center Initialization

• kmeans++ (or cmeans++) Initialization: Python code (using NumPy)

ctrs[0] = data[npr.randint(n))] # choose first cluster center randomly

dsts = np.array([sqrdist(ctrs[0], x) for x in data])

# compute distances to first center

for i in range(1,c): # select the remaining clusters

if i > 1: # update the minimum distances

dsts = np.minimum(dsts, [sqrdist(ctrs[i], x) for x in data])

dcum = np.cumsum(dsts) # compute cumulated distance sums

m = np.searchsorted(dcum, dcum[-1] *npr.random())

if m >= size: # sample randomly from d^2 distribution

m = size-1 # and ensure that the index is in range

dsts[m] = 0.0 # mark the data point as selected

ctrs[i] = data[m] # and add it to the set of centers

• The computational costs may be reducedby using a Markov Chain Monte Carlo approach for the sampling.

[Bachem, Lucic, Hassani and Krause 2016]This approach avoids having to compute all n · c distances.

Christian Borgelt Data Mining / Intelligent Data Analysis 491

Learning Vector Quantization

Adaptation of reference vectors / codebook vectors

• May be seen as an “online” version of (batch) c-means clustering.

• For each training pattern find the closest reference vector.

• Adapt only this reference vector (winner neuron).

• For classified data the class may be taken into account:Each reference vector is assigned to a class.

Attraction rule (data point and reference vector have same class)

~r (new) = ~r (old) + η(~x− ~r (old)),

Repulsion rule (data point and reference vector have different class)

~r (new) = ~r (old) − η(~x− ~r (old)).

Christian Borgelt Data Mining / Intelligent Data Analysis 492

Page 124: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Learning Vector Quantization

Adaptation of reference vectors / codebook vectors

~r1

~r3

~r2

~p

dηd

~r1

~r3~p

~r2dηd

• ~x: data point, ~ri: reference vector

• η = 0.4 (learning rate)

Christian Borgelt Data Mining / Intelligent Data Analysis 493

Learning Vector Quantization: Example

Adaptation of reference vectors / codebook vectors

• Left: Online training with learning rate η = 0.1,

• Right: Batch training with learning rate η = 0.05.

Christian Borgelt Data Mining / Intelligent Data Analysis 494

Learning Vector Quantization: Learning Rate Decay

Problem: fixed learning rate can lead to oscillations

Solution: time dependent learning rate

η(t) = η0αt, 0 < α < 1, or η(t) = η0t

κ, κ > 0.

Christian Borgelt Data Mining / Intelligent Data Analysis 495

Learning Vector Quantization: Classified Data

Improved update rule for classified data

• Idea: Update not only the one reference vector that is closest to the data point(the winner neuron), but update the two closest reference vectors.

• Let ~x be the currently processed data point and c its class.Let ~rj and ~rk be the two closest reference vectors and zj and zk their classes.

• Reference vectors are updated only if zj 6= zk and either c = zj or c = zk.(Without loss of generality we assume c = zj.)The update rules for the two closest reference vectors are:

~r(new)j = ~r

(old)j + η(~x− ~r (old)j ) and

~r(new)k = ~r

(old)k − η(~x− ~r (old)k ),

while all other reference vectors remain unchanged.

Christian Borgelt Data Mining / Intelligent Data Analysis 496

Page 125: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Learning Vector Quantization: Window Rule

• It was observed in practical tests that standard learning vector quantization maydrive the reference vectors further and further apart.

• To counteract this undesired behavior a window rule was introduced:update only if the data point ~x is close to the classification boundary.

• “Close to the boundary” is made formally precise by requiring

min

(d(~x, ~rj)

d(~x, ~rk),d(~x, ~rk)

d(~x, ~rj)

)> θ, where θ =

1− ξ1 + ξ

.

ξ is a parameter that has to be specified by a user.

• Intuitively, ξ describes the “width” of the window around the classification bound-ary, in which the data point has to lie in order to lead to an update.

• Using it prevents divergence, because the update ceases for a data point once theclassification boundary has been moved far enough away.

Christian Borgelt Data Mining / Intelligent Data Analysis 497

Fuzzy Clustering

• Allow degrees of membership of a datum to different clusters.(Classical c-means clustering assigns data crisply.)

Objective Function: (to be minimized)

J(X,B,U) =c∑

i=1

n∑

j=1

uwijd2(βi, ~xj)

• U = [uij] is the c× n fuzzy partition matrix,

uij ∈ [0, 1] is the membership degree of the data point ~xj to the i-th cluster.

• B = {β1, . . . , βc} is the set of cluster prototypes.

• w is the so-called “fuzzifier” (the higher w, the softer the cluster boundaries).

• Constraints:

∀i ∈ {1, . . . , c} :n∑

j=1

uij > 0 and ∀j ∈ {1, . . . , n} :c∑

i=1

uij = 1.

Christian Borgelt Data Mining / Intelligent Data Analysis 498

Fuzzy and Hard Clustering

Relation to Classical c-Means Clustering:

• Classical c-means clustering can be seen as optimizing the objective function

J(X,B,U) =c∑

i=1

n∑

j=1

uij d2(βi, ~xj),

where ∀i, j : uij ∈ {0, 1} (i.e. hard assignment of the data points)and the cluster prototypes βi consist only of cluster centers.

• To obtain a fuzzy assignment of the data points, it is not enoughto extend the range of values for the uij to the unit interval [0, 1]:The objective function J is optimized for a hard assignment(each data point is assigned to the closest cluster center).

• To achieve actual degrees of membership:Apply a convex function h : [0, 1]→ [0, 1] to the membership degrees uij.Most common choice: h(u) = uw, usually with w = 2.

Christian Borgelt Data Mining / Intelligent Data Analysis 499

Reminder: Function Optimization

Task: Find values ~x = (x1, . . . , xm) such that f (~x) = f (x1, . . . , xm) is optimal.

Often feasible approach:

• A necessary condition for a (local) optimum (maximum or minimum) isthat the partial derivatives w.r.t. the parameters vanish (Pierre Fermat).

• Therefore: (Try to) solve the equation system that results from settingall partial derivatives w.r.t. the parameters equal to zero.

Example task: Minimize f (x, y) = x2 + y2 + xy − 4x− 5y.

Solution procedure:

1. Take the partial derivatives of the objective function and set them to zero:

∂f

∂x= 2x + y − 4 = 0,

∂f

∂y= 2y + x− 5 = 0.

2. Solve the resulting (here: linear) equation system: x = 1, y = 2.

Christian Borgelt Data Mining / Intelligent Data Analysis 500

Page 126: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Function Optimization with Constraints

Often a function has to be optimized subject to certain constraints.

Here: restriction to k equality constraints Ci(~x) = 0, i = 1, . . . , k.

Note: the equality constraints describe a subspace of the domain of the function.

Problem of optimization with constraints:

• The gradient of the objective function f may vanish outside the constrainedsubspace, leading to an unacceptable solution (violating the constraints).

• At an optimum in the constrained subspace the derivatives need not vanish.

One way to handle this problem are generalized coordinates:

• Exploit the dependence between the parameters specified in the constraintsto express some parameters in terms of the others and thus reduce the set ~xto a set ~x′ of independent parameters (generalized coordinates).

• Problem: Can be clumsy and cumbersome, if possible at all, becausethe form of the constraints may not allow for expressing some parametersas proper functions of the others.

Christian Borgelt Data Mining / Intelligent Data Analysis 501

Function Optimization with Constraints

A much more elegant approach is based on the following nice insights:Let ~x∗ be a (local) optimum of f (~x) in the constrained subspace. Then:

• The gradient ∇~xf (~x∗), if it does not vanish, must be perpendicular to theconstrained subspace. (If ∇~xf (~x∗) had a component in the constrained subspace,~x∗ would not be a (local) optimum in this subspace.)

• The gradients ∇~xCj(~x∗), 1 ≤ j ≤ k, must all be perpendicular to theconstrained subspace, because they are constant, namely 0, in this subspace.Together they span the subspace perpendicular to the constrained subspace.

• Therefore it must be possible to find values λj, 1 ≤ j ≤ k, such that

∇~xf (~x∗) +s∑

j=1

λj∇~xCj(~x∗) = 0.

If the constraints (and thus their gradients) are linearly independent,the values λj are uniquely determined. This equation can be used tocompensate the gradient of f (~x∗) so that it vanishes at ~x∗.

Christian Borgelt Data Mining / Intelligent Data Analysis 502

Function Optimization: Lagrange Theory

As a consequence of these insights we obtain the

Method of Lagrange Multipliers:

Given: ◦ a function f (~x), which is to be optimized,◦ k equality constraints Cj(~x) = 0, 1 ≤ j ≤ k.

Procedure:

1. Construct the so-called Lagrange function by incorporating the equalityconstraints Ci, i = 1, . . . , k, with (unknown) Lagrange multipliers λi:

L(~x, λ1, . . . , λk) = f (~x) +k∑

i=1

λiCi(~x).

2. Set the partial derivatives of the Lagrange function equal to zero:

∂L

∂x1= 0, . . . ,

∂L

∂xm= 0,

∂L

∂λ1= 0, . . . ,

∂L

∂λk= 0.

3. (Try to) solve the resulting equation system.

Christian Borgelt Data Mining / Intelligent Data Analysis 503

Function Optimization: Lagrange Theory

Observations:

• Due to the representation of the gradient of f (~x) at a local optimum ~x∗in the constrained subspace (see above) the gradient of L w.r.t. ~x vanishes at ~x∗.→ The standard approach works again!

• If the constraints are satisfied, the additional terms have no influence.

→ The original task is not modified (same objective function).

• Taking the partial derivative w.r.t. a Lagrange multiplierreproduces the corresponding equality constraint:

∀j; 1 ≤ j ≤ k :∂

∂λjL(~x, λ1, . . . , λk) = Cj(~x),

→ Constraints enter the equation system to solve in a natural way.

Remark:

• Inequality constraints can be handled with the Kuhn–Tucker theory.

Christian Borgelt Data Mining / Intelligent Data Analysis 504

Page 127: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Lagrange Theory: Example 1

Example task: Minimize f (x, y) = x2 + y2 subject to x + y = 1.

–0.50

0.510

1 1

21

2

x

y

f

unconstrainedminimum~p0 = (0, 0)

f(x, y) = x2 + y2minimum in theconstrained subspace~p1 = ( 12 ,

12 ) constrained

subspacex+ y = 1

The unconstrained minimum is not in the constrained subspace, andat the minimum in the constrained subspace the gradient does not vanish.

Christian Borgelt Data Mining / Intelligent Data Analysis 505

Lagrange Theory: Example 1

Example task: Minimize f (x, y) = x2 + y2 subject to x + y = 1.

Solution procedure:

1. Rewrite the constraint, so that one side gets zero: x + y − 1 = 0.

2. Construct the Lagrange function by incorporating the constraintinto the objective function with a Lagrange multiplier λ:

L(x, y, λ) = x2 + y2 + λ(x + y − 1).

3. Take the partial derivatives of the Lagrange function and set them to zero(necessary conditions for a minimum):

∂L

∂x= 2x + λ = 0,

∂L

∂y= 2y + λ = 0,

∂L

∂λ= x + y − 1 = 0.

4. Solve the resulting (here: linear) equation system:

λ = −1, x = y = 12.

Christian Borgelt Data Mining / Intelligent Data Analysis 506

Lagrange Theory: Example 1

C(x, y) = x + y − 1

1

21

2

x

y

C

–0.50

0.510

0.5

1

x

–0.50

0.510

0.5

1

x+ y − 1 = 0

L(x, y,−1) = x2 + y2 − (x + y − 1)

–0.50

0.510

1 1

21

2

x

y

L

minimum ~p1 = ( 12 ,12 )

The gradient of the constraint is perpendicular to the constrained subspace.The (unconstrained) minimum of the Lagrange function L(x, y, λ)is the minimum of the objective function f (x, y) in the constrained subspace.

Christian Borgelt Data Mining / Intelligent Data Analysis 507

Lagrange Theory: Example 2

Example task: Find the side lengths x, y, z of a box with maximum volumefor a given area S of the surface.

Formally: Maximize f (x, y, z) = xyzsubject to 2xy + 2xz + 2yz = S.

Solution procedure:

1. The constraint is C(x, y, z) = 2xy + 2xz + 2yz − S = 0.

2. The Lagrange function is

L(x, y, z, λ) = xyz + λ(2xy + 2xz + 2yz − S).

3. Taking the partial derivatives yields (in addition to the constraint):

∂L

∂x= yz+2λ(y+z) = 0,

∂L

∂y= xz+2λ(x+z) = 0,

∂L

∂y= xy+2λ(x+y) = 0.

4. The solution is: λ = −14

√S6 , x = y = z =

√S6 (i.e., the box is a cube).

Christian Borgelt Data Mining / Intelligent Data Analysis 508

Page 128: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Fuzzy Clustering: Alternating Optimization

Objective function: (to be minimized)

J(X,B,U) =c∑

i=1

n∑

j=1

uwijd2(~xj, βi)

Constraints:

∀i ∈ {1, . . . , c} :n∑

j=1

uij > 0 and ∀j ∈ {1, . . . , n} :c∑

i=1

uij = 1.

• Problem: The objective function J cannot be minimized directly.

• Therefore: Alternating Optimization

◦ Optimize membership degrees for fixed cluster parameters.

◦ Optimize cluster parameters for fixed membership degrees.

(Update formulae are derived by differentiating the objective function J)

◦ Iterate until convergence (checked, e.g., by change of cluster center).

Christian Borgelt Data Mining / Intelligent Data Analysis 509

Fuzzy Clustering: Alternating Optimization

First Step: Fix the cluster parameters.

Introduce Lagrange multipliers λj, 0 ≤ j ≤ n, to incorporate the constraints ∀j; 1 ≤j ≤ n :

∑ci=1 uij = 1. This yields the Lagrange function (to be minimized)

L(X,B,U,Λ) =c∑

i=1

n∑

j=1

uwij d2ij

︸ ︷︷ ︸=J(X,B,U)

+n∑

j=1

λj

1−

c∑

i=1

uij

,

A necessary condition for the minimum is that the partial derivatives of theLagrange function w.r.t. the membership degrees vanish, i.e.,

∂uklL(X,B,U,Λ) = w uw−1kl d2kl − λl

!= 0,

which leads to

∀i; 1 ≤ i ≤ c : ∀j; 1 ≤ j ≤ n : uij =

λj

w d2ij

1w−1

.

Christian Borgelt Data Mining / Intelligent Data Analysis 510

Fuzzy Clustering: Alternating Optimization

Summing these equations over the clusters (in order to be able to exploitthe corresponding constraints on the membership degrees), we get

1 =c∑

i=1

uij =c∑

i=1

λj

w d2ij

1w−1

.

Consequently the λj, 1 ≤ j ≤ n, are

λj =

c∑

i=1

(w d2ij

) 11−w

1−w

.

Inserting this into the equation for the membership degrees yields

∀i; 1 ≤ i ≤ c : ∀j; 1 ≤ j ≤ n : uij =d

21−wij

∑ck=1 d

21−wkj

.

This update formula results regardless of the distance measure.

Christian Borgelt Data Mining / Intelligent Data Analysis 511

Standard Fuzzy Clustering Algorithms

Fuzzy C-Means Algorithm: Euclidean distance

d 2fcm(~xj, βi) = (~xj − ~µi)⊤(~xj − ~µi)Necessary condition for a minimum: gradients w.r.t. cluster centers vanish.

∇~µk Jfcm(X,B,U) = ∇~µkc∑

i=1

n∑

j=1

uwij (~xj − ~µi)⊤(~xj − ~µi)

=n∑

j=1

uwkj ∇~µk(~xj − ~µk)⊤(~xj − ~µk)

= −2n∑

j=1

uwkj (~xj − ~µk)!= ~0

Resulting update rule for the cluster centers (second step of alt. optimization):

∀i; 1 ≤ i ≤ c : ~µi =

∑nj=1 u

wij~xj∑n

j=1 uwij

Christian Borgelt Data Mining / Intelligent Data Analysis 512

Page 129: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Standard Fuzzy Clustering Algorithms

Gustafson–Kessel Algorithm: Mahalanobis distance

d 2gk(~xj, βi) = (~xj − ~µi)⊤C−1i (~xj − ~µi)

Additional constraints: |Ci| = 1 (all cluster have unit size).These constraints are incorporated again by Lagrange multipliers.

A similar derivation as for the fuzzy c-means algorithmyields the same update rule for the cluster centers:

∀i; 1 ≤ i ≤ c : ~µi =

∑nj=1 u

wij~xj∑n

j=1 uwij

Update rule for the covariance matrices (m is the number of dimensions):

Ci =1

m√|Σi|

Σi where Σi =n∑

j=1

uwij(~xj − ~µi)(~xj − ~µi)⊤.

Christian Borgelt Data Mining / Intelligent Data Analysis 513

Fuzzy Clustering: Overlapping Clusters

Classical c-Means Fuzzy c-Means

Christian Borgelt Data Mining / Intelligent Data Analysis 514

Fuzzy Clustering of the Iris Data

Fuzzy c-Means Gustafson–Kessel

Christian Borgelt Data Mining / Intelligent Data Analysis 515

Expectation Maximization: Mixture of Gaussians

• Assumption: Data was generated by sampling a set of normal distributions.(The probability density is a mixture of Gaussian distributions.)

• Formally: We assume that the probability density can be described as

f ~X(~x;C) =c∑

y=1

f ~X,Y (~x, y;C) =c∑

y=1

pY (y;C) · f ~X|Y (~x|y;C).

C is the set of cluster parameters

~X is a random vector that has the data space as its domain

Y is a random variable that has the cluster indices as possiblevalues (i.e., dom( ~X) = IRm and dom(Y ) = {1, . . . , c})

pY (y;C) is the probability that a data point belongs to (is generatedby) the y-th component of the mixture

f ~X|Y (~x|y;C) is the conditional probability density function of a data pointgiven the cluster (specified by the cluster index y)

Christian Borgelt Data Mining / Intelligent Data Analysis 516

Page 130: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Expectation Maximization

• Basic idea: Do a maximum likelihood estimation of the cluster parameters.

• Problem: The likelihood function,

L(X;C) =n∏

j=1

f ~Xj(~xj;C) =

n∏

j=1

c∑

y=1

pY (y;C) · f ~X|Y (~xj|y;C),

is difficult to optimize, even if one takes the natural logarithm (cf. the maximumlikelihood estimation of the parameters of a normal distribution), because

lnL(X;C) =n∑

j=1

lnc∑

y=1

pY (y;C) · f ~X|Y (~xj|y;C)

contains the natural logarithms of complex sums.

• Approach: Assume that there are “hidden” variables Yj stating the clustersthat generated the data points ~xj, so that the sums reduce to one term.

• Problem: Since the Yj are hidden, we do not know their values.

Christian Borgelt Data Mining / Intelligent Data Analysis 517

Expectation Maximization

• Formally: Maximize the likelihood of the “completed” data set (X, ~y),where ~y = (y1, . . . , yn) combines the values of the variables Yj. That is,

L(X, ~y;C) =n∏

j=1

f ~Xj,Yj(~xj, yj;C) =

n∏

j=1

pYj(yj;C) · f ~Xj|Yj(~xj|yj;C).

• Problem: Since the Yj are hidden, the values yj are unknown(and thus the factors pYj(yj;C) cannot be computed).

• Approach to find a solution nevertheless:

◦ See the Yj as random variables (the values yj are not fixed) andconsider a probability distribution over the possible values.

◦ As a consequence L(X, ~y;C) becomes a random variable,even for a fixed data set X and fixed cluster parameters C.

◦ Try to maximize the expected value of L(X, ~y;C) or lnL(X, ~y;C)(hence the name expectation maximization).

Christian Borgelt Data Mining / Intelligent Data Analysis 518

Expectation Maximization

• Formally: Find the cluster parameters as

C = argmaxC

E([ln]L(X, ~y;C) | X;C),

that is, maximize the expected likelihood

E(L(X, ~y;C) | X;C) =∑

~y∈{1,...,c}np~Y |X (~y |X;C) ·

n∏

j=1

f ~Xj,Yj(~xj, yj;C)

or, alternatively, maximize the expected log-likelihood

E(lnL(X, ~y;C) | X;C) =∑

~y∈{1,...,c}np~Y |X (~y |X;C) ·

n∑

j=1

ln f ~Xj,Yj(~xj, yj;C).

• Unfortunately, these functionals are still difficult to optimize directly.

• Solution: Use the equation as an iterative scheme, fixing C in some terms(iteratively compute better approximations, similar to Heron’s algorithm).

Christian Borgelt Data Mining / Intelligent Data Analysis 519

Excursion: Heron’s Algorithm

• Task: Find the square root of a given number x, i.e., find y =√x.

• Approach: Rewrite the defining equation y2 = x as follows:

y2 = x ⇔ 2y2 = y2 + x ⇔ y =1

2y(y2 + x) ⇔ y =

1

2

(y +

x

y

).

• Use the resulting equation as an iteration formula, i.e., compute the sequence

yk+1 =1

2

(yk +

x

yk

)with y0 = 1.

• It can be shown that 0 ≤ yk −√x ≤ yk−1 − yn for k ≥ 2.

Therefore this iteration formula provides increasingly better approximations of thesquare root of x and thus is a safe and simple way to compute it.Ex.: x = 2: y0 = 1, y1 = 1.5, y2 ≈ 1.41667, y3 ≈ 1.414216, y4 ≈ 1.414213.

• Heron’s algorithm converges very quickly and is often used in pocket calculatorsand microprocessors to implement the square root.

Christian Borgelt Data Mining / Intelligent Data Analysis 520

Page 131: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Expectation Maximization

• Iterative scheme for expectation maximization:

Choose some initial set C0 of cluster parameters and then compute

Ck+1 = argmaxC

E(lnL(X, ~y;C) | X;Ck)

= argmaxC

~y∈{1,...,c}np~Y |X (~y |X;Ck)

n∑

j=1

ln f ~Xj,Yj(~xj, yj;C)

= argmaxC

~y∈{1,...,c}n

n∏

l=1

pYl| ~Xl

(yl|~xl;Ck)

n∑

j=1

ln f ~Xj,Yj(~xj, yj;C)

= argmaxC

c∑

i=1

n∑

j=1

pYj| ~Xj(i|~xj;Ck) · ln f ~Xj,Yj(~xj, i;C).

• It can be shown that each EM iteration increases the likelihood of the dataand that the algorithm converges to a local maximum of the likelihood function(i.e., EM is a safe way to maximize the likelihood function).

Christian Borgelt Data Mining / Intelligent Data Analysis 521

Expectation Maximization

Justification of the last step on the previous slide:

~y∈{1,...,c}n

n∏

l=1

pYl| ~Xl

(yl|~xl;Ck)

n∑

j=1

ln f ~Xj,Yj(~xj, yj;C)

=c∑

y1=1

· · ·c∑

yn=1

n∏

l=1

pYl| ~Xl

(yl|~xl;Ck)

n∑

j=1

c∑

i=1

δi,yj ln f ~Xj,Yj(~xj, i;C)

=c∑

i=1

n∑

j=1

ln f ~Xj,Yj(~xj, i;C)

c∑

y1=1

· · ·c∑

yn=1

δi,yj

n∏

l=1

pYl| ~Xl

(yl|~xl;Ck)

=c∑

i=1

n∑

j=1

pYj| ~Xj(i|~xj;Ck) · ln f ~Xj,Yj(~xj, i;C)

c∑

y1=1

· · ·c∑

yj−1=1

c∑

yj+1=1

· · ·c∑

yn=1

n∏

l=1,l 6=jpYl| ~Xl

(yl|~xl;Ck)

︸ ︷︷ ︸=

∏nl=1,l 6=j

∑cyl=1 pYl| ~Xl

(yl|~xl;Ck) =∏nl=1,l 6=j 1 = 1

.

Christian Borgelt Data Mining / Intelligent Data Analysis 522

Expectation Maximization

• The probabilities pYj| ~Xj(i|~xj;Ck) are computed as

pYj| ~Xj(i|~xj;Ck) =

f ~Xj,Yj(~xj, i;Ck)

f ~Xj(~xj;Ck)

=f ~Xj|Yj(~xj|i;Ck) · pYj(i;Ck)

∑cl=1 f ~Xj|Yj(~xj|l;Ck) · pYj(l;Ck)

,

that is, as the relative probability densities of the different clusters (as specifiedby the cluster parameters) at the location of the data points ~xj.

• The pYj| ~Xj(i|~xj;Ck) are the posterior probabilities of the clusters

given the data point ~xj and a set of cluster parameters Ck.

• They can be seen as case weights of a “completed” data set:

◦ Split each data point ~xj into c data points (~xj, i), i = 1, . . . , c.

◦ Distribute the unit weight of the data point ~xj according to the above proba-bilities, i.e., assign to (~xj, i) the weight pYj| ~Xj(i|~xj;Ck), i = 1, . . . , c.

Christian Borgelt Data Mining / Intelligent Data Analysis 523

Expectation Maximization: Cookbook Recipe

Core Iteration Formula

Ck+1 = argmaxC

c∑

i=1

n∑

j=1

pYj| ~Xj(i|~xj;Ck) · ln f ~Xj,Yj(~xj, i;C)

Expectation Step

• For all data points ~xj:Compute for each normal distribution the probability p

Yj| ~Xj(i|~xj;Ck)that the data point was generated from it(ratio of probability densities at the location of the data point).→ “weight” of the data point for the estimation.

Maximization Step

• For all normal distributions:Estimate the parameters by standard maximum likelihood estimationusing the probabilities (“weights”) assigned to the data pointsw.r.t. the distribution in the expectation step.

Christian Borgelt Data Mining / Intelligent Data Analysis 524

Page 132: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Expectation Maximization: Mixture of Gaussians

Expectation Step: Use Bayes’ rule to compute

pC| ~X(i|~x;C) =

pC(i; ci) · f ~X|C(~x|i; ci)f ~X(~x;C)

=pC(i; ci) · f ~X|C(~x|i; ci)∑c

k=1 pC(k; ck) · f ~X|C(~x|k; ck).

→ “weight” of the data point ~x for the estimation.

Maximization Step: Use maximum likelihood estimation to compute

(t+1)i =

1

n

n∑

j=1

pC| ~Xj(i|~xj;C

(t)), ~µ(t+1)i =

∑nj=1 pC| ~Xj(i|~xj;C

(t)) · ~xj∑nj=1 pC| ~Xj(i|~xj;C

(t)),

and Σ(t+1)i =

∑nj=1 pC| ~Xj(i|~xj;C

(t)) ·(~xj − ~µ(t+1)i

)(~xj − ~µ(t+1)i

)⊤

∑nj=1 pC| ~Xj(i|~xj;C

(t))

Iterate until convergence (checked, e.g., by change of mean vector).

Christian Borgelt Data Mining / Intelligent Data Analysis 525

Expectation Maximization: Technical Problems

• If a fully general mixture of Gaussian distributions is used,the likelihood function is truly optimized if

◦ all normal distributions except one are contracted to single data points and

◦ the remaining normal distribution is the maximum likelihood estimate for theremaining data points.

• This undesired result is rare,because the algorithm gets stuck in a local optimum.

• Nevertheless it is recommended to take countermeasures,which consist mainly in reducing the degrees of freedom, like

◦ Fix the determinants of the covariance matrices to equal values.

◦ Use a diagonal instead of a general covariance matrix.

◦ Use an isotropic variance instead of a covariance matrix.

◦ Fix the prior probabilities of the clusters to equal values.

Christian Borgelt Data Mining / Intelligent Data Analysis 526

Hierarchical Agglomerative Clustering

• Start with every data point in its own cluster.(i.e., start with so-called singletons: single element clusters)

• In each step merge those two clusters that are closest to each other.

• Keep on merging clusters until all data points are contained in one cluster.

• The result is a hierarchy of clusters that can be visualized in a tree structure(a so-called dendrogram — from the Greek δεντων (dendron): tree)

• Measuring the Distances

◦ The distance between singletons is simply the distancebetween the (single) data points contained in them.

◦ However: How do we compute the distance between clustersthat contain more than one data point?

Christian Borgelt Data Mining / Intelligent Data Analysis 527

Measuring the Distance between Clusters

• Centroid (red)Distance between the centroids (mean value vectors) of the two clusters.

• Average LinkageAverage distance between two points of the two clusters.

• Single Linkage (green)Distance between the two closest points of the two clusters.

• Complete Linkage (blue)Distance between the two farthest points of the two clusters.

Christian Borgelt Data Mining / Intelligent Data Analysis 528

Page 133: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Measuring the Distance between Clusters

• Single linkage can “follow chains” in the data(may be desirable in certain applications).

• Complete linkage leads to very compact clusters, but may also “bridge gaps.”

• Average linkage also tends clearly towards compact clusters.

Single Linkage Complete Linkage

(These are the actual results that are computed for this data set; see also below.)

Christian Borgelt Data Mining / Intelligent Data Analysis 529

Dendrograms

• The cluster merging process arranges the data points in a binary tree.

• Draw the data tuples at the bottom or on the left(equally spaced if they are multi-dimensional).

• Draw a connection between clusters that are merged, with the distance to the datapoints representing the distance between the clusters.

datatuples

distance between clusters

Christian Borgelt Data Mining / Intelligent Data Analysis 530

Dendrograms

• Example: Clustering of the 1-dimensional data set {2, 12, 16, 25, 29, 45}.

• All three approaches to measure the distance between clusterslead to different dendrograms.

2 12 16 25 29 45 2 12 16 25 29 45 2 12 16 25 29 45

Centroid

14 27

10

16.8

21.5

Single Linkage Complete Linkage

Christian Borgelt Data Mining / Intelligent Data Analysis 531

Dendrograms for “Half Circle” Data

• Single linkage can “follow chains” in the data.

• Complete linkage leads to very compact clusters,but may also “bridge gaps.”

• These dendrograms use centroids.

Single Linkage Complete Linkage

Christian Borgelt Data Mining / Intelligent Data Analysis 532

Page 134: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Implementation Aspects

• Hierarchical agglomerative clustering can be implemented by processing the matrixD = (dκij)1≤i,j≤n containing the pairwise (squared) distances of the data points.(The data points themselves are actually not needed.)

• In each step the rows and columns corresponding to the two clustersthat are closest to each other are deleted.

• A new row and column corresponding to the cluster formedby merging these clusters is added to the matrix.

• The elements of this new row/column are computed according to (κ ∈ {1, 2}):

∀k : dκk∗ = dκ∗k = αidκik + αjd

κjk + βdκij + γ|dκik − dκjk|

i, j indices of the two clusters that are mergedk indices of the old clusters that are not merged∗ index of the new cluster (result of merger)αi, αj, β, γ parameters specifying the method (single linkage etc.)

Christian Borgelt Data Mining / Intelligent Data Analysis 533

Implementation Aspects

• The parameters defining the different methods are [Lance & Williams 1967](ni, nj, nk are the numbers of data points in the clusters):

method κ αi αj β γ

centroid method 2ni

ni+nj

njni+nj

− ninj(ni+nj)2

0

median method 1 12

12 −1

4 0

single linkage 1 or 2 12

12 0 −1

2

complete linkage 1 or 2 12

12 0 +1

2

average linkage 1ni

ni+nj

njni+nj

0 0

Ward’s method 2ni+nk

ni+nj+nk

nj+nkni+nj+nk

0 0

Christian Borgelt Data Mining / Intelligent Data Analysis 534

Implementation Aspects: Centroid Formula

Application of the (planar) cosine theorem

ϕ

~xk

~xi

~xj

~x∗ = ni

ni+nj~xi +

nj

ni+nj~xj

dk∗

dij

ni

ni+njdik

nj

ni+njdjk

in its two forms (parallelogram diagonals):

(a) d2ij = d2ik + d2jk − 2dikdjk cosϕ

⇔ 2dikdjk cosϕ = d2ik + d2jk − d2ij

(b) d2k∗ =( nini + nj

dik)2

+( njni + nj

djk)2

+ 2ni

ni + njdik

njni + nj

djk cosϕ

︸ ︷︷ ︸=

ninj

(ni+nj)2

(d2ik+d

2jk−d2ij

); see (a)

=ni

ni + nj︸ ︷︷ ︸αi

d2ik +nj

ni + nj︸ ︷︷ ︸αj

d2jk−ninj

(ni + nj)2︸ ︷︷ ︸β

d2ij + 0

︸︷︷︸γ

|d2ik − d2jk|

Christian Borgelt Data Mining / Intelligent Data Analysis 535

Implementation Aspects: Single/Complete Linkage

Single Linkage:

dκk∗ =1

2dκik +

1

2dκjk −

1

2|dκik − dκjk|

=1

2dκik +

1

2dκjk +

12dκik − 1

2dκjk if dκik > dκjk,

12dκjk − 1

2dκik otherwise

= min{dκik, dκjk}

Complete Linkage:

dκk∗ =1

2dκik +

1

2dκjk +

1

2|dκik − dκjk|

=1

2dκik +

1

2dκjk +

12dκjk − 1

2dκik if dκik > dκjk,

12dκik − 1

2dκjk otherwise

= max{dκik, dκjk}

Christian Borgelt Data Mining / Intelligent Data Analysis 536

Page 135: Bibliography Data Mining / Intelligent Data Analysis ...Data Mining / Intelligent Data Analysis Christian Borgelt ... (e.g. cash registers with scanners in supermarkets, Intern et)

Choosing the Clusters

• Simplest Approach:

◦ Specify a minimum desired distance between clusters.

◦ Stop merging clusters if the closest two clustersare farther apart than this distance.

• Visual Approach:

◦ Merge clusters until all data points are combined into one cluster.

◦ Draw the dendrogram and find a good cut level.

◦ Advantage: Cut need not be strictly horizontal.

• More Sophisticated Approaches:

◦ Analyze the sequence of distances in the merging process.

◦ Try to find a step in which the distance between the two clusters merged isconsiderably larger than the distance of the previous step.

◦ Several heuristic criteria exist for this step selection.

Christian Borgelt Data Mining / Intelligent Data Analysis 537

Summary Clustering

• Prototype-based Clustering

◦ Alternating adaptation of data point assignment and cluster parameters.

◦ Online or batch adaptation of the cluster center.

◦ Crisp/hard or fuzzy/probabilistic assignment of a datum to a cluster.

◦ Local minima can pose a problem.

◦ Fuzzy/probabilistic approaches are usually more robust.

• Hierarchical Agglomerative Clustering

◦ Start with singletons (one element clusters).

◦ Always merge those clusters that are closest.

◦ Different ways to measure the distance of clusters.

◦ Cluster hierarchy can be depicted as a dendrogram.

Christian Borgelt Data Mining / Intelligent Data Analysis 538

Software

Software for

• Multipolynomial and Logistic Regression,

• Bayes Classifier Induction (naive and full),

• Decision and Regression Tree Induction,

• Artificial Neural Networks (MLPs, RBFNs),

• Learning Vector Quantization,

• Fuzzy and Probabilistic Clustering,

• Association Rule Induction and Frequent Item Set Mining

• Frequent Subgraph Mining / Molecular Fragment Mining

can be found at

http://www.borgelt.net/software.html

Christian Borgelt Data Mining / Intelligent Data Analysis 539