DATA & DATA PREPROCESSING
PART 2
ITS61504 Data Mining
Outline
o General data characteristics
o Why preprocess the data?
Data cleaning
o Data integration
o Data transformation
o Data reduction
o Summary
2
Data Cleaning
o To clean data from:
Incomplete /missing data
Noisy data
Inconsistent /outliers
o Importance
“Data cleaning is one of the three biggest problems in data
warehousing”—Ralph Kimball
“Data cleaning is the number one problem in data warehousing”—DCI
survey
o Data cleaning tasks
Fill in missing values
Identify outliers and smooth out noisy data
Correct inconsistent data
Resolve redundancy caused by data integration
3
Missing Data
o Data is not always available
E.g., many tuples have no recorded value for several attributes, such as
customer income in sales data
o 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
o Missing data may need to be inferred
4
How to Handle Missing Data?
o Ignore the tuple: usually done when class label is missing (when doing
classification)—not effective when the % of missing values per attribute
varies considerably
o Fill in the missing value manually: tedious + infeasible?
o 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
the most probable value: inference-based such as Bayesian formula or
decision tree
5
Noisy Data
o Noise: random error or variance in a measured variable
o Incorrect attribute values may due to
faulty data collection instruments
data entry problems
data transmission problems
technology limitation
inconsistency in naming convention
o Other data problems which requires data cleaning
duplicate records
incomplete data
inconsistent data
6
How to Handle Noisy Data?
o Binning/Discretization
first sort data and partition into (equal-frequency) bins
then one can smooth by bin means, smooth by bin median, smooth by
bin boundaries, etc.
o Regression
smooth by fitting the data into regression functions
o Clustering
detect and remove outliers
o Combined computer and human inspection
detect suspicious values and check by human (e.g., deal with possible
outliers)
7
Simple Discretization Methods - Binning
o Equal-width (distance) partitioning
Divides the range into N intervals of equal size: uniform grid
if A and B are the lowest and highest values of the attribute, the width of
intervals will be: W = (B –A)/N.
The most straightforward, but outliers may dominate presentation
Skewed data is not handled well
o Equal-depth (frequency) partitioning
Divides the range into N intervals, each containing approximately same
number of samples
Good data scaling
Managing categorical attributes can be tricky
8
Binning Methods for Data Smoothing
o Sorted data for price (in dollars):
4, 8, 9, 15, 21, 21, 24, 25, 26, 28, 29, 34
o Partition into (equi-depth) 4 bins:
Bin 1: 4, 8, 9, 15
Bin 2: 21, 21, 24, 25
Bin 3: 26, 28, 29, 34
o Smoothing by bin means:
Bin 1: 9, 9, 9, 9
Bin 2: 23, 23, 23, 23
Bin 3: 29, 29, 29, 29
o Smoothing by bin boundaries:
Bin 1: 4, 4, 4, 15
Bin 2: 21, 21, 25, 25
Bin 3: 26, 26, 26, 34
9
Regression
Y1
Y1’ y=x+1
X1 x
10
Cluster Analysis
11
Data Cleaning as a Process
o Data discrepancy detection
Use metadata (e.g., domain, range, dependency, distribution)
Check field overloading
Check uniqueness rule, consecutive rule and null rule
Use commercial tools
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)
o Data migration and integration
Data migration tools: allow transformations to be specified
ETL (Extraction/Transformation/Loading) tools: allow users to specify
transformations through a graphical user interface
o Integration of the two processes
Iterative and interactive (e.g., Potter’s Wheels)
12
Outline
o General data characteristics
o Why preprocess the data?
o Data cleaning
Data integration
o Data transformation
o Data reduction
o Summary
13
Data Integration
o Data integration:
Combines data from multiple sources into a coherent store
o Schema integration: e.g., [Link]-id ≡ [Link]-#
Integrate metadata from different sources
o Entity identification problem:
Identify real world entities from multiple data sources, e.g., Bill Clinton =
William Clinton
o Detecting and resolving data value conflicts
For the same real world entity, attribute values from different sources
are different
Possible reasons: different representations, different scales, e.g., metric vs.
British units
14
Handling Redundancy in Data Integration
o Redundant data occur often when integration of multiple databases
Object identification: The same attribute or object may have different
names in different databases
Derivable data: One attribute may be a “derived” attribute in another
table, e.g., annual revenue
o Redundant attributes may be able to be detected by correlation analysis &
covariance analysis
o Careful integration of the data from multiple sources may help
reduce/avoid redundancies and inconsistencies and improve mining speed
and quality
15
Correlation Analysis (Numerical Data)
o 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.
o If rp,q > 0, p and q are positively correlated (p’s values increase as q’s). The
higher, the stronger correlation.
o rp,q = 0: independent
o rpq < 0: negatively correlated
16
Correlation (viewed as linear relationship)
o Correlation measures the linear o Visually Evaluating Correlation
relationship between objects
o Scatter plots showing the
o To compute correlation, we similarity from –1 to 1.
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′
17
Correlation Analysis (Categorical Data)
o Χ2 (chi-square) test
(Observed − Expected ) 2
χ =∑
2
Expected
o The larger the Χ2 value, the more likely the variables are related
o The cells that contribute the most to the Χ 2 value are those whose actual
count is very different from the expected count
o Correlation does not imply causality
# of hospitals and # of car-theft in a city are correlated
Both are causally linked to the third variable: population
Correlation relationship # of hospitals and # of car-theft (setting the
direction; coincidence???)
But no causal relationship between # of hospitals and & # of car-theft
Causal relationship (hidden) # of hospitals & population / # of car-
theft & population
18
Chi-Square Calculation: An Example
Play chess Not play chess Sum (row)
Like science fiction 250 200 450
Not like science fiction 50 1000 1050
Sum(col.) 300 1200 1500
(250 − 90) 2 (50 − 210) 2 (200 − 360) 2 (1000 − 840) 2
χ =
2
+ + + = 507.93
90 210 360 840
For this 2 × 2 table, the degrees of freedom are .2 − 1/.2 − 1/ D 1.
For 1 degree of freedom, the χ2 value needed to reject the hypothesis
at the 0.001 significance level is 10.828
19
Chi-Square Calculation: An Example
Observed Play chess Not play chess Sum (row)
Like science fiction 250 200 450
Not like science fiction 50 1000 1050
Sum(col.) 300 1200 1500
Expected
Play chess Not play chess Sum (row)
Like science fiction 300 x 450 1200 x 450 450
1500 1500
=90 =360
Not like science fiction 300 x 1050 1200 x 1050 1050
1500 1500
=210 =840
Sum(col.) 300 1200 1500
20
Chi-Square Calculation: An Example
(250 − 90) 2 (50 − 210) 2 (200 − 360) 2 (1000 − 840) 2
χ =
2
+ + + = 507.93
90 210 360 840
21
Covariance (Numeric Data)
o Covariance is similar to correlation
Correlation coefficient:
where n is the number of tuples, A and B are the respective mean or
expected values of A and B, σA and σB are the respective standard deviation
of A and B.
o Positive covariance: If CovA,B > 0, then A and B both tend to be larger than
their expected values.
o Negative covariance: If CovA,B < 0 then if A is larger than its expected value, B
is likely to be smaller than its expected value.
o Independence: CovA,B = 0 but the converse is not true:
Some pairs of random variables may have a covariance of 0 but are not independent.
Only under some additional assumptions (e.g., the data follow multivariate normal
distributions) does a covariance of 0 imply independence
22
Co-Variance: An Example
o It can be simplified in computation as
o Suppose two stocks A and B have the following values in one week: (2, 5), (3,
8), (5, 10), (4, 11), (6, 14).
o Question: If the stocks are affected by the same industry trends, will their
Covariance indicates the
prices rise or fall together? direction of the linear
relationship between
E(A) = (2 + 3 + 5 + 4 + 6)/ 5 = 20/5 = 4 variables. Correlation
measures both the
strength and direction of
E(B) = (5 + 8 + 10 + 11 + 14) /5 = 48/5 = 9.6 the linear relationship
between two variables.
Cov(A,B) = (2×5+3×8+5×10+4×11+6×14)/5 − 4 × 9.6 = 4
o Thus, A and B rise together since Cov(A, B) > 0.
Outline
o General data characteristics
o Why preprocess the data?
o Data cleaning
o Data integration
Data transformation
o Data reduction
o Summary
24
Data Transformation
o A function that maps the entire set of values of a given attribute to a new
set of replacement values. So, each old value can be identified with one of
the new values
o Methods
Smoothing: Remove noise from data
Aggregation: Summarization, data cube construction
Generalization: Concept hierarchy climbing
Normalization: Scaled to fall within a small, specified range
min-max normalization
z-score normalization
normalization by decimal scaling
Attribute/feature construction
New attributes constructed from the given ones
25
Data Transformation: Normalization
o 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]. Then
$73,000 is mapped to 73,600 − 12,000
(1.0 − 0) + 0 = 0.716
98,000 − 12,000 Decimal scaling. Suppose that the
recorded values of A range from -986 to
o Z-score normalization (μ: mean, σ: standard deviation): 917. The maximum absolute value of A is
986. To normalize by decimal scaling, we
v − µA therefore divide each value by 1000 (i.e., j
v' = D 3) so that -986 normalizes to -0.986 and
σ A
917 normalizes to 0.917.
73,600 − 54,000
Ex. Let μ = 54,000, σ = 16,000. Then = 1.225
16,000
o Normalization by decimal scaling
v
v' = j Where j is the smallest integer such that Max(|ν’|) < 1
10
26
Z-Score (Example)
v v’ v v’
0.18 -0.84 Avg 0.68 20 -.26 Avg 34.3
0.60 -0.14 sdev 0.59 40 .11 sdev 55.9
0.52 -0.27 5 .55
0.25 -0.72 70 4
0.80 0.20 32 -.05
0.55 -0.22 8 -.48
0.92 0.40 5 -.53
0.21 -0.79 15 -.35
0.64 -0.07 250 3.87
0.20 -0.80 32 -.05
0.63 -0.09 18 -.30
0.70 0.04 10 -.44
0.67 -0.02 -14 -.87
0.58 -0.17 22 -.23
0.98 0.50 45 .20
0.81 0.22 60 .47
0.10 -0.97 -5 -.71
0.82 0.24 7 -.49
0.50 -0.30 2 -.58
3.00 3.87 4 -.55
27
Discretization
o 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
o 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
Prepare for further analysis, e.g., classification
28
Data Discretization Methods
o 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, bottom-up merge)
29
Simple Discretization: Binning
o Equal-width (distance) partitioning
Divides the range into N intervals of equal size: uniform grid
if A and B are the lowest and highest values of the attribute, the width of intervals
will be: W = (B –A)/N.
The most straightforward, but outliers may dominate presentation
Skewed data is not handled well
[For example, if the values range from 0 to 100, and we want 10 bins, each bin will have a width of 10.]
o Equal-depth (frequency) partitioning [For example, if we have 100 observations and we want
10 bins, each bin will have 10 observations.]
Divides the range into N intervals, each containing approximately same number of
samples
Good data scaling
Managing categorical attributes can be tricky
30
Binning Methods for Data Smoothing
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
31
Discretization Without Using Class Labels
(Binning vs. Clustering)
Data Equal interval width (binning)
Equal frequency (binning) K-means clustering leads to better results
32
Discretization by Classification &
Correlation Analysis
o Classification (e.g., decision tree analysis)
Supervised: Given class labels, e.g., cancerous vs. benign
Using entropy to determine split point (discretization point)
Top-down, recursive split
o Correlation analysis (e.g., Chi-merge: χ2-based discretization)
Supervised: use class information
Bottom-up merge: find the best neighboring intervals (those having similar
distributions of classes, i.e., low χ2 values) to merge
Merge performed recursively, until a predefined stopping condition
33
Concept Hierarchy Generation
o Concept hierarchy organizes concepts (i.e., attribute values) hierarchically
and is usually associated with each dimension in a data warehouse
o Concept hierarchies facilitate drilling and rolling in data warehouses to view
data in multiple granularity
o 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)
o Concept hierarchies can be explicitly specified by domain experts and/or data
warehouse designers
o Concept hierarchy can be automatically formed for both numeric and nominal
data. For numeric data, use discretization methods shown.
34
Concept Hierarchy Generation
for Nominal Data
o Specification of a partial/total ordering of attributes explicitly at
the schema level by users or experts
street < city < state < country
o Specification of a hierarchy for a set of values by explicit data
grouping
{Urbana, Champaign, Chicago} < Illinois
o Specification of only a partial set of attributes
E.g., only street < city, not others
o Automatic generation of hierarchies (or attribute levels) by the
analysis of the number of distinct values
E.g., for a set of attributes: {street, city, state, country}
35
Automatic Concept Hierarchy Generation
o Some hierarchies can be automatically generated based on
the analysis of the number of distinct values per attribute in
the data set
The attribute with the most distinct values is placed at the
lowest level of the hierarchy
Exceptions, e.g., weekday, month, quarter, year
country 15 distinct values
province_or_ state 365 distinct values
city 3567 distinct values
street 674,339 distinct values
36
Outline
o General data characteristics
o Why preprocess the data?
o Data cleaning
o Data integration
o Data transformation
Data reduction
o Summary
37
Data Reduction Strategies
o Warehouse may store terabytes of data
Complex data analysis/mining may take a very long time to run on the
complete data set
o Data reduction
Obtains a reduced representation of the data set that is much smaller in
volume but yet produces the same (or almost the same) analytical
results
o Data reduction strategies
Data cube aggregation
Dimensionality reduction remove unimportant attributes
Numerosity reduction
Discretization and concept hierarchy generation
38
Data Cube Aggregation
o The lowest level of a data cube (base cuboid)
the aggregated data for an individual entity of interest
e.g., a customer in a phone calling data warehouse.
o Multiple levels of aggregation in data cubes
Further reduce the size of data to deal with
o Reference appropriate levels
Use the smallest representation which is enough to solve the task
o Queries regarding aggregated information should be answered using data
cube, when possible
Year = 1999 Year Sales
Year = 1998 1997 $10.7M
1998 $14.1M
Year = 1997 1999 $30.5M
Quarter Sales
Q1 $1.4M
Q2 $4.1M
Q3 $3.5M
39
Principal Component Analysis (PCA)
o Find a projection that captures the largest amount of variation in data
o The original data are projected onto a much smaller space, resulting in
dimensionality reduction. We find the eigenvectors of the covariance matrix,
and these eigenvectors define the new space
x2
x1
40
Principal Component Analysis (Steps)
o 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 components, it is possible to reconstruct a good
approximation of the original data)
o Works for numeric data only
41
Data reduction: Data Cube Aggregation
Front View of Sample Data Cube Entire View of Sample Data Cube
42
Attribute Creation (Feature Generation)
o Create new attributes (features) that can capture the
important information in a data set more effectively than the
original ones
o 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
Data discretization
43
Attribute Reduction
o When there are a large number of variables in the database.
o It is very likely that subsets of variables are highly correlated with
each other.
o The accuracy and reliability of a classification or prediction model will
suffer if we include highly correlated variables or variables that are
unrelated to the outcome of interest because of over fitting. In model
deployment, it can increase costs due to collection and processing of these
variables.
o The dimensionality of a model is the number of independent or input
variables used by the model. One of the key steps in data mining is
therefore finding ways to reduce dimensionality without sacrificing
accuracy.
44
Attribute Reduction - Dimensionality Reduction
Feature Selection ** Feature is another word for “attribute”
or “variable”.
Feature Extraction
Which attribute or attributes can be considered important and
should be selected ?
45
Attribute Reduction – Feature Selection
o Also known as variable selection or attribute selection
o Selection of optimal subset of attributes for better performance
and accuracy
o One common method in feature subset selection is called StepWise
regression.
o StepWise regression has 2 strategies:-
Forward Selection (FS)
Backward Elimination (BE)
46
Attribute Reduction – Feature Selection (Stepwise)
o Forward selection:
involves starting with no attributes in the model, testing the
addition of each attribute using a chosen model comparison
criterion, adding the attribute (if any) that improves the model the most,
and repeating this process until none improves the model.
o Backward elimination:
involves starting with all candidate attribute , testing the deletion
of each attribute using a chosen model comparison criterion, deleting
the attribute (if any) that improves the model the most by being deleted,
and repeating this process until no further improvement is
possible.
47
Dimensionality Reduction:
Example of Heuristic Method
o Forward selection o Backward selection
Initial attribute set: Initial attribute set:
{A1, A2, A3, A4, A5, A6} {A1, A2, A3, A4, A5, A6}
Initial reduced set: {A1, A3, A4, A5, A6}
{} {A1, A4, A5, A6}
{A1} Reduced attribute set:
{A1, A4} {A1, A4, A6}
Reduced attribute set:
{A1, A4, A6}
48
Numerosity reduction
“Can we reduce the data volume by choosing alternative,
‘smaller’ forms of data representation?”
o Parametric methods
A model is used to estimate the data, so that typically only the data
parameters need to be stored, instead of the actual data (outliers may
also be stored)
e.g: Log-linear models: estimate discrete multidimensional probability
distributions
o Non-parametric methods
Do not assume models; storing reduced representations of data
Major methods: histograms, clustering, & sampling
49
Numerosity Reduction:
Regress Analysis and Log-Linear Models
o 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, ….
Data are modeled to fit a straight line
Often uses the least-square method to fit the line
o Multiple regression:Y = b0 + b1 X1 + b2 X2.
Many nonlinear functions can be transformed into the above
allows a response variable Y to be modeled as a linear function of
multidimensional feature vector
o Log-linear models:
The multi-way table of joint probabilities is approximated by a product of lower-
order tables
Probability: p(a, b, c, d) = αab βacχad δbcd
approximates discrete multidimensional probability distributions
50
Numerosity Reduction:
Histograms
o Divide data into buckets and store average (sum) for each bucket
o Partitioning rules:
Equal-width: equal bucket range
Equal-frequency (or equal-depth)
V-optimal: with the least histogram variance (weighted sum of the original values
that each bucket represents)
MaxDiff: set bucket boundary between each pair for pairs have the β–1 largest
differences
Example:
list of prices of sold items:
1,1,5,5,5,5,5,8,8,10,10,10,10,12,14,14,
14,15,15,15,15,15,15,18,18,18,18,18,
18,18,18,20,20,20,20,20,20,20,21,21,
21,21,25,25,25,25,25,28,28,30,30,30.
51
Numerosity Reduction:
Clustering
o Partition data set into clusters based on similarity, and store cluster
representation (e.g., centroid and diameter) only
o Can be very effective if data is clustered but not if data is “smeared”
o Can have hierarchical clustering and be stored in multi-dimensional index
tree structures
o There are many choices of clustering
definitions and clustering
algorithms (Chapter 8)
52
Numerosity Reduction:
Sampling
o Sampling: obtaining a small sample s to represent the whole data set N
o Allow a mining algorithm to run in complexity that is potentially sub-linear
to the size of the data
o Key principle: Choose a representative subset of the data
Simple random sampling may have very poor performance in the
presence of skew
Develop adaptive sampling methods, e.g., stratified sampling:
o Note: Sampling may not reduce database I/Os (page at a time)
53
Numerosity Reduction:
Types of Sampling
o Simple random sampling
There is an equal probability of selecting any particular item
o Sampling without replacement
Once an object is selected, it is removed
from the population
o Sampling with replacement
A selected object is not removed from
the population
o Stratified sampling:
Partition the data set, and draw samples
from each partition (proportionally, i.e., approximately
the same percentage of the data)
Used in conjunction with skewed data
54
Outline
o General data characteristics
o Why preprocess the data?
o Data cleaning
o Data integration
o Data transformation
o Data reduction
Summary
55
Summary of Data Preprocessing Methods
Data cleaning Missing / incomplete 1. Ignore the tuple
data 2. Fill in it manually
3. Fill in it automatically
Noisy data / 1. Binning
inconsistence / 2. Regression
outliers 3. Clustering
4. Combined computer with human inspection
Data preprocessing
Data integration 1. Correlation analysis & Covariance
Data transformation 1. Smoothing
2. Aggregation
3. Generalization
4. Normalization
5. Attribute / feature construction
Data reduction 1. Data cube aggregation
2. Attribute Reduction - Dimensionality reduction
3. Numerosity reduction
5. Discretization and concept hierarchy generation
56
Summary
o Data preparation/preprocessing: A big issue for data mining
o Data description, data exploration, and measure data similarity set the base
for quality data preprocessing
o Data preparation includes
Data cleaning
Data integration and data transformation
Data reduction (dimensionality and numerosity reduction)
o A lot a methods have been developed but data preprocessing still an active
area of research
57