Unit 3
Unit 3
Unit 3
1
UNIT – 3
Data Preprocessing: Overview, Data Cleaning, Data
Integration, Data Reduction, Data Transformation
and Data Discretization.
1-2
Data Quality: Why Preprocess the
Data?
4
Data Cleaning
Data in the Real World Is Dirty: Lots of potentially incorrect
data, e.g., instrument faulty, human or computer error,
transmission error
incomplete: lacking attribute values, lacking certain
attributes of interest, or containing only aggregate data
e.g., Occupation=“ ” (missing data)
noisy: containing noise, errors, or outliers
e.g., Salary=“−10” (an error)
inconsistent: containing discrepancies in codes or names,
e.g.,
Age=“42”, Birthday=“03/07/2010”
Was rating “1, 2, 3”, now rating “A, B, C”
discrepancy between duplicate records
Intentional (e.g., disguised missing data)
5
Incomplete (Missing) Data
Data is not always available
E.g., many tuples have no recorded value for
several attributes, such as customer income in
sales data
Missing data may be due to
equipment malfunction
inconsistent with other recorded data and thus
deleted
data not entered due to misunderstanding
certain data may not be considered important
at the time of entry
not register history or changes of the data
6
How to Handle Missing
Data?
Ignore the tuple: usually done when class label is
missing (when doing classification)—not effective
when the % of missing values per attribute varies
considerably
Fill in the missing value manually: tedious +
infeasible?
Fill in it automatically with
a global constant : e.g., “unknown”, a new
class?!
the attribute mean
the attribute mean for all samples belonging to
the same class: smarter 7
Noisy Data
Noise: random error or variance in a measured
variable
Incorrect attribute values may be due to
faulty data collection instruments
technology limitation
incomplete data
inconsistent data
8
How to Handle Noisy Data?
Binning
first sort data and partition into (equal-
frequency) bins
then one can smooth by bin means, smooth by
functions
Clustering
detect and remove outliers
distribution)
Check field overloading
Data scrubbing: use simple domain knowledge (e.g.,
postal code, spell-check) to detect errors and make
corrections
Data auditing: by analyzing data to discover rules and
relationship to detect violators (e.g., correlation and
clustering to find outliers)
Data migration and integration
Data migration tools: allow transformations to be specified
13
Chi-Square Calculation: An
Example
i 1 (ai A)(bi B)
n n
(ai bi ) n AB
rA, B i 1
(n 1) A B (n 1) A B
15
Visually Evaluating Correlation
Scatter plots
showing the
similarity from
–1 to 1.
16
Correlation (viewed as linear
relationship)
Correlation measures the linear relationship
between objects
To compute correlation, we standardize
data objects, A and B, and then take their
dot product
a 'k (ak mean( A)) / std ( A)
17
Covariance (Numeric Data)
Covariance is similar to correlation
Correlation coefficient:
Suppose two stocks A and B have the following values in one week: (2, 5), (3,
8), (5, 10), (4, 11), (6, 14).
Question: If the stocks are affected by the same industry trends, will their
prices rise or fall together?
E(A) = (2 + 3 + 5 + 4 + 6)/ 5 = 20/5 = 4
E(B) = (5 + 8 + 10 + 11 + 14) /5 = 48/5 = 9.6
Cov(A,B) = (2×5+3×8+5×10+4×11+6×14)/5 − 4 × 9.6 = 4
Thus, A and B rise together since Cov(A, B) > 0.
Data Reduction Strategies
Data reduction: Obtain a reduced representation of the data
set that is much smaller in volume but yet produces the same
(or almost the same) analytical results
Why data reduction? — A database/data warehouse may store
terabytes of data. Complex data analysis may take a very
long time to run on the complete data set.
Data reduction strategies
Dimensionality reduction, e.g., remove unimportant
attributes
Wavelet transforms
Principal Components Analysis (PCA)
Feature subset selection, feature creation
Numerosity reduction (some simply call it: Data Reduction)
Regression and Log-Linear Models
Histograms, clustering, sampling
Data cube aggregation
Data compression
20
Data Reduction 1: Dimensionality
Reduction
Curse of dimensionality
When dimensionality increases, data becomes increasingly sparse
Density and distance between points, which is critical to
clustering, outlier analysis, becomes less meaningful
The possible combinations of subspaces will grow exponentially
Dimensionality reduction
Avoid the curse of dimensionality
Help eliminate irrelevant features and reduce noise
Reduce time and space required in data mining
Allow easier visualization
Dimensionality reduction techniques
Wavelet transforms
Principal Component Analysis
Supervised and nonlinear techniques (e.g., feature selection)
21
Mapping Data to a New Space
Fourier transform
Wavelet transform
22
What Is Wavelet Transform?
Decomposes a signal into
different frequency subbands
Applicable to n-dimensional
signals
Data are transformed to
preserve relative distance
between objects at different
levels of resolution
Allow natural clusters to
become more distinguishable
Used for image compression
23
Wavelet
Transformation
Haar2 Daubechie4
Discrete wavelet transform (DWT) for linear signal
processing, multi-resolution analysis
Compressed approximation: store only a small
fraction of the strongest of the wavelet coefficients
Similar to discrete Fourier transform (DFT), but
better lossy compression, localized in space
Method:
Length, L, must be an integer power of 2 (padding with
0’s, when necessary)
Each transform has 2 functions: smoothing, difference
Applies to pairs of data, resulting in two set of data of
length L/2
Applies two functions recursively, until reaches the
24 desired
Wavelet Decomposition
Wavelets: A math tool for space-efficient
hierarchical decomposition of functions
S = [2, 2, 0, 2, 3, 5, 4, 4] can be transformed to S^
= [23/4, -11/4, 1/2, 0, 0, -1, -1, 0]
Compression: many small detail coefficients can
be replaced by 0’s, and only the significant
coefficients are retained
25
Haar Wavelet Coefficients
Coefficient
Hierarchical “Supports”
2.75
decomposition 2.75 +
structure (a.k.a. +
“error tree”) + -1.25
-
-1.25
+ -
0.5
+
0.5
- +
0
- 0
+
-
0 -1 -1 0
+
-
+ + 0
- - + - + -
-
+
-+
-+
2 2 0 2 3 5 4 4
1-1
Multi-resolution
Detect arbitrary shaped clusters at different
scales
Efficient
Complexity O(N)
x1
28
Principal Component Analysis
(Steps)
Given N data vectors from n-dimensions, find k ≤ n
orthogonal vectors (principal components) that can be best
used to represent data
Normalize input data: Each attribute falls within the same
range
Compute k orthonormal (unit) vectors, i.e., principal
components
Each input data (vector) is a linear combination of the k
principal component vectors
The principal components are sorted in order of decreasing
“significance” or strength
Since the components are sorted, the size of the data can
be reduced by eliminating the weak components, i.e.,
those with low variance (i.e., using the strongest principal 29
Attribute Subset Selection
Another way to reduce dimensionality of data
Redundant attributes
Duplicate much or all of the information
contained in one or more other attributes
E.g., purchase price of a product and the
amount of sales tax paid
Irrelevant attributes
Contain no information that is useful for the
data mining task at hand
E.g., students' ID is often irrelevant to the task
of predicting students' GPA
30
Heuristic Search in Attribute
Selection
There are 2d possible attribute combinations of d
attributes
Typical heuristic attribute selection methods:
Best single attribute under the attribute
The best single-attribute is picked first
Then next best attribute condition to the
first, ...
Step-wise attribute elimination:
Repeatedly eliminate the worst attribute
Best combined attribute selection and elimination
31
Attribute Creation (Feature
Generation)
Create new attributes (features) that can capture
the important information in a data set more
effectively than the original ones
Three general methodologies
Attribute extraction
Domain-specific
Mapping data to new space (see: data
reduction)
E.g., Fourier transformation, wavelet
transformation, manifold approaches (not
covered)
Attribute construction
Combining features (see: discriminative
frequent patterns in Chapter 7) 32
Data Reduction 2: Numerosity
Reduction
Reduce data volume by choosing alternative,
smaller forms of data representation
Parametric methods (e.g., regression)
Assume the data fits some model, estimate
sampling, …
33
Parametric Data Reduction:
Regression and Log-Linear
Models
Linear regression
Data modeled to fit a straight line
line
Multiple regression
Allows a response variable Y to be modeled as
probability distributions
34
y
Regression Analysis
Y1
Regression analysis: A collective name for
techniques for the modeling and analysis of Y1’
y=x+1
numerical data consisting of values of a
dependent variable (also called response
variable or measurement) and of one or more X1 x
independent variables (aka. explanatory
variables or predictors) Used for prediction
The parameters are estimated so as to give a (including forecasting of
"best fit" of the data time-series data),
inference, hypothesis
Most commonly the best fit is evaluated by
testing, and modeling of
using the least squares method, but other
causal relationships
criteria have also been used
35
Regress Analysis and Log-
Linear Models
Linear regression: Y = w X + b
Two regression coefficients, w and b, specify the line and
are to be estimated by using the data at hand
Using the least squares criterion to the known values of Y1,
Y2, …, X1, X2, ….
Multiple regression: Y = b0 + b1 X1 + b2 X2
Many nonlinear functions can be transformed into the
above
Log-linear models:
Approximate discrete multidimensional probability
distributions
Estimate the probability of each point (tuple) in a multi-
dimensional space for a set of discretized attributes, based
36
Histogram Analysis
Divide data into buckets 40
and store average (sum) 35
for each bucket 30
Partitioning rules: 25
Equal-width: equal 20
bucket range
15
Equal-frequency (or 10
equal-depth)
5
0
10000
20000
30000
40000
50000
60000
70000
80000
90000
100000
37
Clustering
Partition data set into clusters based on similarity,
and store cluster representation (e.g., centroid
and diameter) only
Can be very effective if data is clustered but not if
data is “smeared”
Can have hierarchical clustering and be stored in
multi-dimensional index tree structures
There are many choices of clustering definitions
and clustering algorithms
Cluster analysis will be studied in depth in
Chapter 10
38
Sampling
particular item
Sampling without replacement
Once an object is selected, it is removed from
the population
Sampling with replacement
A selected object is not removed from the
population
Stratified sampling:
Partition the data set, and draw samples from
40
Sampling: With or without
Replacement
W O R
SRS le random
i m p ho ut
( s e wi t
l
sa m p m e nt )
p l a ce
re
SRSW
R
Raw Data
41
Sampling: Cluster or Stratified
Sampling
42
Data Cube Aggregation
algorithms
Typically lossless, but only limited manipulation is
refinement
Sometimes small fragments of signal can be
os sy
l
Original Data
Approximated
45
Data Transformation
A function that maps the entire set of values of a given
attribute to a new set of replacement values s.t. each old
value can be identified with one of the new values
Methods
Smoothing: Remove noise from data
Attribute/feature construction
New attributes constructed from the given ones
Aggregation: Summarization, data cube construction
Normalization: Scaled to fall within a smaller, specified
range
min-max normalization
z-score normalization
normalization by decimal scaling 46
Normalization
Min-max normalization: to [new_minA, new_maxA]
v minA
v' (new _ maxA new _ minA) new _ minA
maxA minA
Ex. Let income range $12,000 to $98,000 normalized to [0.0, 1.0].
73,600 12,000
(1.0 0) 0 0.716
Then $73,000 is mapped to 98,000 12,000
73,600 54,000
Ex. Let μ = 54,000, σ = 16,000. Then 1.225
16,000
Normalization by decimal scaling
v
v' j Where j is the smallest integer such that Max(|ν’|) < 1
10
47
Discretization
Three types of attributes
Nominal—values from an unordered set, e.g., color,
profession
Ordinal—values from an ordered set, e.g., military or
academic rank
Numeric—real numbers, e.g., integer or real numbers
Discretization: Divide the range of a continuous attribute into
intervals
Interval labels can then be used to replace actual data
values
Reduce data size by discretization
Supervised vs. unsupervised
Split (top-down) vs. merge (bottom-up)
Discretization can be performed recursively on an attribute 48
Data Discretization Methods
Typical methods: All the methods can be applied
recursively
Binning
Top-down split, unsupervised
Histogram analysis
Top-down split, unsupervised
Clustering analysis (unsupervised, top-down split
or bottom-up merge)
Decision-tree analysis (supervised, top-down
split)
Correlation (e.g., 2) analysis (unsupervised,
49
Simple Discretization: Binning
51
Class Labels
(Binning vs. Clustering)
Methods
Summary
57
What Is Frequent Pattern
Analysis?
Frequent pattern: a pattern (a set of items, subsequences,
substructures, etc.) that occurs frequently in a data set
First proposed by Agrawal, Imielinski, and Swami [AIS93] in the
context of frequent itemsets and association rule mining
Motivation: Finding inherent regularities in data
What products were often purchased together?— Beer and
diapers?!
What are the subsequent purchases after buying a PC?
What kinds of DNA are sensitive to this new drug?
Can we automatically classify web documents?
Applications
Basket data analysis, cross-marketing, catalog design, sale
campaign analysis, Web log (click stream) analysis, and DNA 58
Why Is Freq. Pattern Mining
Important?
Freq. pattern: An intrinsic and important property of
datasets
Foundation for many essential data mining tasks
Association, correlation, and causality analysis
analysis
Cluster analysis: frequent pattern-based
clustering
Data warehousing: iceberg cube and cube-
gradient
59
Basic Concepts: Frequent
Patterns
Tid Items bought itemset: A set of one or
10 Beer, Nuts, Diaper more items :beer , nuts,
20 Beer, Coffee, Diaper diaper
30 Beer, Diaper, Eggs k-itemset X = {x1, …, xk}
40 Nuts, Eggs, Milk (absolute) support, or,
50 Nuts, Coffee, Diaper, Eggs, Milk
support count of X:
Customer
Frequency or occurrence of
Customer
buys both buys diaper
an itemset X
Eg: (beer=3)
(relative) support, s, is the
fraction of transactions
that contains X (i.e., the
Customer probability that a
buys beer
transaction contains X)
Eg:x=beer (10,20,30) 60
Basic Concepts: Association
Rules
Ti Items bought
d
Find all the rules X Y with
10 Beer, Nuts, Diaper
minimum support and
20 Beer, Coffee, Diaper
30 Beer, Diaper, Eggs confidence
40 Nuts, Eggs, Milk support, s, probability that
50 Nuts, Coffee, Diaper, Eggs,
Milk
a transaction contains X
Customer
Customer Y
buys both
buys confidence, c, conditional
diaper
probability that a
transaction having X also
Customer contains Y
buys beer Let
Association
minsup = 50%, rules: (many
minconf = 50%
Freq.more!)
Pat.: Beer:3, Nuts:3, Diaper:4,
Beer
Eggs:3,
Diaper
{Beer, (60%,
Diaper}:3
100%)
61
62
No of distinct item sets= 2n − 1
63
64
65
C-closed NC-not closed
66
67
A-frequent
B-frequent
C-frequent
E-frequent
AB-frequent
ABC-frequent
ABCE-frequent(max)
68
69
Min support=2
Total
transactions=4
70
Only 1 superset
71
Closed Patterns and Max-
Patterns
A long pattern contains a combinatorial number of
sub-patterns, e.g., {a1, …, a100} contains (1001) +
(1002) + … + (110000) = 2100 – 1 = 1.27*1030 sub-
patterns!
Solution: Mine closed patterns and max-patterns
instead
An itemset X is closed if X is frequent and there
exists no super-pattern Y כX, with the same
support as X (proposed by Pasquier, et al. @
ICDT’99)
An itemset X is a max-pattern if X is frequent and
there exists no frequent super-pattern Y כX
(proposed by Bayardo @ SIGMOD’98) 72
Closed Patterns and Max-
Patterns
Exercise. DB = {<a1, …, a100>, < a1, …,
a50>}
Min_sup = 1.
What is the set of closed itemset?
<a1, …, a100>: 1
< a1, …, a50>: 2
What is the set of max-pattern?
<a1, …, a100>: 1
What is the set of all patterns?
!! 73
Computational Complexity of Frequent
Itemset Mining
How many itemsets are potentially to be generated in the worst
case?
The number of frequent itemsets to be generated is senstive to
the minsup threshold
When minsup is low, there exist potentially an exponential
number of frequent itemsets
The worst case: MN where M: # distinct items, and N: max
length of transactions
The worst case complexty vs. the expected probability
Ex. Suppose Walmart has 104 kinds of products
The chance to pick up one product 10-4
The chance to pick up a particular set of 10 products: ~10-
40
What is the chance this particular set of 10 products to be
frequent 103 times in 109 transactions? 74
Chapter 5: Mining Frequent Patterns,
Association and Correlations: Basic
Concepts and Methods
Basic Concepts
Methods
Summary
75
Scalable Frequent Itemset Mining
Methods
Approach
Approach
frequent
If {beer, diaper, nuts} is frequent, so is {beer,
diaper}
i.e., every transaction having {beer, diaper, nuts}
@SIGMOD’00)
Vertical data format approach (Charm—Zaki &
Hsiao @SDM’02)
77
Apriori: A Candidate Generation & Test
Approach
C3 Itemset
3 scan
rd L3 Itemset sup
{B, C, E} {B, C, E} 2
79
The Apriori Algorithm
(Pseudo-Code)
Ck: Candidate itemset of size k
Lk : frequent itemset of size k
L1 = {frequent items};
for (k = 1; Lk !=; k++) do begin
Ck+1 = candidates generated from Lk;
for each transaction t in database do
increment the count of all candidates in Ck+1
that are contained in t
Lk+1 = candidates in Ck+1 with min_support
end
return k Lk; 80
81
82
83
84
85
Mod 7? Table size=10 (max prime no we have take from the given table size
86
87
88
89
90
91
92
93
94
95
96
97
98
Minimum support count=2
M=2(no of parts)[T100,T200] & )[T300,T400]
99
100
101
102
103
104
Data set Sample(s) Search items in s not in D
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Implementation of Apriori
Subset function
Transaction: 1 2 3 5 6
3,6,9
1,4,7
2,5,8
1+2356
13+56 234
567
145 345 356 367
136 368
357
12+356
689
124
457 125 159
458
124
Candidate Generation: An SQL
Implementation
SQL Implementation of candidate generation
Suppose the items in Lk-1 are listed in an order
Step 1: self-joining Lk-1
insert into Ck
select p.item1, p.item2, …, p.itemk-1, q.itemk-1
from Lk-1 p, Lk-1 q
where p.item1=q.item1, …, p.itemk-2=q.itemk-2, p.itemk-1 <
q.itemk-1
Step 2: pruning
forall itemsets c in Ck do
forall (k-1)-subsets s of c do
if (s is not in Lk-1) then delete c from Ck
Use object-relational extensions like UDFs, BLOBs, and Table
functions for efficient implementation [See: S. Sarawagi, S. Thomas,
and R. Agrawal. Integrating association rule mining with relational
database systems: Alternatives and implications. SIGMOD’98]
125
Scalable Frequent Itemset Mining
Methods
Format
127
Partition: Scan Database
Only Twice
Any itemset that is potentially frequent in DB must
be frequent in at least one of the partitions of DB
Scan 1: partition database and find local
frequent patterns
Scan 2: consolidate global frequent patterns
… 10 {yz, qs,
2Hash
wt}
Table
Frequent 1-itemset: a, b, d, e
ab is not a candidate 2-itemset if the sum of count of {ab,
ad, ae} is below support threshold
J. Park, M. Chen, and P. Yu. An effective hash-based algorithm
for mining association rules. SIGMOD’95
129
Sampling for Frequent Patterns
ABCD
Once both A and D are determined frequent,
the counting of AD begins
ABC ABD ACD BCD Once all length-2 subsets of BCD are
determined frequent, the counting of BCD
begins
AB AC BC AD BD CD
Transactions
1-itemsets
A B C D
Apriori 2-itemsets
…
{}
Itemset lattice 1-itemsets
2-items
S. Brin R. Motwani, J. Ullman,
and S. Tsur. Dynamic itemset DIC 3-items
counting and implication
rules for market basket data.
SIGMOD’97 131
Scalable Frequent Itemset Mining
Methods
Format
Patterns containing p
…
Pattern f
135
Find Patterns Having P From P-conditional
Database
base
Construct the FP-tree for the frequent items of
{}
Cond. pattern base of “cam”: (f:3) f:3
cam-conditional FP-tree
138
A Special Case: Single Prefix Path
in FP-tree
C2:k2 C3:k3
a3:n3 C2:k2 C3:k3
139
Benefits of the FP-tree Structure
Completeness
Preserve complete information for frequent
pattern mining
Never break a long pattern of any transaction
Compactness
Reduce irrelevant info—infrequent items are gone
Items in frequency descending order: the more
frequently occurring, the more likely to be shared
Never be larger than the original database (not
count node-links and the count field)
140
The Frequent Pattern Growth Mining
Method
Idea: Frequent pattern growth
Recursively grow frequent patterns by pattern
conditional FP-tree
Until the resulting FP-tree is empty, or it contains
141
Scaling FP-growth by Database
Projection
What about if FP-tree cannot fit in memory?
DB projection
First partition a database into a set of projected DBs
Then construct and mine FP-tree for each projected DB
Parallel projection vs. partition projection techniques
Parallel projection
Project the DB in parallel for each frequent item
Parallel projection is space costly
All the partitions can be processed in parallel
Partition projection
Partition the DB based on the ordered frequent items
Passing the unprocessed parts to the subsequent
partitions
142
Partition-Based Projection
am-proj DB cm-proj DB
fc f …
fc f
fc f
143
Performance of FPGrowth in Large
Datasets
100
140
90 D1 FP-grow th runtime D2 FP-growth
80
D1 Apriori runtime 120 D2 TreeProjection
70 100
Run time(sec.)
Runtime (sec.)
60
80
50 Data set T25I20D10K Data set T25I20D100K
40 60
30 40
20
20
10
0 0
0 0.5 1 1.5 2 2.5 3 0 0.5 1 1.5 2
Support threshold(%)
Support threshold (%)
144
Advantages of the Pattern Growth
Approach
Divide-and-conquer:
Decompose both the mining task and DB according to
the frequent patterns obtained so far
Lead to focused search of smaller databases
Other factors
No candidate generation, no candidate test
Compressed database: FP-tree structure
No repeated scan of entire database
Basic ops: counting local freq items and building sub FP-
tree, no pattern search and matching
A good open-source implementation and refinement of
FPGrowth
FPGrowth+ (Grahne and J. Zhu, FIMI'03)
145
Further Improvements of Mining
Methods
146
Extension of Pattern Growth Mining
Methodology
Mining closed frequent itemsets and max-patterns
CLOSET (DMKD’00), FPclose, and FPMax (Grahne & Zhu,
Fimi’03)
Mining sequential patterns
PrefixSpan (ICDE’01), CloSpan (SDM’03), BIDE (ICDE’04)
Pattern-growth-based Clustering
MaPle (Pei, et al., ICDM’03)
Pattern-Growth-Based Classification
Mining frequent and discriminative patterns (Cheng, et al,
147
Scalable Frequent Itemset Mining
Methods
Format
Format
155
Visualization of Association Rules: Rule
Graph
156
Visualization of Association
Rules
(SGI/MineSet 3.0)
157
Chapter 5: Mining Frequent Patterns,
Association and Correlations: Basic
Concepts and Methods
Basic Concepts
Methods
Summary
158
Interestingness Measure:
Correlations (Lift)
159
Are lift and 2 Good Measures of
Correlation?
160
Null-Invariant Measures
161
Comparison of Interestingness
Measures