P4-5 Preprocessing
P4-5 Preprocessing
Slides adopted from Jiawei Han, Computer Science, Univ. Illinois at Urbana-Champaign, 2017
1
Chapter 3: Data Preprocessing
q Data Preprocessing: An Overview
q Data Cleaning
q Data Integration
q Dimensionality Reduction
q Summary
2
What is Data Preprocessing? — Major Tasks
q Data cleaning
q Handle missing data, smooth noisy data, identify or remove outliers, and
resolve inconsistencies
q Data integration
q Integration of multiple databases, data cubes, or files
q Data reduction
q Dimensionality reduction
q Numerosity reduction
q Data compression
q Data transformation and data discretization
q Normalization
q Concept hierarchy generation
3
Why Preprocess the Data? — Data Quality Issues
q Measures for data quality: A multidimensional view
q Accuracy: correct or wrong, accurate or not
q Completeness: not recorded, unavailable, …
q Consistency: some modified but some not, dangling, …
q Timeliness: timely update?
q Believability: how trustable the data are correct?
q Interpretability: how easily the data can be understood?
4
Chapter 3: Data Preprocessing
q Data Preprocessing: An Overview
q Data Cleaning
q Data Integration
q Dimensionality Reduction
q Summary
5
Data Cleaning
qData in the Real World Is Dirty: Lots of potentially incorrect data, e.g., instrument faulty,
human or computer error, and transmission error
q Incomplete: lacking attribute values, lacking certain attributes of interest, or containing
only aggregate data
q e.g., Occupation = “ ” (missing data)
q Noisy: containing noise, errors, or outliers
q e.g., Salary = “−10” (an error)
q Inconsistent: containing discrepancies in codes or names, e.g.,
Age = “42”, Birthday = “03/07/2010”
q
q Was rating “1, 2, 3”, now rating “A, B, C”
q discrepancy between duplicate records
q Intentional (e.g., disguised missing data)
q Jan. 1 as everyone’s birthday?
6
Incomplete (Missing) Data
q Data is not always available
q E.g., many tuples have no recorded value for several attributes, such as
customer income in sales data
q Missing data may be due to
q Equipment malfunction
q Inconsistent with other recorded data and thus deleted
q Data were not entered due to misunderstanding
q Certain data may not be considered important at the time of entry
q Did not register history or changes of the data
q Missing data may need to be inferred
7
How to Handle Missing Data?
q Ignore the tuple: usually done when class label is missing (when doing
classification)—not effective when the % of missing values per attribute varies
considerably
q Fill in the missing value manually: tedious + infeasible?
q Fill in it automatically with
q a global constant : e.g., “unknown”, a new class?!
q the attribute mean
q the attribute mean for all samples belonging to the same class: smarter
q the most probable value: inference-based such as Bayesian formula or decision
tree
8
Noisy Data
q Noise: random error or variance in a measured variable
q Incorrect attribute values may be due to
q Faulty data collection instruments
q Data entry problems
q Data transmission problems
q Technology limitation
q Inconsistency in naming convention
q Other data problems
q Duplicate records
q Incomplete data
q Inconsistent data
9
How to Handle Noisy Data?
q Binning
q First sort data and partition into (equal-frequency) bins
q Then one can smooth by bin means, smooth by bin median, smooth by bin
boundaries, etc.
q Regression
q Smooth by fitting the data into regression functions
q Clustering
q Detect and remove outliers
q Semi-supervised: Combined computer and human inspection
q Detect suspicious values and check by human (e.g., deal with possible outliers)
10
Data Cleaning as a Process
q Data discrepancy detection
q Use metadata (e.g., domain, range, dependency, distribution)
q Check field overloading
q Check uniqueness rule, consecutive rule and null rule
q Use commercial tools
q Data scrubbing: use simple domain knowledge (e.g., postal code, spell-check) to
detect errors and make corrections
q Data auditing: by analyzing data to discover rules and relationship to detect violators
(e.g., correlation and clustering to find outliers)
q Data migration and integration
q Data migration tools: allow transformations to be specified
q ETL (Extraction/Transformation/Loading) tools: allow users to specify transformations
through a graphical user interface
q Integration of the two processes
q Iterative and interactive (e.g., Potter’s Wheels)
11
Chapter 3: Data Preprocessing
q Data Preprocessing: An Overview
q Data Cleaning
q Data Integration
q Dimensionality Reduction
q Summary
12
Data Integration
q Data integration
q Combining data from multiple sources into a coherent store
q Schema integration: e.g., A.cust-id º B.cust-#
q Integrate metadata from different sources
q Entity identification:
q Identify real world entities from multiple data sources, e.g., Bill Clinton =
William Clinton
q Detecting and resolving data value conflicts
q For the same real world entity, attribute values from different sources are
different
q Possible reasons: different representations, different scales, e.g., metric vs.
British units
13
Handling Redundancy in Data Integration
q Redundant data occur often when integration of multiple databases
q Object identification: The same attribute or object may have different names in
different databases
q Derivable data: One attribute may be a “derived” attribute in another table,
e.g., annual revenue
q Redundant attributes may be able to be detected by correlation analysis and
covariance analysis
q Careful integration of the data from multiple sources may help reduce/avoid
redundancies and inconsistencies and improve mining speed and quality
14
Correlation Analysis (for Categorical Data)
q Χ2 (chi-square) test:
16
Variance for Single Variable (Numerical Data)
q The variance of a random variable X provides a measure of how much the value of
X deviates from the mean or expected value of X:
ì å ( x - µ ) 2 f ( x) if X is discrete
ï
ï x
s = var( X ) = E[(X - µ ) ] = í ¥
2 2
ï ò ( x - µ ) 2 f ( x)dx if X is continuous
ï
î -¥
q where σ2 is the variance of X, σ is called standard deviation
µ is the mean, and µ = E[X] is the expected value of X
q That is, variance is the expected value of the square deviation from the mean
q It can also be written as: s 2 = var( X ) = E[(X - µ ) 2 ] = E[X 2 ] - µ 2 = E[X 2 ] - [ E ( x)]2
q Sample variance is the average squared deviation of the data value xi from the
n
sample meanµ̂ 1
sˆ = å ( xi - µˆ ) 2
2
n i =1
17
Covariance for Two Variables
q Covariance between two variables X1 and X2
s 12 = E[( X 1 - µ1 )( X 2 - µ2 )] = E[ X 1 X 2 ] - µ1µ2 = E[ X 1 X 2 ] - E[ X 1 ]E[ X 2 ]
where µ1 = E[X1] is the respective mean or expected value of X1; similarly for µ2
1 n
q Sample covariance between X1 and X2: sˆ12 = å ( xi1 - µˆ1 )( xi 2 - µˆ 2 )
n i =1
q Sample covariance is a generalization of the sample variance:
1 n 1 n
sˆ11 = å ( xi1 - µˆ1 )( xi1 - µˆ1 ) = å ( xi1 - µˆ1 ) 2 = sˆ12
n i =1 n i =1
q Positive covariance: If σ12 > 0
q Negative covariance: If σ12 < 0
q Independence: If X1 and X2 are independent, σ12 = 0 but the reverse is not true
q Some pairs of random variables may have a covariance 0 but are not independent
q Only under some additional assumptions (e.g., the data follow multivariate normal
distributions) does a covariance of 0 imply independence
18
Example: Calculation of Covariance
q Suppose two stocks X1 and X2 have the following values in one week:
q (2, 5), (3, 8), (5, 10), (4, 11), (6, 14)
q Question: If the stocks are affected by the same industry trends, will their prices
rise or fall together?
q Covariance formula
s 12 = E[( X 1 - µ1 )( X 2 - µ2 )] = E[ X 1 X 2 ] - µ1µ2 = E[ X 1 X 2 ] - E[ X 1 ]E[ X 2 ]
q Its computation can be simplified as: s 12 = E[ X 1 X 2 ] - E[ X 1 ]E[ X 2 ]
q E(X1) = (2 + 3 + 5 + 4 + 6)/ 5 = 20/5 = 4
q E(X2) = (5 + 8 + 10 + 11 + 14) /5 = 48/5 = 9.6
q σ12 = (2×5 + 3×8 + 5×10 + 4×11 + 6×14)/5 − 4 × 9.6 = 4
q Thus, X1 and X2 rise together since σ12 > 0
19
Correlation between Two Numerical Variables
q Correlation between two variables X1 and X2 is the standard covariance, obtained by
normalizing the covariance with the standard deviation of each variable
s 12 s 12
r12 = =
s 1s 2 s 12s 2 2 n
sˆ12 å (x - µˆ1 )( xi 2 - µˆ 2 )
Sample correlation for two attributes X1 and X2: rˆ
i1
q = = i =1
12
sˆ1sˆ 2 n n
å (x
i =1
i1 - µˆ1 ) 2
å (x
i =1
i2 - µˆ 2 ) 2
where n is the number of tuples, µ1 and µ2 are the respective means of X1 and X2 ,
σ1 and σ2 are the respective standard deviation of X1 and X2
q If ρ12 > 0: A and B are positively correlated (X1’s values increase as X2’s)
q The higher, the stronger correlation
q If ρ12 = 0: independent (under the same assumption as discussed in co-variance)
q If ρ12 < 0: negatively correlated
20
Visualizing Changes of Correlation Coefficient
21
Covariance Matrix
q The variance and covariance information for the two variables X1 and X2
can be summarized as 2 X 2 covariance matrix as
X 1 - µ1
S = E[( X - µ )( X - µ ) ] = E[(
T
)( X 1 - µ1 X 2 - µ2 )]
X 2 - µ2
æ E[( X 1 - µ1 )( X 1 - µ1 )] E[( X 1 - µ1 )( X 2 - µ2 )] ö
=ç ÷
è E[( X 2 - µ 2 )( X 1 - µ1 )] E[( X 2 - µ 2 )( X 2 - µ )]
2 ø
æ s 12 s 12 ö
=ç 2 ÷
è s 21 s 2 ø
q Generalizing it to d dimensions, we have,
22
Chapter 3: Data Preprocessing
q Data Preprocessing: An Overview
q Data Cleaning
q Data Integration
q Dimensionality Reduction
q Summary
23
Data Reduction
q Data reduction:
q Obtain a reduced representation of the data set
q much smaller in volume but yet produces almost the same analytical results
q Why data reduction?—A database/data warehouse may store terabytes of data
q Complex analysis may take a very long time to run on the complete data set
q Methods for data reduction (also data size reduction or numerosity reduction)
q Regression and Log-Linear Models
q Histograms, clustering, sampling
q Data cube aggregation
q Data compression
24
Data Reduction: Parametric vs. Non-Parametric Methods
q Reduce data volume by choosing alternative, smaller
forms of data representation tip vs. bill
26
Linear and Multiple Regression
q Linear regression: Y = w X + b
q Data modeled to fit a straight line
q Often uses the least-square method to fit the line
q Two regression coefficients, w and b, specify the line
and are to be estimated by using the data at hand
q Using the least squares criterion to the known values
of Y1, Y2, …, X1, X2, ….
q Nonlinear regression:
q Data are modeled by a function which is a nonlinear
combination of the model parameters and depends
on one or more independent variables
q The data are fitted by a method of successive
approximations
27
Multiple Regression and Log-Linear Models
q Multiple regression: Y = b0 + b1 X1 + b2 X2
q Allows a response variable Y to be modeled as a linear
function of multidimensional feature vector
q Many nonlinear functions can be transformed into the above
q Log-linear model:
q A math model that takes the form of a function whose
logarithm is a linear combination of the parameters of the
model, which makes it possible to apply (possibly
multivariate) linear regression
q Estimate the probability of each point (tuple) in a multi-
dimen. space for a set of discretized attributes, based on a
smaller subset of dimensional combinations
q Useful for dimensionality reduction and data smoothing
28
Histogram Analysis
40
q Divide data into buckets and store
average (sum) for each bucket 35
q Partitioning rules: 30
q Equal-width: equal bucket range 25
q Equal-frequency (or equal-depth) 20
15
10
5
0
10000 30000 50000 70000 90000
29
Clustering
q Partition data set into clusters based on similarity, and
store cluster representation (e.g., centroid and
diameter) only
q Can be very effective if data is clustered but not if data
is “smeared”
q Can have hierarchical clustering and be stored in multi-
dimensional index tree structures
q There are many choices of clustering definitions and
clustering algorithms
q Cluster analysis will be studied in depth in Chapter 10
30
Announcement 1: Registration of the Overflow Session
q For those who would like to try to register our online session of the CS412 Fall
classes
q Register before the end of Thursday (i.e., 11:59pm CT Thursday, Sept. 14)!
http://go.cs.illinois.edu/CS412OverflowSection
q Fill up all the needed information, waiting until the end of the week
q We will evaluate your application and decide if you can get into the overflown
session
31
Announcement 2: Additional Work for the 4th Credit
q Two choices, select one:
q Survey: A focused, comprehensive survey on a focused topic of data mining
q Ex. Clustering methods for heterogeneous information networks
q Research Project: Working on a research problem related to data mining and
write a paper/report, including a literature review, proposed method, datasets,
and experiment results
q Grouping: Single person or a group of maximum 3 students
q Submission on Compass2g
q One page proposal @the end of 4th week: Title, abstract, datasets, references
q Final report: similar to a conference paper, usually 10-12 pages in double
columns
q Piazza: Containing more detailed description, please raise questions on Piazza
32
Sampling
q Sampling: obtaining a small sample s to represent the whole data set N
q Allow a mining algorithm to run in complexity that is potentially sub-linear to the
size of the data
q Key principle: Choose a representative subset of the data
q Simple random sampling may have very poor performance in the presence of
skew
q Develop adaptive sampling methods, e.g., stratified sampling:
q Note: Sampling may not reduce database I/Os (page at a time)
33
Types of Sampling
q Simple random sampling: equal probability
of selecting any particular item Raw Data
OR
SR S W
ran dom
q Sampling without replacement im ple hout
( s it
m ple w t)
q Once an object is selected, it is removed sa e m en
c
from the population repla
SRSW
R
q Sampling with replacement
q A selected object is not removed from the
population
q Stratified sampling Stratified sampling
37
Wavelet Transformation
Haar2 Daubechie4
q Discrete wavelet transform (DWT) for linear signal processing, multi-resolution
analysis
q Compressed approximation: Store only a small fraction of the strongest of the
wavelet coefficients
q Similar to discrete Fourier transform (DFT), but better lossy compression, localized
in space
q Method:
q Length, L, must be an integer power of 2 (padding with 0’s, when necessary)
q Each transform has 2 functions: smoothing, difference
q Applies to pairs of data, resulting in two set of data of length L/2
q Applies two functions recursively, until reaches the desired length
38
Wavelet Decomposition
q Wavelets: A math tool for space-efficient hierarchical decomposition of functions
q 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]
q Compression: many small detail coefficients can be replaced by 0’s, and only the
significant coefficients are retained
39
Why Wavelet Transform?
q Use hat-shape filters
q Emphasize region where points cluster
q Suppress weaker information in their boundaries
q Effective removal of outliers
q Insensitive to noise, insensitive to input order
q Multi-resolution
q Detect arbitrary shaped clusters at different scales
q Efficient
q Complexity O(N)
q Only applicable to low dimensional data
40
Data Transformation
q 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
q Methods
q Smoothing: Remove noise from data
q Attribute/feature construction
q New attributes constructed from the given ones
q Aggregation: Summarization, data cube construction
q Normalization: Scaled to fall within a smaller, specified range
q min-max normalization
q z-score normalization
q normalization by decimal scaling
q Discretization: Concept hierarchy climbing
41
Normalization
q Min-max normalization: to [new_minA, new_maxA]
v - minA
v' = (new _ maxA - new _ minA) + new _ minA
maxA - minA
q Ex. Let income range $12,000 to $98,000 normalized to [0.0, 1.0]
73,600 - 12,000
q Then $73,000 is mapped to 98,000 - 12,000
(1.0 - 0) + 0 = 0.716
73,600 - 54,000
q Ex. Let μ = 54,000, σ = 16,000. Then = 1.225
16,000
q Normalization by decimal scaling
v Where j is the smallest integer such that Max(|ν’|) < 1
v'=
10 j
42
Discretization
q Three types of attributes
q Nominal—values from an unordered set, e.g., color, profession
q Ordinal—values from an ordered set, e.g., military or academic rank
q Numeric—real numbers, e.g., integer or real numbers
q Discretization: Divide the range of a continuous attribute into intervals
q Interval labels can then be used to replace actual data values
q Reduce data size by discretization
q Supervised vs. unsupervised
q Split (top-down) vs. merge (bottom-up)
q Discretization can be performed recursively on an attribute
q Prepare for further analysis, e.g., classification
43
Data Discretization Methods
q Binning
q Top-down split, unsupervised
q Histogram analysis
q Top-down split, unsupervised
q Clustering analysis
q Unsupervised, top-down split or bottom-up merge
q Decision-tree analysis
q Supervised, top-down split
q Correlation (e.g., c2) analysis
q Unsupervised, bottom-up merge
q Note: All the methods can be applied recursively
44
Simple Discretization: Binning
q Equal-width (distance) partitioning
q Divides the range into N intervals of equal size: uniform grid
q if A and B are the lowest and highest values of the attribute, the width of
intervals will be: W = (B –A)/N.
q The most straightforward, but outliers may dominate presentation
q Skewed data is not handled well
q Equal-depth (frequency) partitioning
q Divides the range into N intervals, each containing approximately same number
of samples
q Good data scaling
q Managing categorical attributes can be tricky
45
Example: Binning Methods for Data Smoothing
q Sorted data for price (in dollars): 4, 8, 9, 15, 21, 21, 24, 25, 26, 28, 29, 34
* Partition into equal-frequency (equi-depth) bins:
- Bin 1: 4, 8, 9, 15
- Bin 2: 21, 21, 24, 25
- Bin 3: 26, 28, 29, 34
* Smoothing by bin means:
- Bin 1: 9, 9, 9, 9
- Bin 2: 23, 23, 23, 23
- Bin 3: 29, 29, 29, 29
* Smoothing by bin boundaries:
- Bin 1: 4, 4, 4, 15
- Bin 2: 21, 21, 25, 25
- Bin 3: 26, 26, 26, 34
46
Discretization Without Supervision: Binning vs. Clustering
48
Concept Hierarchy Generation
q Concept hierarchy organizes concepts (i.e., attribute values) hierarchically and is
usually associated with each dimension in a data warehouse
q Concept hierarchies facilitate drilling and rolling in data warehouses to view data
in multiple granularity
q Concept hierarchy formation: Recursively reduce the data by collecting and
replacing low level concepts (such as numeric values for age) by higher level
concepts (such as youth, adult, or senior)
q Concept hierarchies can be explicitly specified by domain experts and/or data
warehouse designers
q Concept hierarchy can be automatically formed for both numeric and nominal
data—For numeric data, use discretization methods shown
49
Concept Hierarchy Generation for Nominal Data
q Specification of a partial/total ordering of attributes explicitly at the schema level
by users or experts
q street < city < state < country
q Specification of a hierarchy for a set of values by explicit data grouping
q {Urbana, Champaign, Chicago} < Illinois
q Specification of only a partial set of attributes
q E.g., only street < city, not others
q Automatic generation of hierarchies (or attribute levels) by the analysis of the
number of distinct values
q E.g., for a set of attributes: {street, city, state, country}
50
Automatic Concept Hierarchy Generation
qSome hierarchies can be automatically generated based on the analysis of the
number of distinct values per attribute in the data set
q The attribute with the most distinct values is placed at the lowest level of the
hierarchy
q Exceptions, e.g., weekday, month, quarter, year
51
Chapter 3: Data Preprocessing
q Data Preprocessing: An Overview
q Data Cleaning
q Data Integration
q Dimensionality Reduction
q Summary
52
Dimensionality Reduction
q Curse of dimensionality
q When dimensionality increases, data becomes increasingly sparse
q Density and distance between points, which is critical to clustering, outlier
analysis, becomes less meaningful
q The possible combinations of subspaces will grow exponentially
q Dimensionality reduction
q Reducing the number of random variables under consideration, via obtaining a set
of principal variables
q Advantages of dimensionality reduction
q Avoid the curse of dimensionality
q Help eliminate irrelevant features and reduce noise
q Reduce time and space required in data mining
q Allow easier visualization
53
Dimensionality Reduction Techniques
q Dimensionality reduction methodologies
q Feature selection: Find a subset of the original variables (or features, attributes)
q Feature extraction: Transform the data in the high-dimensional space to a space
of fewer dimensions
q Some typical dimensionality methods
q Principal Component Analysis
q Supervised and nonlinear techniques
q Feature subset selection
q Feature creation
54
Principal Component Analysis (PCA)
q PCA: A statistical procedure that uses an
orthogonal transformation to convert a set of
observations of possibly correlated variables into
a set of values of linearly uncorrelated variables
called principal components
q The original data are projected onto a much
smaller space, resulting in dimensionality
reduction
q Method: Find the eigenvectors of the covariance
matrix, and these eigenvectors define the new
space Ball travels in a straight line. Data from
three cameras contain much redundancy
55
Principal Component Analysis (Method)
q Given N data vectors from n-dimensions, find k ≤ n orthogonal
vectors (principal components) best used to represent data
q Normalize input data: Each attribute falls within the same range
q Compute k orthonormal (unit) vectors, i.e., principal components
q Each input data (vector) is a linear combination of the k principal
component vectors
q The principal components are sorted in order of decreasing
“significance” or strength
Ack. Wikipedia: Principal
q Since the components are sorted, the size of the data can be Component Analysis
reduced by eliminating the weak components, i.e., those with
low variance (i.e., using the strongest principal components, to
reconstruct a good approximation of the original data)
q Works for numeric data only
56
Attribute Subset Selection
q Another way to reduce dimensionality of data
q Redundant attributes
q Duplicate much or all of the information
contained in one or more other attributes
q E.g., purchase price of a product and the
amount of sales tax paid
q Irrelevant attributes
q Contain no information that is useful for the
data mining task at hand
q Ex. A student’s ID is often irrelevant to the task
of predicting his/her GPA
57
Heuristic Search in Attribute Selection
q There are 2d possible attribute combinations of d attributes
q Typical heuristic attribute selection methods:
q Best single attribute under the attribute independence assumption: choose by
significance tests
q Best step-wise feature selection:
q The best single-attribute is picked first
q Then next best attribute condition to the first, ...
q Step-wise attribute elimination:
q Repeatedly eliminate the worst attribute
q Best combined attribute selection and elimination
q Optimal branch and bound:
q Use attribute elimination and backtracking
58
Attribute Creation (Feature Generation)
q Create new attributes (features) that can capture the important information in a
data set more effectively than the original ones
q Three general methodologies
q Attribute extraction
q Domain-specific
q Mapping data to new space (see: data reduction)
q E.g., Fourier transformation, wavelet transformation, manifold approaches (not
covered)
q Attribute construction
q Combining features (see: discriminative frequent patterns in Chapter on
“Advanced Classification”)
q Data discretization
59
Summary
q Data quality: accuracy, completeness, consistency, timeliness, believability,
interpretability
q Data cleaning: e.g. missing/noisy values, outliers
q Data integration from multiple sources:
q Entity identification problem; Remove redundancies; Detect inconsistencies
q Data reduction, data transformation and data discretization
q Numerosity reduction; Data compression
q Normalization; Concept hierarchy generation
q Dimensionality reduction
60