Download Data

Document related concepts

Elementary mathematics wikipedia , lookup

Transcript
Data Mining: Data
刘淇
School of Computer Science and Technology
USTC
h
http://staff.ustc.edu.cn/~qiliuql/DM2013.html
// ff
d
/ ili l/DM2013 h l
Outline
• Attributes and Objects
• Types
T
off Data
D t
• Data Quality
• Data Preprocessing
Quick Questions?
• What are the most time consuming part in DM?
Data Preprocessing
• What is the most important step for finishing a given
DM task?
Rank 1: Data Understanding and Preprocessing
Rank 2: Domain Knowledge Discovery
Rank 3: Visualization
Rank 4: Alogrithm
3
Simple Comparison
Medical Care
Data Mining
First Concern
First Concern
Patient&
P
ti t&
symptoms
M di i
Medicine
Data
D
t &
Applications
Al
Algorithms
ith
4
What is Data?
Attributes
• Collection of data objects
and their attributes
¾ Examples: eye color of a
person, temperature, etc.
¾ Attribute is also known as
variable, field, characteristic,
or feature
f t
• A collection of attributes
describe an object
Objjects
• An attribute is a property or
characteristic
h
t i ti off an object
bj t
¾ Object is also known as
record, point, case, sample,
entity, or instance
Tid Refund Marital
Status
Taxable
Income Cheat
1
Yes
Single
125K
No
2
No
Married
100K
No
3
No
Single
70K
No
4
Yes
Married
120K
No
5
No
Divorced 95K
Yes
6
No
Married
No
7
Yes
Divorced 220K
No
8
No
Single
85K
Yes
9
No
Married
75K
No
Single
90K
Yes
10 No
10
60K
Attribute Values
• Attribute values are numbers or symbols assigned
to an attribute for a particular object
• Distinction between attributes and attribute values
¾ Same attribute can be mapped to different attribute
values
‹
Example: height can be measured in feet or meters
¾ Different attributes can be mapped to the same set of
values
‹
‹
Example: Attribute values for ID and age are integers
But properties of attribute values can be different
Measurement of Length
• The way you measure an attribute may not match the
p p
attributes properties.
5
A
1
B
7
This scale
preserves
only the
ordering
property of
length.
2
C
8
3
D
10
4
E
15
5
This scale
preserves
the ordering
and additive
properties of
length.
Types of Attributes
• There are different types of attributes
¾Nominal 标称
‹
Examples: ID numbers, eye color, zip codes
¾Ordinal 序数
‹
Examples: rankings (e.g., taste of potato chips on a
scale from
f
1-10),
) grades, height in {{tall, medium, short}}
¾Interval 区间
‹
Examples: calendar dates, temperatures in Celsius or
Fahrenheit.
¾R ti 比例
¾Ratio
‹
Examples: temperature in Kelvin, length, time, counts
Properties of Attribute Values
• The type of an attribute depends on which of the
following properties it possesses:
¾ Distinctness:
= ≠
¾ Order:
Od
< >
¾ Addition:
+ ¾ Multiplication:
*/
¾ Nominal
N i l attribute:
ib
di
distinctness
i
¾ Ordinal attribute: distinctness & order
¾ Interval attribute: distinctness, order & addition
¾ Ratio attribute: all 4 properties
Difference Between Ratio and
Interval
• Is it physically meaningful to say that a
temperature of 10 ° degrees twice that of 5°
5 on
¾ the Celsius scale?
¾ the
th F
Fahrenheit
h h it scale?
l ?
¾ the Kelvin scale?
• Consider measuring the height above average
¾ If Bill’s height is three inches above average and
Bob’s height is six inches above average, then would
we say that
th t B
Bob
b iis ttwice
i as ttallll as B
Bob?
b?
¾ Is this situation analogous to that of temperature?
Cattegorical
Qualitative
Attribute Description
Type
Nominal
Nominal attribute
values only
distinguish. (=, ≠)
zip codes, employee
ID numbers, eye
l sex: {{male,
l
color,
female}
Ordinal
Ordinal attribute
values also order
objects.
(< >)
(<,
For interval
attributes,
differences between
values are
meaningful. (+, - )
For ratio variables,
both differences and
ratios are
meaningful. (*, /)
hardness of minerals,
minerals
{good, better, best},
grades, street
numbers
calendar dates,
temperature in
Celsius or Fahrenheit
Interval
Numeric
c
Quantitativ
ve
Examples
Ratio
Operations
mode, entropy,
contingency
correlation, χ2
test
median,
median
percentiles, rank
correlation, run
tests sign tests
tests,
mean, standard
deviation,
Pearson's
correlation, t and
F tests
temperature in Kelvin, geometric mean,
monetary quantities,
harmonic mean,
counts, age, mass,
percent variation
length, current
This categorization of attributes is due to S. S. Stevens
Numeric
Q
Quantitat
tive
Cate
egorical
Qua
alitative
Attribute Transformation
Type
Comments
Nominal
Any permutation of values
If all employee ID numbers
were reassigned, would it
make any
an difference?
Ordinal
An order preserving change of
values ii.e.,
values,
e
new_value = f(old_value)
where f is a monotonic function
An attribute encompassing
the notion of good
good, better best
can be represented equally
well by the values {1, 2, 3} or
by { 0.5, 1, 0}.
Interval
new_value =a * old_value + b
where a and b are constants
Ratio
new value = a * old_value
new_value
old value
Thus, the Fahrenheit and
Celsius temperature scales
differ in terms of where
here their
zero value is and the size of a
unit (degree).
Length can be measured in
meters or feet.
This categorization of attributes is due to S. S. Stevens
Discrete and Continuous Attributes
• Discrete Attribute
¾ Has onlyy a finite or countablyy infinite set of values
¾ Examples: zip codes, counts, or the set of words in a collection
of documents
¾ Often represented as integer variables.
variables
¾ Note: binary attributes are a special case of discrete attributes
• Continuous Attribute
¾ Has real numbers as attribute values
¾ Examples:
p
temperature,
p
, height,
g , or weight.
g
¾ Practically, real values can only be measured and represented
using a finite number of digits.
¾ Continuous
C ti
attributes
tt ib t are typically
t i ll represented
t d as flfloatingti
point variables.
Asymmetric Attributes
• Only presence (a non-zero attribute value) is regarded as
important
• Examples:
¾ Words present in documents
¾ Items present in customer transactions
• If we met a friend in the grocery store would we ever say
the following?
“II see our purchases are very similar since we didn
didn’tt buy most
of the same things.”
• We need two asymmetric binary attributes to represent
one ordinary binary attribute
¾ Association analysis uses asymmetric attributes
Important Characteristics of Structured Data
¾Dimensionality
‹
Curse of Dimensionality
¾Sparsity
‹
Only presence counts
¾Resolution
‹
P tt
Patterns
depend
d
d on th
the scale
l
Types of data sets
• Record
¾ Data Matrix
¾ Document Data
¾ Transaction Data
• Graph
¾ World Wide Web
¾ Molecular Structures
• Ordered
¾ Spatial Data
¾ Temporal Data
¾ Sequential Data
¾ Genetic Sequence Data
Record Data
• Data that consists of a collection of records, each of
which consists of a fixed set of attributes
10
Tid Refund Marital
Status
Taxable
Income Cheat
1
Yes
Single
125K
No
2
No
Married
100K
No
3
No
Single
70K
No
4
Yes
Married
120K
No
5
N
No
Di
Divorced
d 95K
Y
Yes
6
No
Married
No
7
Yes
Divorced 220K
No
8
No
Single
85K
Yes
9
No
Married
75K
No
10
No
Single
90K
Yes
60K
Data Matrix
• If data objects have the same fixed set of numeric
attributes then the data objects can be thought of as
attributes,
points in a multi-dimensional space, where each
dimension represents a distinct attribute
• Such data set can be represented by an m by n matrix,
where there are m rows, one for each object, and n
columns, one for each attribute
Projection
of x Load
Projection
of y load
Distance
Load
Thickness
10.23
5.27
15.22
2.7
1.2
12 65
12.65
6 25
6.25
16 22
16.22
22
2.2
11
1.1
Document Data
• Each document becomes a `term' vector,
¾ each term is a component (attribute) of the vector
vector,
¾ the value of each component is the number of times the
corresponding term occurs in the document.
Transaction Data
• A special type of record data, where
¾ each record (transaction) involves a set of items
items.
¾ For example, consider a grocery store. The set of
products purchased by a customer during one shopping
trip constitute a transaction, while the individual products
that were purchased are the items.
TID
Items
1
Bread Coke
Bread,
Coke, Milk
2
3
4
5
Beer, Bread
Beer Coke,
Beer,
Coke Diaper,
Diaper Milk
Beer, Bread, Diaper, Milk
Coke Diaper
Coke,
Diaper, Milk
Graph Data
• Examples: Generic graph, a Moleule, and Webpages
2
1
5
2
5
Benzene Molecule: C6H6
Ordered Data
• Sequences of transactions
Items/Events
t1
t2
Customer 1
Customer 1
Customer 1
An element of
the sequence
th
t3
Ordered Data
• Genomic sequence data
GGTTCCGCCTTCAGCCCCGCGCC
CGCAGGGCCCGCCCCGCGCCGTC
GAGAAGGGCCCGCCTGGCGGGCG
GGGGGAGGCGGGGCCGCCCGAGC
CCAACCGAGTCCGACCAGGTGCC
CCCTCTGCTCGGCCTAGACCTGA
GCTCATTAGGCGGCAGCGGACAG
GCCAAGTAGAACACGCGAAGCGC
TGGGCTGCCTGCTGCGACCAGGG
Ordered Data
• Spatio-Temporal Data
Average Monthly
Temperature of
land and ocean
Data Quality
• Poor data quality negatively affects many data processing
efforts
“The most important point is that poor data quality is an unfolding
disaster.
¾ Poor data quality costs the typical company at least ten percent
(10%) of revenue; twenty percent (20%) is probably a better
estimate.”
ti t ”
Thomas C. Redman, DM Review, August 2004
• Data mining example: a classification model for detecting
people who are loan risks is built using poor data
¾ Some credit-worthy candidates are denied loans
¾ More loans are given to individuals that default
Data Quality …
• What kinds of data quality problems?
• How can we detect problems with the data?
• What can we do about these problems?
• Examples of data quality problems:
¾ Noise and outliers
¾ Missing
Mi i values
l
¾ Duplicate data
Noise
• Noise refers to modification of original values
¾ Examples: distortion of a person’s
person s voice when talking on
a poor phone and “snow” on television screen
Two Sine Waves
Two Sine Waves + Noise
Outliers
• Outliers are data objects with characteristics that
are considerably different than most of the other
data objects in the data set
¾ Case 1: Outliers are
noise that interferes
with data analysis
¾ Case 2: Outliers are
the goal of our analysis
‹
‹
Credit card fraud
I t i detection
Intrusion
d t ti
Missing Values
• Reasons for missing values
¾ Information is not collected
(e.g., people decline to give their age and weight)
¾ Attributes may not be applicable to all cases
(
(e.g.,
annuall iincome iis nott applicable
li bl tto children)
hild )
• Handling missing values
¾ Eliminate data objects
¾ Estimate missing values
‹ Example:
time series of temperature
‹ Example:
p census results
¾ Ignore the missing value during analysis
Duplicate Data
• Data set may include data objects that are
duplicates, or almost duplicates of one another
¾ Major issue when merging data from heterogeous
sources
• Examples:
¾ Same person with multiple email addresses
• Data cleaning
¾ Process
P
off dealing
d li with
ith d
duplicate
li t d
data
t iissues
Data Preprocessing
• Aggregation
• Sampling
S
li
• Dimensionalityy Reduction
• Feature subset selection
• Feature creation
• Discretization and Binarization
• Attribute Transformation
Aggregation
• Combining two or more attributes (or objects) into a
single attribute (or object)
• Purpose
P
¾ Data reduction
‹
Reduce the number off attributes or objects
¾ Change of scale
‹
Citi aggregated
Cities
t d iinto
t regions,
i
states,
t t
countries,
ti
etc
t
¾ More “stable” data
‹
A
Aggregated
t d data
d t tends
t d to
t have
h
less
l
variability
i bilit
Example: Precipitation in Australia
• This example is based on precipitation in Australia
from the period 1982 to 1993.
The next slide shows
¾ A histogram for the standard deviation of average
monthly precipitation for 3,030 0.5◦ by 0.5◦ grid cells in
Australia, and
¾ A histogram for the standard deviation of the average
yearly precipitation for the same locations.
• The average yearly precipitation has less variability
than the average
g monthly
yp
precipitation.
p
• All precipitation measurements (and their standard
deviations) are in centimeters
centimeters.
Example: Precipitation in Australia …
Variation of Precipitation in Australia
Standard Deviation of Average
Monthly Precipitation
Standard Deviation of
Average Yearly Precipitation
Sampling
• Sampling is the main technique employed for data
selection.
selection
¾ It is often used for both the preliminary investigation of
y
the data and the final data analysis.
• Statisticians sample
p because obtaining
g the entire
set of data of interest is too expensive or time
consuming.
Sampling …
• The key principle for effective sampling is the
following:
¾ Using a sample will work almost as well as using the
entire data sets, if the sample is representative
¾ A sample is representative if it has approximately the
same p
property
p y ((of interest)) as the original
g
set of data
Sample Size
8000 points
2000 Points
500 Points
Types of Sampling
• Simple Random Sampling
¾ There is an equal probability of selecting any particular
item
¾ Sampling without replacement
‹ As each item is selected, it is removed from the
population
¾ Sampling
S
li with
ith replacement
l
t
‹ Objects are not removed from the population as they
are selected for the sample
sample.
– In sampling with replacement, the same object
can be picked up more than once
• Stratified sampling
¾ Split the data into several partitions; then draw random
samples from each partition
Exercise
• 老师为了研究男女同学的数据挖掘学习情况、对某班
12名同学(男8女4)采取了分层抽样的方法,抽取 个
12名同学(男8女4)采取了分层抽样的方法,抽取一个
样本容量为3的样本进行研究,某女同学甲被抽到的
概率是多少?某男同学乙被抽到的概率是多少?
• 若用随机 抽样法(无放回抽样),某女同学甲恰好
抽样法(无放回抽样) 某女同学甲恰好
被抽到一次的概率是多少?
• 扩充:若用随机 抽样法(有放回抽样),该样本中
恰好有一个女生的概率是多少?
39
Sample Size
• What sample size is necessary to get at least one
object from each of 10 equal
equal-sized
sized groups.
Exercise-2
• 有10个样本有放回随机抽取30次,每个样本都能被
抽到至少 次的概率是多大?
抽到至少一次的概率是多大?
41
Curse of Dimensionality
• When dimensionality
increases data becomes
increases,
increasingly sparse in the
space that it occupies
• Definitions of density and
distance between points,
which is critical for
clustering and outlier
detection, become less
meaningful
• Randomly generate 500 points
• Compute difference between max and
min
i distance
di t
between
b t
any pair
i off points
i t
Dimensionality Reduction
• Purpose:
¾ Avoid curse of dimensionalityy
¾ Reduce amount of time and memory required by data
mining algorithms
¾ Allow data to be more easily visualized
¾ May help to eliminate irrelevant features or reduce noise
• Techniques
¾ Principal Components Analysis (PCA)
¾ Singular Value Decomposition
¾ Others: supervised and non
non-linear
linear techniques
Dimensionality Reduction: PCA
• Goal is to find a projection that captures the largest
amount of variation in data
x2
e
x1
PCA 主成分分析
• PCA (Principal Components Analysis)
¾ 目的:数据降维、去噪
目的:数据降维 去噪
¾ 思想:将原始的高维(如维度为N)数据向一个较低维度
(如维度为K)的空间投影,同时使得数据之间的区分度
变大。这K维空间的每一个维度的基向量(坐标)就是一
个主成分
¾ 问题:如何找到这K个主成分
¾ 思路:使用方差信息,若在一个方向上发现数据分布的方
差越大,则说明该投影方向越能体现数据中的主要信息。
该投影方向即应当是一个主成分
K=1
45
PCA 主成分分析
• 原理:假设X是一个2*M的数据矩阵(M是数据样本个数), xi是其中一个2维
的数据样本。如果我们想将这些数据X从2维降低到1维,则:
•
推广:
¾ 第K个主成分就是第K大的特征值对应的特征向量
¾ 对于原始的N
对于原始的N*M(N维M个样本)的数据
M(N维M个样本)的数据,原始存储空间是N
原始存储空间是N*M
M,PCA以后为:K
PCA以后为:K*M(M个K
M(M个K
维样本)+N*K(K个特征向量)
46
PCA 主成分分析
• 基本计算思路
•
•
•
•
•
1.对每个样本提取出属性组成一个数字向量
对每个样本提取出属性组成 个数字向量
2.对所有样本里的每个属性的取值进行归一化(按属性归一化),以消除不
同属性的取值范围等不同带来的影响,得到一个N*M样本矩阵(归一化);
3 该矩阵乘以该矩阵的逆为协方差矩阵 这个协方差矩阵是可对角化的 对
3.该矩阵乘以该矩阵的逆为协方差矩阵,这个协方差矩阵是可对角化的,对
角化后剩下的元素为特征值,每个特征值对应一个特征向量(特征向量要标
准化);
4.选取最大的K个特征值(其中K即为PCA的主元(PC)数,K越少,越降
低数据量,但信息丢失也越大,识别效果也越差),将这K个特征值对应的
特征向量组成新的矩阵;
5.将新的矩阵转置后乘以样本向量即可得到降维后的数据(这些数据是原数
据中相对较为主要的,而数据量一般也远远小于原数据量)。
47
PCA 主成分分析
数据归一化
三个主成分
48
Dimensionality Reduction: PCA
Feature Subset Selection
• Another way to reduce dimensionality of data
• Redundant features
¾ Duplicate much or all of the information contained in one
or more other attributes
¾ Example: purchase price of a product and the amount of
sales tax paid
• Irrelevant
I l
features
f
¾ Contain no information that is useful for the data mining
task at hand
¾ Example: students' ID is often irrelevant to the task of
predicting students'
students GPA
• Many techniques developed, especially for
classification
Feature Creation
• Create new attributes that can capture the
important information in a data set much more
efficiently than the original attributes
• Three general methodologies:
¾ Feature extraction
‹
Example: extracting edges from images
¾ Feature construction
‹
Example: dividing mass by volume to get density
¾ Mapping data to new space
‹
Example: Fourier and wavelet analysis
Mapping Data to a New Space
z
Fourier and wavelet transform
Frequency
Two Sine Waves + Noise
Frequency
Discretization
• Discretization is the process of converting a
continuous attribute into an ordinal attribute
¾ A potentially infinite number of values are mapped into a
small number of categories
g
¾ Discretization is commonly used in classification
¾Many classification algorithms work best if both the
independent and dependent variables have only a
few values
¾We give an illustration of the usefulness of
discretization using
g the Iris data set
Iris Sample Data Set
• Many of the exploratory data techniques are illustrated
with the Iris Plant data set
set.
¾ Can be obtained from the UCI Machine Learning Repository
http://www.ics.uci.edu/~mlearn/MLRepository.html
¾ From the statistician Douglas Fisher
¾ Three flower types (classes):
‹ Setosa
‹ Virginica
‹ Versicolour
V i l
¾ Four (non-class) attributes
‹ Sepal width and length
Virginica. Robert H. Mohlenbrock. USDA
‹ Petal width and length
NRCS. 1995. Northeast wetland flora: Field
office guide to plant species. Northeast National
T h i l Center,
Technical
C
Chester,
Ch
PA.
PA Courtesy
C
off
USDA NRCS Wetland Science Institute.
Discretization: Iris Example
Petal width low or petal length low implies Setosa.
P t l width
Petal
idth medium
di
or petal
t l llength
th medium
di
iimplies
li V
Versicolour.
i l
Petal width high or petal length high implies Virginica.
Discretization: Iris Example …
• How can we tell what the best discretization is?
¾ Unsupervised
p
discretization: find breaks in the data
values
‹ Example:
50
Petal Length
Coun
nts
40
30
20
10
0
0
2
4
6
Petal Length
8
¾ Supervised discretization: Use class labels to find breaks
Discretization Without Using Class Labels
Data consists of four groups of points and two outliers. Data is onedimensional but a random y component is added to reduce overlap.
dimensional,
overlap
Discretization Without Using Class Labels
Equal
q
interval width approach
pp
used to obtain 4 values.
Discretization Without Using Class Labels
Equal
q
frequency
q
y approach
pp
used to obtain 4 values.
Discretization Without Using Class Labels
K-means approach
pp
to obtain 4 values.
Binarization
• Binarization maps a continuous or categorical
attribute into one or more binaryy variables
• Typically used for association analysis
• Often convert a continuous attribute to a categorical
attribute and then convert a categorical attribute to
a set of binary attributes
¾ Association analysis needs asymmetric binary attributes
p
eye
y color and height
g measured as
¾ Examples:
{low, medium, high}
Attribute Transformation
• An attribute transform is a function that maps the
entire set of values of a given attribute to a new
set of replacement values such that each old
value can be identified with one of the new
values
¾Simple
¾Si
l ffunctions:
ti
xk, log(x),
l ( ) ex, |x|
| |
¾Normalization
‹ Refers
to various techniques to adjust to
differences among attributes in terms of frequency
of occurrence,
occurrence mean
mean, variance,
variance magnitude
¾ In statistics, standardization refers to subtracting off
the means and dividing by the standard deviation
Example: Sample Time Series of Plant Growth
Minneapolis
Net Primary
y
Production (NPP)
is a measure of
plant growth used
by ecosystem
scientists.
Correlations between time series
Correlations between
time series
Minneapolis
Minneapolis
1.0000
Atlanta
0.7591
Sao Paolo
-0.7581
0.7581
Atlanta
0.7591
1.0000
-0.5739
0.5739
Sao Paolo
-0.7581
-0.5739
1.0000
Seasonality Accounts for Much Correlation
Minneapolis
Normalized using
monthly Z Score:
Subtract off monthly
mean and divide by
monthly standard
deviation
Correlations between time series
Correlations between time series
Minneapolis
Minneapolis
1.0000
Atlanta
0.0492
Sao Paolo
0.0906
Atlanta
0.0492
1.0000
-0.0154
Sao Paolo
0.0906
-0.0154
1.0000
Outline of Second Lecture for
p 2
Chapter
• Basics of Similarity and Dissimilarity Measures
• Distances and Their Properties
• Similarities and Their Properties
p
• Density
Similarity and Dissimilarity Measures
• Similarity measure
¾ Numerical measure of how alike two data objects are
are.
¾ Is higher when objects are more alike.
¾ Often falls in the range [0
[0,1]
1]
• Dissimilarity measure
¾ Numerical
N
i l measure off h
how diff
differentt are ttwo d
data
t objects
bj t
¾ Lower when objects are more alike
¾ Minimum
Mi i
dissimilarity
di i il it iis often
ft 0
¾ Upper limit varies
• Proximity refers to a similarity or dissimilarity
Similarity/Dissimilarity for Simple
Attributes
p and q are the corresponding attribute values for two data
objects.
Euclidean Distance
• Euclidean Distance
dist =
n
2
(
p
−
q
)
∑ k
k
k =1
Where n is the number of dimensions (attributes) and
pk and qk are,
are respectively,
respectively the kth attributes
(components) or data objects p and q.
z
Standardization is necessary, if scales differ.
Euclidean Distance
3
point
p1
p2
p3
p4
p
p1
2
p3
p4
1
p2
0
0
1
2
3
4
5
p1
p1
p2
p
p3
p4
0
2.828
3.162
5.099
x
0
2
3
5
y
2
0
1
1
6
p2
2.828
0
1.414
3.162
Distance Matrix
p3
3.162
1.414
0
2
p4
5.099
3.162
2
0
Minkowski Distance
• Minkowski Distance is a generalization of Euclidean
Distance
n
dist = ( ∑ | pk − qk
k =1
1
r r
|)
Where r is
Wh
i a parameter, n is
i the
h number
b off di
dimensions
i
(attributes) and pk and qk are, respectively, the kth
attributes ((components)
p
) or data objects
j
p and q
q.
Minkowski Distance: Examples
• r = 1. City block (Manhattan, taxicab, L1 norm) distance.
¾ A common example of this is the Hamming distance,
distance which
is just the number of bits that are different between two
binary vectors
• r = 2. Euclidean distance
• r → ∞. “supremum” (Lmax norm, L∞ norm) distance.
¾ This is the maximum difference between anyy component
p
of
the vectors
• D
Do nott confuse
f
r with
ith n, i.e.,
i
allll th
these di
distances
t
are
defined for all numbers of dimensions.
Minkowski Distance
point
p1
p2
p3
p4
x
0
2
3
5
y
2
0
1
1
L1
p1
p2
p3
p4
p1
0
4
4
6
p2
4
0
2
4
p3
4
2
0
2
p4
6
4
2
0
L2
p1
p2
p3
p4
p1
p2
2.828
0
1.414
3.162
p3
3.162
1.414
0
2
p4
5.099
3.162
2
0
L∞
p1
p2
p
p3
p4
p1
p2
p3
p4
0
2.828
3.162
5.099
0
2
3
5
2
0
1
3
Di t
Distance
Matrix
M ti
3
1
0
2
5
3
2
0
Mahalanobis Distance
−1
mahalanobi s ( p , q ) = ( p − q ) ∑ ( p − q )
T
Σ is the covariance matrix
of the input data X
Σ j ,k
1 n
=
∑ ( X ij − X j )( X ik − X k )
n − 1 i =1
Determining
D
t
i i similarity
i il it off an
unknown Sample set to a known
one. It takes Into account the
correlations of the Data set and
is scale-invariant.
F red
For
d points,
i t the
th Euclidean
E lid
di
distance
t
iis 14
14.7,
7 M
Mahalanobis
h l
bi di
distance
t
is
i 6.
6
Mahalanobis Distance
Covariance
Matrix:
C
⎡ 0.3 0.2⎤
Σ=⎢
⎥
⎣0.2 0.3⎦
A: (0
(0.5,
5 0
0.5)
5)
B
B: (0, 1)
A
C: (1.5, 1.5)
Mahal(A,B) = 5
Mahal(A,C) = 4
Common Properties of a Distance
•
Distances, such as the Euclidean distance,
have some well known properties
properties.
1. d(p, q) ≥ 0 for all p and q and d(p, q) = 0 only if
p = q.
q (Positive definiteness)
2. d(p, q) = d(q, p) for all p and q. (Symmetry)
3. d(p,
(p, r)) ≤ d(p,
(p, q) + d(q,
(q, r)) for all p
points p, q, and r.
(Triangle Inequality)
where d(p,
(p, q) is the distance ((dissimilarity)
y) between
points (data objects), p and q.
•
A distance that satisfies these properties is a
metric
Common Properties of a Similarity
•
Similarities, also have some well known
properties.
properties
1. s(p,
(p q) = 1 ((or maximum similarity)
y) onlyy if p = q
q.
2. s(p, q) = s(q, p) for all p and q. (Symmetry)
where s(p, q) is the similarity between points (data
objects), p and q.
Similarity Between Binary Vectors
•
Common situation is that objects, p and q, have only
binaryy attributes
•
Compute similarities using the following quantities
F01 = the number of attributes where p was 0 and q was 1
F10 = the number of attributes where p was 1 and q was 0
F00 = the number of attributes where p was 0 and q was 0
F11 = the number of attributes where p was 1 and q was 1
•
Simple Matching and Jaccard Coefficients
SMC = number of matches / number of attributes
= (F11 + F00) / (F01 + F10 + F11 + F00)
J
= number
u be o
of 11 matches
atc es / number
u be o
of non-zero
o e o att
attributes
butes
= (F11) / (F01 + F10 + F11)
SMC versus Jaccard: Example
p= 1000000000
q= 0000001001
F01 = 2
F01 = 1
F00 = 7
F11 = 0
SMC
(the number of attributes where p was 0 and q was 1)
(the number of attributes where p was 1 and q was 0)
(the number of attributes where p was 0 and q was 0)
(the number of attributes where p was 1 and q was 1)
= (F11 + F00) / (F01 + F10 + F11 + F00)
= (0+7) / (2+1+0+7) = 0.7
J = (F11) / (F01 + F10 + F11) = 0 / (2 + 1 + 0) = 0
Cosine Similarity
• If d1 and d2 are two document vectors, then
cos( d1, d2 ) = (d1 • d2) / ||d1|| ||d2|| ,
where • indicates vector dot product and || d || is the
length
g of vector d.
• Example:
d1 = 3 2 0 5 0 0 0 2 0 0
d2 = 1 0 0 0 0 0 0 1 0 2
d1 • d2= 3
3*1
1 + 2*0
2 0 + 0*0
0 0 + 5*0
5 0 + 0*0
0 0 + 0*0
0 0 + 0*0
0 0 + 2*1
2 1 + 0*0
0 0 + 0*2
0 2=5
||d1|| = (3*3+2*2+0*0+5*5+0*0+0*0+0*0+2*2+0*0+0*0)0.5 = (42) 0.5 = 6.481
||d2|| = (1*1+0*0+0*0+0*0+0*0+0*0+0*0+1*1+0*0+2*2) 0.5 = (6) 0.5 = 2.245
cos( d1, d2 ) = .3150
Extended Jaccard Coefficient (Tanimoto)
• Variation of Jaccard for continuous or count
attributes
¾ Reduces to Jaccard for binary attributes
Correlation
• Correlation measures the linear relationship
between objects
• To compute correlation, we standardize data
objects p and q
objects,
q, and then take their dot product
pk′ = ( pk − mean( p)) / std ( p)
qk′ = ( qk − mean( q)) / std ( q)
correlation( p, q) = p′ • q′ /(n − 1)
Visually Evaluating Correlation
Scatter plots
showing
h i
the
th
similarity from
–1
1 to 1.
Drawback of Correlation
• X = (-3, -2, -1, 0, 1, 2, 3)
• Y = (9, 4, 1, 0, 1, 4, 9)
Y = X2
• Mean(X) = 0, Mean(Y) = 4
• Correlation
= (-3)(5)+(-2)(0)+(-1)(-3)+(0)(-4)+(1)(-3)+(2)(0)+3(5)
=0
General Approach for Combining Similarities
Sometimes attributes are of many different types, but an
overall similarity is needed
needed.
1: For the kth attribute, compute a similarity, sk(x, y), in the
range [0
[0, 1]
1].
2: Define an indicator variable, δk, for the kth attribute as
follows:
•
δk = 0 if the kth attribute is an asymmetric attribute and
j
have a value of 0,, or if one of the objects
j
both objects
has a missing value for the kth attribute
δk = 1 otherwise
3. Compute
Using Weights to Combine Similarities
• May not want to treat all attributes the same.
¾ Use weights wk which are between 0 and 1 and sum to 1
1.
Density
• Measures the degree to which data objects are close to
each other in a specified area
• The notion of density is closely related to that of proximity
• Concept
p of density
y is typically
yp
y used for clustering
g and
anomaly detection
• Examples:
¾ Euclidean density
‹
Euclidean density = number of points per unit volume
¾ Probability density
‹
Estimate what the distribution of the data looks like
¾ Graph-based density
‹ Connectivity
y
Euclidean Density: Grid-based Approach
• Simplest approach is to divide region into a number of
rectangular
t
l cells
ll off equall volume
l
and
dd
define
fi d
density
it as
# of points the cell contains
Grid-based density.
Counts for each cell.
Euclidean Density: Center-Based
• Euclidean density is the number of points within
a specified
ifi d radius
di off th
the point
i t
Illustration of center
center-based
based density
density.