You are on page 1of 63

— Chapter 2 —

Getting to Know Your Data

April 7, 2019 Data Mining: Concepts and Techniques 1


What is about Data?

 General data characteristics


 Basic data description and exploration
 Measuring data similarity

April 7, 2019 Data Mining: Concepts and Techniques 2


What is Data?
Attributes
 Collection of data objects and their
attributes
Tid Refund Marital Taxable
 An attribute is a property or Status Income Cheat

characteristic of an object 1 Yes Single 125K No

 Examples: eye color of a


2 No Married 100K No

person, temperature, etc. 3 No Single 70K No

 Attribute is also known as


4 Yes Married 120K No

variable, field, characteristic, or 5 No Divorced 95K Yes


Objects
feature 6 No Married 60K No
7 Yes Divorced 220K No
 A collection of attributes describe
8 No Single 85K Yes
an object
9 No Married 75K No
 Object is also known as record,
10 No Single 90K Yes
point, case, sample, entity, or 10

instance

April 7, 2019 Data Mining: Concepts and Techniques 3


Important Characteristics of Structured Data

 Dimensionality
 Curse of dimensionality

 Sparsity vs Density
 Density counts only presence; and Sparsity,

absence
 Data Value Conflict Detection and Resolution
Patterns depend on the scale
 Similarity
 Distance measure

April 7, 2019 Data Mining: Concepts and Techniques 4


Attribute Values

 Attribute values are numbers or symbols assigned to an attribute

 Distinction between attributes and attribute values


 Same attribute can be mapped to different set of values
(different scales)
 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

 ID has no limit but age has a maximum and


minimum value
April 7, 2019 Data Mining: Concepts and Techniques 5
Types of Attributes
 Nominal
 Relating to names. The values of a nominal attribute are symbols or
names of things. Each value represents some kind of category, code, or
state, and so nominal attributes are also referred to as categorical. The
values do not have any meaningful order. E.g., profession, ID numbers,
eye color, zip codes
 Nominal values can also be represented as numbers (black hair= 0, grey
hair =1,…)
 Ordinal
 Attribute with possible values that have a meaningful order or ranking
among them, but the magnitude between successive values is not
known.
 E.g., rankings {Prof., Assistant Prof.}, grades {A, B,…} , height {tall,

medium, short}, drink size or ready-made garments size {small,


medium, and large}: The values have a meaningful sequence (which
corresponds to increasing size)
April 7, 2019 Data Mining: Concepts and Techniques 6
Types of Attribute Values
The above attributes are qualitative: they describe a feature of an object without
giving an actual size or quantity
Binary and numeric attributes are quantitative which provide quantitative
measurements of an object
 Binary
 E.g., medical test (positive vs. negative)
 Numeric: is quantitative (i.e., measurable quantity). It is represented in
integer or in real values. They can be interval-scaled or ratio-scaled.
 Interval

 measured on a scale of equal-size units. The values of interval-scaled

attributes have order and can be positive, 0, or negative. Thus, in


addition to providing a ranking of values, such attributes allow us to
compare and quantify the difference between values
 E.g., calendar dates, body temperatures (difference between 20°C
and 10°C). We cannot say that that 10°C is twice as warm as 5°C.
April 7, 2019 Data Mining: Concepts and Techniques 7
Types of Attribute Values

 Ratio
 Ratio is a numeric attribute with an inherent zero-point.
That is, if a measurement is ratio-scaled, we can speak of
a value as being a multiple (or ratio) of another value. In
addition, the values are ordered, and we can also compute
the difference between values, as well as the mean,
median, and mode.
 E.g., temperature in Kelvin, (0°K = −273.15°C: It is the
point at which the particles that comprise matter have
zero kinetic energy), counts (years_of_experience,
number_of_words in a document)

April 7, 2019 Data Mining: Concepts and Techniques 8


Properties of Attribute Values

 The type of an attribute depends on which of the following properties it


possesses:
 Distinctness: = 
 Order: < >
 Addition: + -
 Multiplication: */

 Nominal attribute: distinctness


 Ordinal attribute: distinctness & order
 Interval attribute: distinctness, order & addition
 Ratio attribute: all 4 properties

April 7, 2019 Data Mining: Concepts and Techniques 9


Attribute Description Examples Operations
Type

Nominal The values of a nominal attribute are zip codes, employee mode, entropy,
just different names, i.e., nominal ID numbers, eye color, contingency
attributes provide only enough sex: {male, female} correlation, 2 test
information to distinguish one object
from another. (=, )

Ordinal The values of an ordinal attribute hardness of minerals, median, percentiles,


provide enough information to order {good, better, best}, rank correlation,
objects. (<, >) grades, street numbers run tests, sign tests

Interval For interval attributes, the calendar dates, mean, standard


differences between values are temperature in Celsius deviation, Pearson's
meaningful, i.e., a unit of or Fahrenheit correlation, t and F
measurement exists. tests
(+, - )

Ratio For ratio variables, both differences temperature in Kelvin, geometric mean,
and ratios are meaningful. (*, /) monetary quantities, harmonic mean,
counts, age, mass, percent variation
length, electrical
current

April 7, 2019 Data Mining: Concepts and Techniques 10


Discrete vs. Continuous Attributes
 Discrete Attribute
 Has only a finite or countably infinite set of values

 E.g., zip codes, profession, or the set of words in a


collection of documents
 Sometimes, represented as integer variables

 Note: Binary attributes are a special case of discrete


attributes
 Continuous Attribute
 Has real numbers as attribute values

 Examples: temperature, height, or weight

 Practically, real values can only be measured and


represented using a finite number of digits
 Continuous attributes are typically represented as
floating-point variables
April 7, 2019 Data Mining: Concepts and Techniques 11
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

April 7, 2019 Data Mining: Concepts and Techniques 12


Record Data

 Data that consists of a collection of records, each


of which consists of a fixed set of attributes
Tid Refund Marital Taxable
Status 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 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes
10

April 7, 2019 Data Mining: Concepts and Techniques 13


Data Matrix
 If data objects have the same fixed set of numeric attributes, then the data
objects can be thought of as 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 Projection Distance Load Thickness


of x Load of y load

10.23 5.27 15.22 2.7 1.2


12.65 6.25 16.22 2.2 1.1

April 7, 2019 Data Mining: Concepts and Techniques 14


Document Data
 Each document becomes a `term' vector,
 each term is a component (attribute) of the vector,
 the value of each component is the number of times
the corresponding term occurs in the document.

timeout

season
coach

game
score
team

ball

lost
pla

wi
n
y

Document 1 3 0 5 0 2 6 0 2 0 2

Document 2 0 7 0 2 1 0 0 3 0 0

Document 3 0 1 0 0 1 2 2 0 3 0

April 7, 2019 Data Mining: Concepts and Techniques 15


Transaction Data

 A special type of record data, where


 each record (transaction) involves a set of 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, Milk
2 Beer, Bread
3 Beer, Coke, Diaper, Milk
4 Beer, Bread, Diaper, Milk
5 Coke, Diaper, Milk

April 7, 2019 Data Mining: Concepts and Techniques 16


Graph Data

 Examples: Generic graph and HTML Links


<a href="papers/papers.html#bbbb">
Data Mining </a>
<li>
2 <a href="papers/papers.html#aaaa">
Graph Partitioning </a>
5 1 <li>
2 <a href="papers/papers.html#aaaa">
Parallel Solution of Sparse Linear System of Equations </a>
5 <li>
<a href="papers/papers.html#ffff">
N-Body Computation and Dense Linear System Solvers

April 7, 2019 Data Mining: Concepts and Techniques 17


Chemical Data

 Benzene Molecule: C6H6

April 7, 2019 Data Mining: Concepts and Techniques 18


Ordered Data

 Sequences of transactions
Items/Events

An element of
the sequence

April 7, 2019 Data Mining: Concepts and Techniques 19


Ordered Data

 Genomic sequence data


GGTTCCGCCTTCAGCCCCGCGCC
CGCAGGGCCCGCCCCGCGCCGTC
GAGAAGGGCCCGCCTGGCGGGCG
GGGGGAGGCGGGGCCGCCCGAGC
CCAACCGAGTCCGACCAGGTGCC
CCCTCTGCTCGGCCTAGACCTGA
GCTCATTAGGCGGCAGCGGACAG
GCCAAGTAGAACACGCGAAGCGC
TGGGCTGCCTGCTGCGACCAGGG

April 7, 2019 Data Mining: Concepts and Techniques 20


Ordered Data

 Spatio-Temporal Data

Average Monthly
Temperature of
land and ocean

April 7, 2019 Data Mining: Concepts and Techniques 21


 General data characteristics
 Basic data description and exploration
 Measuring data similarity

April 7, 2019 Data Mining: Concepts and Techniques 22


Mining Data Descriptive Characteristics

 Motivation
 To better understand the data: central tendency, variation
and spread
 Data dispersion characteristics
 median, max, min, quantiles, outliers, variance, etc.
 Numerical dimensions correspond to sorted intervals
 Data dispersion: analyzed with multiple granularities of
precision
 Boxplot or quantile analysis on sorted intervals
 Dispersion analysis on computed measures
 Folding measures into numerical dimensions
 Boxplot or quantile analysis on the transformed cube

April 7, 2019 Data Mining: Concepts and Techniques 23


Measuring the Central Tendency
1 n x
 Mean (algebraic measure) (sample vs. population): x   xi
n i 1

N
 Weighted arithmetic mean: n

w x i i

 Trimmed mean: chopping extreme values x i 1


n

w i
 Median: A holistic measure i 1

 Middle value if odd number of values, or average of the middle two


values otherwise
 Estimated by interpolation (for grouped data):
N / 2  (  freq)l
 Mode median  L1  ( ) width
freqmedian
 Value that occurs most frequently in the data
 Unimodal, bimodal, trimodal
 Empirical formula: mean  mode  3  (mean  median)
April 7, 2019 Data Mining: Concepts and Techniques 24
Symmetric vs. Skewed Data
 Median, mean and mode of symmetric
symmetric, positively and
negatively skewed data

positively skewed negatively skewed

April 7, 2019 Data Mining: Concepts and Techniques 25


Measuring the Dispersion of Data

 Quartiles, outliers and boxplots


 Quartiles: Q1 (25th percentile), Q3 (75th percentile)
 Inter-quartile range: IQR = Q3 – Q1
 Five number summary: min, Q1, M, Q3, max
 Boxplot: ends of the box are the quartiles, median is marked, whiskers, and
plot outlier individually
 Outlier: usually, a value higher/lower than 1.5 x IQR
 Variance and standard deviation (sample: s, population: σ)
 Variance: (algebraic, scalable computation)
1 n 1 n 2 1 n n n

 [ xi  ( xi ) 2 ]
1 1
s  ( xi  x )         xi   2
2 2 2 2 2
( x )
n  1 i 1 n  1 i 1 n i 1 N i 1
i
N i 1

 Standard deviation s (or σ) is the square root of variance s2 (or σ2)

April 7, 2019 Data Mining: Concepts and Techniques 26


Boxplot Analysis

 Five-number summary of a distribution:


Minimum, Q1, M, Q3, Maximum
 Boxplot
 Data is represented with a box
 The ends of the box are at the first and third
quartiles, i.e., the height of the box is IQR
 The median is marked by a line within the box
 Whiskers: two lines outside the box extend to
Minimum and Maximum

April 7, 2019 Data Mining: Concepts and Techniques 27


Histogram Analysis

 Graph displays of basic statistical class descriptions


 Frequency histograms

 A univariate graphical method


 Consists of a set of rectangles that reflect the counts or
frequencies of the classes present in the given data

April 7, 2019 Data Mining: Concepts and Techniques 28


Histograms Often Tells More than Boxplots

 The two histograms


shown in the left may
have the same boxplot
representation
 The same values
for: min, Q1,
median, Q3, max
 But they have rather
different data
distributions

April 7, 2019 Data Mining: Concepts and Techniques 29


Quantile Plot
 Displays all of the data (allowing the user to assess both
the overall behavior and unusual occurrences)
 Plots quantile information
 For a data xi data sorted in increasing order, fi
indicates that approximately 100 fi% of the data are
below or equal to the value xi

April 7, 2019 Data Mining: Concepts and Techniques 30


Quantile-Quantile (Q-Q) Plot

 Graphs the quantiles of one univariate distribution against


the corresponding quantiles of another
 Allows the user to view whether there is a shift in going
from one distribution to another

April 7, 2019 Data Mining: Concepts and Techniques 31


Scatter plot
 Provides a first look at bivariate data to see clusters of
points, outliers, etc
 Each pair of values is treated as a pair of coordinates and
plotted as points in the plane

April 7, 2019 Data Mining: Concepts and Techniques 32


Loess Curve

 Adds a smooth curve to a scatter plot in order to


provide better perception of the pattern of dependence
 Loess curve is fitted by setting two parameters: a
smoothing parameter, and the degree of the
polynomials that are fitted by the regression

April 7, 2019 Data Mining: Concepts and Techniques 33


Positively and Negatively Correlated Data

 The left half fragment is positively


correlated
 The right half is negative correlated

April 7, 2019 Data Mining: Concepts and Techniques 34


Not Correlated Data

April 7, 2019 Data Mining: Concepts and Techniques 35


Data Visualization and Its Methods
 Why data visualization?
 Gain insight into an information space by mapping data onto
graphical primitives
 Provide qualitative overview of large data sets
 Search for patterns, trends, structure, irregularities, relationships
among data
 Help find interesting regions and suitable parameters for further
quantitative analysis
 Provide a visual proof of computer representations derived
 Typical visualization methods:
 Geometric techniques
 Icon-based techniques
 Hierarchical techniques

April 7, 2019 Data Mining: Concepts and Techniques 36


Geometric Techniques

 Visualization of geometric transformations and projections


of the data
 Methods
 Landscapes
 Projection pursuit technique
 Finding meaningful projections of multidimensional
data
 Scatterplot matrices
 Prosection views
 Hyperslice
 Parallel coordinates
April 7, 2019 Data Mining: Concepts and Techniques 37
Scatterplot Matrices

Used by ermission of M. Ward, Worcester Polytechnic Institute

Matrix of scatterplots (x-y-diagrams) of the k-dim. data

April 7, 2019 Data Mining: Concepts and Techniques 38


Landscapes
Used by permission of B. Wright, Visible Decisions Inc.

news articles
visualized as
a landscape

 Visualization of the data as perspective landscape


 The data needs to be transformed into a (possibly artificial) 2D
spatial representation which preserves the characteristics of the data
April 7, 2019 Data Mining: Concepts and Techniques 39
Parallel Coordinates
 n equidistant axes which are parallel to one of the screen axes and
correspond to the attributes
 The axes are scaled to the [minimum, maximum]: range of the
corresponding attribute
 Every data item corresponds to a polygonal line which intersects each
of the axes at the point which corresponds to the value for the
attribute

• • •

Attr. 1 Attr. 2 Attr. 3 Attr. k


April 7, 2019 Data Mining: Concepts and Techniques 40
Parallel Coordinates of a Data Set

April 7, 2019 Data Mining: Concepts and Techniques 41


Icon-based Techniques

 Visualization of the data values as features of icons


 Methods:
 Chernoff Faces
 Stick Figures
 Shape Coding:
 Color Icons:
 TileBars: The use of small icons representing the
relevance feature vectors in document retrieval

April 7, 2019 Data Mining: Concepts and Techniques 42


Chernoff Faces

 A way to display variables on a two-dimensional surface, e.g., let x be


eyebrow slant, y be eye size, z be nose length, etc.
 The figure shows faces produced using 10 characteristics--head
eccentricity, eye size, eye spacing, eye eccentricity, pupil size,
eyebrow slant, nose size, mouth shape, mouth size, and mouth
opening): Each assigned one of 10 possible values, generated using
Mathematica (S. Dickson)

 REFERENCE: Gonick, L. and Smith, W. The


Cartoon Guide to Statistics. New York:
Harper Perennial, p. 212, 1993
 Weisstein, Eric W. "Chernoff Face." From
MathWorld--A Wolfram Web Resource.
mathworld.wolfram.com/ChernoffFace.html

April 7, 2019 Data Mining: Concepts and Techniques 43


Hierarchical Techniques

 Visualization of the data using a hierarchical


partitioning into subspaces.
 Methods
 Dimensional Stacking
 Worlds-within-Worlds
 Treemap
 Cone Trees
 InfoCube

April 7, 2019 Data Mining: Concepts and Techniques 44


Tree-Map
 Screen-filling method which uses a hierarchical partitioning
of the screen into regions depending on the attribute values
 The x- and y-dimension of the screen are partitioned
alternately according to the attribute values (classes)

MSR Netscan Image

April 7, 2019 Data Mining: Concepts and Techniques 45


Tree-Map of a File System (Schneiderman)

April 7, 2019 Data Mining: Concepts and Techniques 46


 General data characteristics
 Basic data description and exploration
 Measuring data similarity (Sec. 7.2)

April 7, 2019 Data Mining: Concepts and Techniques 47


Similarity and Dissimilarity
 Similarity
 Numerical measure of how alike two data objects are

 Value is higher when objects are more alike

 Often falls in the range [0,1]

 Dissimilarity (i.e., distance)


 Numerical measure of how different are two data

objects
 Lower when objects are more alike

 Minimum dissimilarity is often 0

 Upper limit varies

 Proximity refers to a similarity or dissimilarity

April 7, 2019 Data Mining: Concepts and Techniques 48


Data Matrix and Dissimilarity Matrix
 Data matrix
 n data points with p  x11 ... x1f ... x1p 
 
dimensions  ... ... ... ... ... 
x xip 
 Two modes
... xif ...
 i1 
 ... ... ... ... ... 
x ... xnf ... xnp 
 n1 
 Dissimilarity matrix
 0 
 n data points, but
 d(2,1) 0 
registers only the  
 d(3,1) d ( 3,2) 0 
distance  
 A triangular matrix  : : : 
d ( n,1) d ( n,2) ... ... 0
 Single mode

April 7, 2019 Data Mining: Concepts and Techniques 49


Example: Data Matrix and Distance Matrix

p1
point x y
2
p1 0 2
p3 p4
1
p2 2 0
p2 p3 3 1
0 p4 5 1
0 1 2 3 4 5 6 Data Matrix

p1 p2 p3 p4
p1 0 2.828 3.162 5.099
p2 2.828 0 1.414 3.162
p3 3.162 1.414 0 2
p4 5.099 3.162 2 0

Distance Matrix (i.e., Dissimilarity Matrix) for Euclidean Distance

April 7, 2019 Data Mining: Concepts and Techniques 50


Minkowski Distance
 Minkowski distance: A popular distance measure

d (i, j)  q (| x  x |q  | x  x |q ... | x  x |q )
i1 j1 i2 j2 ip jp
where i = (xi1, xi2, …, xip) and j = (xj1, xj2, …, xjp) are two
p-dimensional data objects, and q is the order
 Properties
 d(i, j) > 0 if i ≠ j, and d(i, i) = 0 (Positive definiteness)
 d(i, j) = d(j, i) (Symmetry)
 d(i, j)  d(i, k) + d(k, j) (Triangle Inequality)
 A distance that satisfies these properties is a metric
April 7, 2019 Data Mining: Concepts and Techniques 51
Special Cases of Minkowski Distance

 q = 1: Manhattan (city block, L1 norm) distance


 E.g., the Hamming distance: the number of bits that are
different between two binary vectors
d (i, j) | x  x |  | x  x | ... | x  x |
i1 j1 i2 j 2 ip jp

 q= 2: (L2 norm) Euclidean distance


d (i, j)  (| x  x |2  | x  x |2 ... | x  x |2 )
i1 j1 i2 j2 ip jp

 q  . “supremum” (Lmax norm, L norm) distance.


 This is the maximum difference between any component of the
vectors
 Do not confuse q with n, i.e., all these distances are defined for all
numbers of dimensions.
 Also, one can use weighted distance, parametric Pearson product
moment correlation, or other dissimilarity measures
April 7, 2019 Data Mining: Concepts and Techniques 52
Example: Minkowski Distance
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
point x y
p1 0 2 L2 p1 p2 p3 p4
p2 2 0 p1 0 2.828 3.162 5.099
p3 3 1 p2 2.828 0 1.414 3.162
p4 5 1 p3 3.162 1.414 0 2
p4 5.099 3.162 2 0

L p1 p2 p3 p4
p1 0 2 3 5
p2 2 0 1 3
p3 3 1 0 2
p4 5 3 2 0

Distance Matrix

April 7, 2019 Data Mining: Concepts and Techniques 53


Binary Variables Object j
1 0 sum
 A contingency table for binary data Object i 1 a b a b
0 c d cd
sum a  c b  d p
 Distance measure for symmetric
binary variables: d (i, j)  bc
 Distance measure for asymmetric
a b c  d
binary variables: d (i, j)  bc
 Jaccard coefficient (similarity a bc
measure for asymmetric binary simJaccard (i, j)  a
variables):
a b c
 A binary variable is symmetric if
both of its states are equally
valuable and carry the same weight.
April 7, 2019 Data Mining: Concepts and Techniques 54
Dissimilarity between Binary Variables

 Example
Name Gender Fever Cough Test-1 Test-2 Test-3 Test-4
Jack M Y N P N N N
Mary F Y N P N P N
Jim M Y P N N N N
 gender is a symmetric attribute
 the remaining attributes are asymmetric binary
 let the values Y and P be set to 1, and the value N be set to 0
01
d ( jack , mary )   0.33
2 01
11
d ( jack , jim )   0.67
111
1 2
d ( jim , mary )   0.75
11 2
April 7, 2019 Data Mining: Concepts and Techniques 55
Nominal Variables

 A generalization of the binary variable in that it can take


more than 2 states, e.g., red, yellow, blue, green
 Method 1: Simple matching
 m: # of matches, p: total # of variables
d (i, j)  p 
p
m

 Method 2: Use a large number of binary variables


 creating a new binary variable for each of the M
nominal states

April 7, 2019 Data Mining: Concepts and Techniques 56


Ordinal Variables

 An ordinal variable can be discrete or continuous


 Order is important, e.g., rank
 Can be treated like interval-scaled
 replace xif by their rank rif {1,...,M f }
 map the range of each variable onto [0, 1] by replacing
i-th object in the f-th variable by
rif 1
zif 
M f 1
 compute the dissimilarity using methods for interval-
scaled variables

April 7, 2019 Data Mining: Concepts and Techniques 57


Ratio-Scaled Variables

 Ratio-scaled variable: a positive measurement on a


nonlinear scale, approximately at exponential scale,
such as AeBt or Ae-Bt
 Methods:
 treat them like interval-scaled variables—not a good
choice! (why?—the scale can be distorted)
 apply logarithmic transformation
yif = log(xif)
 treat them as continuous ordinal data treat their rank
as interval-scaled

April 7, 2019 Data Mining: Concepts and Techniques 58


Variables of Mixed Types

 A database may contain all the six types of variables


 symmetric binary, asymmetric binary, nominal, ordinal,
interval and ratio
 One may use a weighted formula to combine their effects
 pf  1 ij( f ) dij( f )
d (i, j) 
 pf  1 ij( f )
 f is binary or nominal:
dij(f) = 0 if xif = xjf , or dij(f) = 1 otherwise
 f is interval-based: use the normalized distance
 f is ordinal or ratio-scaled
 Compute ranks rif and r 1
zif  if

 Treat zif as interval-scaled M 1 f

April 7, 2019 Data Mining: Concepts and Techniques 59


Vector Objects: Cosine Similarity
 Vector objects: keywords in documents, gene features in micro-arrays, …
 Applications: information retrieval, biologic taxonomy, ...
 Cosine measure: If d1 and d2 are two vectors, then
cos(d1, d2) = (d1  d2) /||d1|| ||d2|| ,
where  indicates vector dot product, ||d||: the length 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*1+2*0+0*0+5*0+0*0+0*0+0*0+2*1+0*0+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
April 7, 2019 Data Mining: Concepts and Techniques 60
Correlation Analysis (Numerical Data)

 Correlation coefficient (also called Pearson’s product


moment coefficient)

rp ,q 
 ( p  p)( q  q)  ( pq)  n p q

(n  1) p q (n  1) p q

where n is the number of tuples, p and q are the respective


means of p and q, σp and σq are the respective standard deviation
of p and q, and Σ(pq) is the sum of the pq cross-product.
 If rp,q > 0, p and q are positively correlated (p’s values
increase as q’s). The higher, the stronger correlation.
 rp,q = 0: independent; rpq < 0: negatively correlated

April 7, 2019 Data Mining: Concepts and Techniques 61


Correlation (viewed as linear relationship)

 Correlation measures the linear relationship


between objects
 To compute correlation, we standardize data
objects, p and q, and then take their dot product

pk  ( pk  mean( p)) / std ( p)


qk  (qk  mean(q)) / std (q)

correlation( p, q)  p  q

April 7, 2019 Data Mining: Concepts and Techniques 62


Visually Evaluating Correlation

Scatter plots
showing the
similarity from
–1 to 1.

April 7, 2019 Data Mining: Concepts and Techniques 63

You might also like