1
Data Mining:
Concepts andTechniques
(3rd
ed.)
â Chapter 3 â
Jiawei Han, Micheline Kamber, and Jian Pei
University of Illinois at Urbana-Champaign &
Simon Fraser University
Š2011 Han, Kamber & Pei. All rights reserved.
2.
2
2
Chapter 3: DataPreprocessing
â Data Preprocessing: An Overview
â Data Quality
â Major Tasks in Data Preprocessing
â Data Cleaning
â Data Integration
â Data Reduction
â Data Transformation and Data Discretization
â Summary
3.
3
Data Quality: WhyPreprocess the Data?
â Measures for data quality: A multidimensional view
â Accuracy: correct or wrong, accurate or not
â Completeness: not recorded, unavailable, âŚ
â Consistency: some modified but some not, dangling, âŚ
â Timeliness: timely update?
â Believability: how trustable the data are correct?
â Interpretability: how easily the data can be
understood?
4.
4
Major Tasks inData Preprocessing
â Data cleaning
â Fill in missing values, smooth noisy data, identify or remove
outliers, and resolve inconsistencies
â Data integration
â Integration of multiple databases, data cubes, or files
â Data reduction
â Dimensionality reduction
â Numerosity reduction
â Data compression
â Data transformation and data discretization
â Normalization
â Concept hierarchy generation
5.
5
5
Chapter 3: DataPreprocessing
â Data Preprocessing: An Overview
â Data Quality
â Major Tasks in Data Preprocessing
â Data Cleaning
â Data Integration
â Data Reduction
â Data Transformation and Data Discretization
â Summary
6.
6
Data Cleaning
â Datain 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)
â Jan. 1 as everyoneâs birthday?
7.
7
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
â Missing data may need to be inferred
8.
8
How to HandleMissing 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
â the most probable value: inference-based such as
Bayesian formula or decision tree
9.
9
Noisy Data
â Noise:random error or variance in a measured variable
â Incorrect attribute values may be due to
â faulty data collection instruments
â data entry problems
â data transmission problems
â technology limitation
â inconsistency in naming convention
â Other data problems which require data cleaning
â duplicate records
â incomplete data
â inconsistent data
10.
10
How to HandleNoisy Data?
â Binning
â 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.
â Regression
â smooth by fitting the data into regression functions
â Clustering
â detect and remove outliers
â Combined computer and human inspection
â detect suspicious values and check by human (e.g.,
deal with possible outliers)
11.
11
Data Cleaning asa Process
â 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)
â 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
â Integration of the two processes
â Iterative and interactive (e.g., Potterâs Wheels)
12.
12
12
Chapter 3: DataPreprocessing
â Data Preprocessing: An Overview
â Data Quality
â Major Tasks in Data Preprocessing
â Data Cleaning
â Data Integration
â Data Reduction
â Data Transformation and Data Discretization
â Summary
13.
13
13
Data Integration
â Dataintegration:
â Combines data from multiple sources into a coherent store
â Schema integration: e.g., A.cust-id ⥠B.cust-#
â Integrate metadata from different sources
â Entity identification problem:
â Identify real world entities from multiple data sources, e.g., Bill
Clinton = William Clinton
â 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.
14
14
Handling Redundancy inData Integration
â 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
â Redundant attributes may be able to be detected by
correlation analysis and covariance analysis
â Careful integration of the data from multiple sources may
help reduce/avoid redundancies and inconsistencies and
improve mining speed and quality
15.
15
Correlation Analysis (NominalData)
â Χ2
(chi-square) test
â The larger the Χ2
value, the more likely the variables are
related
â The cells that contribute the most to the Χ2
value are
those whose actual count is very different from the
expected count
â 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
16.
16
Chi-Square Calculation: AnExample
â Χ2
(chi-square) calculation (numbers in parenthesis are
expected counts calculated based on the data distribution
in the two categories)
â It shows that like_science_fiction and play_chess are
correlated in the group
Play chess Not play chess Sum (row)
Like science fiction 250(90) 200(360) 450
Not like science fiction 50(210) 1000(840) 1050
Sum(col.) 300 1200 1500
17.
17
Correlation Analysis (NumericData)
â Correlation coefficient (also called Pearsonâs product
moment coefficient)
where n is the number of tuples, and are the respective
means of A and B, ĎA
and ĎB
are the respective standard deviation
of A and B, and ÎŁ(ai
bi
) is the sum of the AB cross-product.
â If rA,B
> 0, A and B are positively correlated (Aâs values
increase as Bâs). The higher, the stronger correlation.
â rA,B
= 0: independent; rAB
< 0: negatively correlated
19
Correlation (viewed aslinear relationship)
â Correlation measures the linear relationship
between objects
â To compute correlation, we standardize data
objects, A and B, and then take their dot product
20.
20
Covariance (Numeric Data)
â Covariance is similar to correlation
where n is the number of tuples, and are the respective mean or
expected values of A and B, ĎA
and ĎB
are the respective standard
deviation of A and B.
â Positive covariance: If CovA,B
> 0, then A and B both tend to be larger
than their expected values.
â 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.
â 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
Correlation coefficient:
21.
Co-Variance: An Example
â It can be simplified in computation as
â 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.
22.
Example
â Let's sayyou want to know if gender has anything to do with political
party preference. You poll 440 voters in a simple random sample to
find out which political party they prefer. The results of the survey
are shown in the table below:
â To see if gender is linked to political party preference,
perform a Chi-Square test
* Data Mining: Concepts and Techniques 22
23.
23
23
Chapter 3: DataPreprocessing
â Data Preprocessing: An Overview
â Data Quality
â Major Tasks in Data Preprocessing
â Data Cleaning
â Data Integration
â Data Reduction
â Data Transformation and Data Discretization
â Summary
24.
24
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
25.
25
Clustering
â Partition dataset 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
26.
26
Sampling
â Sampling: obtaininga small sample s to represent the
whole data set N
â Allow a mining algorithm to run in complexity that is
potentially sub-linear to the size of the data
â 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:
â Note: Sampling may not reduce database I/Os (page at a
time)
27.
27
Types of Sampling
â Simple random sampling
â There is an equal probability of selecting any 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 each
partition (proportionally, i.e., approximately the same
percentage of the data)
â Used in conjunction with skewed data
28.
28
Sampling: With orwithout Replacement
SRSWOR
(simple random
sample without
replacement)
SRSWR
Raw Data
30
Data Cube Aggregation
â 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
â Multiple levels of aggregation in data cubes
â Further reduce the size of data to deal with
â Reference appropriate levels
â Use the smallest representation which is enough to
solve the task
â Queries regarding aggregated information should be
answered using data cube, when possible
31.
31
Data Reduction 3:Data Compression
â String compression
â There are extensive theories and well-tuned algorithms
â Typically lossless, but only limited manipulation is
possible without expansion
â Audio/video compression
â Typically lossy compression, with progressive refinement
â Sometimes small fragments of signal can be
reconstructed without reconstructing the whole
â Time sequence is not audio
â Typically short and vary slowly with time
â Dimensionality and numerosity reduction may also be
considered as forms of data compression
33
Chapter 3: DataPreprocessing
â Data Preprocessing: An Overview
â Data Quality
â Major Tasks in Data Preprocessing
â Data Cleaning
â Data Integration
â Data Reduction
â Data Transformation and Data Discretization
â Summary
34.
34
Data Transformation
â Afunction 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
â Discretization: Concept hierarchy climbing
35.
35
Normalization
â Min-max normalization:to [new_minA
, new_maxA
]
â Ex. Let income range $12,000 to $98,000 normalized to [0.0,
1.0]. Then $73,000 is mapped to
â Z-score normalization (Îź: mean, Ď: standard deviation):
â Ex. Let Îź = 54,000, Ď = 16,000. Then
â Normalization by decimal scaling
Where j is the smallest integer such that Max(|νâ|) < 1
36.
36
Discretization
â Three typesof 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
â Prepare for further analysis, e.g., classification
37.
37
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, bottom-up
merge)
38.
38
Simple Discretization: Binning
â 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
â 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
39.
39
Binning Methods forData 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:
⢠Smoothing by bin means:
⢠Smoothing by bin boundaries:
40.
40
Binning Methods forData 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
41.
41
Discretization Without UsingClass Labels
(Binning vs. Clustering)
Data Equal interval width (binning)
Equal frequency (binning) K-means clustering leads to better results
42.
42
Discretization by Classification&
Correlation Analysis
â 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
â Details to be covered in Chapter 7
â 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
43.
43
Concept Hierarchy Generation
â Concept hierarchy organizes concepts (i.e., attribute values)
hierarchically and is usually associated with each dimension in a data
warehouse
â Concept hierarchies facilitate drilling and rolling in data warehouses to
view data in multiple granularity
â 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)
â Concept hierarchies can be explicitly specified by domain experts
and/or data warehouse designers
â Concept hierarchy can be automatically formed for both numeric and
nominal data. For numeric data, use discretization methods shown.
44.
44
Concept Hierarchy Generation
forNominal Data
â Specification of a partial/total ordering of attributes
explicitly at the schema level by users or experts
â street < city < state < country
â Specification of a hierarchy for a set of values by explicit
data grouping
â {Urbana, Champaign, Chicago} < Illinois
â Specification of only a partial set of attributes
â E.g., only street < city, not others
â 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}
45.
45
Automatic Concept HierarchyGeneration
â 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
province_or_ state
city
street
15 distinct values
365 distinct values
3567 distinct values
674,339 distinct values
46.
46
Chapter 3: DataPreprocessing
â Data Preprocessing: An Overview
â Data Quality
â Major Tasks in Data Preprocessing
â Data Cleaning
â Data Integration
â Data Reduction
â Data Transformation and Data Discretization
â Summary
47.
47
Summary
â Data quality:accuracy, completeness, consistency, timeliness,
believability, interpretability
â Data cleaning: e.g. missing/noisy values, outliers
â Data integration from multiple sources:
â Entity identification problem
â Remove redundancies
â Detect inconsistencies
â Data reduction
â Dimensionality reduction
â Numerosity reduction
â Data compression
â Data transformation and data discretization
â Normalization
â Concept hierarchy generation
48.
48
References
â D. P.Ballou and G. K. Tayi. Enhancing data quality in data warehouse environments. Comm. of
ACM, 42:73-78, 1999
â A. Bruce, D. Donoho, and H.-Y. Gao. Wavelet analysis. IEEE Spectrum, Oct 1996
â T. Dasu and T. Johnson. Exploratory Data Mining and Data Cleaning. John Wiley, 2003
â J. Devore and R. Peck. Statistics: The Exploration and Analysis of Data. Duxbury Press, 1997.
â H. Galhardas, D. Florescu, D. Shasha, E. Simon, and C.-A. Saita. Declarative data cleaning:
Language, model, and algorithms. VLDB'01
â M. Hua and J. Pei. Cleaning disguised missing data: A heuristic approach. KDD'07
â H. V. Jagadish, et al., Special Issue on Data Reduction Techniques. Bulletin of the Technical
Committee on Data Engineering, 20(4), Dec. 1997
â H. Liu and H. Motoda (eds.). Feature Extraction, Construction, and Selection: A Data Mining
Perspective. Kluwer Academic, 1998
â J. E. Olson. Data Quality: The Accuracy Dimension. Morgan Kaufmann, 2003
â D. Pyle. Data Preparation for Data Mining. Morgan Kaufmann, 1999
â V. Raman and J. Hellerstein. Potters Wheel: An Interactive Framework for Data Cleaning and
Transformation, VLDBâ2001
â T. Redman. Data Quality: The Field Guide. Digital Press (Elsevier), 2001
â R. Wang, V. Storey, and C. Firth. A framework for analysis of data quality research. IEEE Trans.
Knowledge and Data Engineering, 7:623-640, 1995