Data Preprocessing Techniques Explained
Data Preprocessing Techniques Explained
Data preprocessing
Data preprocessing describes any type of processing performed on raw data to prepare it for
another processing procedure. Commonly used as a preliminary data mining practice, data
preprocessing transforms the data into a format that will be more easily and effectively
processed for the purpose of the user.
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 transformation
Normalization and aggregation
1
Data reduction
Obtains reduced representation in volume but produces the same or similar analytical
results
Data discretization
Part of data reduction but with particular importance, especially for numerical data
2
(e) Using the most probable value to fill in the missing value: This may be determined
with regression, inference-based tools using Bayesian formalism, or decision tree induction.
For example, using the other customer attributes in your data set, you may construct a
decision tree to predict the missing values for income
Example:- Smooth out the following prices 21, 8, 28, 4, 34, 21, 15, 25, 24.
Data for price are first sorted and then partitioned into equidepth bins of depth 3.
Sorted data for price (in dollars): 4, 8, 15, 21, 21, 24, 25, 28, 34
2 Clustering: Outliers in the data may be detected by clustering, where similar values are
organized into groups, or ‘clusters’. Values that fall outside of the set of clusters may be
considered outliers.
3
3 Regression : smooth by fitting the data into regression functions.
Linear regression involves finding the best of line to fit two variables, so that one
variable can be used to predict the other.
Multiple linear regression is an extension of linear regression, where more than two
variables are involved and the data are fit to a multidimensional surface.
4
There may also be inconsistencies due to data integration (e.g.,where a given attribute
can have different names in different databases).
Discrepancy Detection
a) Using Meta Data
Discrepancy can be detected by using metadata. For example, what are the domain
and data type of each attribute? What are the acceptable values for each attribute?
What is the range of the length of values? Do all values fall within the expected
range? Are there any known dependencies between attributes? E.t.c
5
2.3 Data Integration
It combines data from multiple sources into a coherent store. There are number of issues to
consider during data integration.
Issues:
Schema integration: refers integration of metadata from different sources.
Entity identification problem: Identifying entity in one data source similar to entity
in another table. For example, customer_id in one db and customer_no in another db
refer to the same entity
Detecting and resolving data value conflicts: Attribute values from different
sources can be different due to different representations, different scales. E.g. metric
vs. British units
Redundancy: is another issue while performing data integration. Redundancy can
occur due to the following reasons:
Object identification: The same attribute may have different names in different db
Derived Data: one attribute may be derived from another attribute
The result of the equation is > 0, then A and B are positively correlated, which means
the value of A increases as the values of B increases. The higher value may indicate
redundancy that may be removed.
The result of the equation is = 0, then A and B are independent and there is no
correlation between them.
If the resulting value is < 0, then A and B are negatively correlated where the values
of one attribute increase as the value of one attribute decrease which means each
attribute may discourages each other.
rA,B also called Pearson’s product moment coefficient
6
[Link] Analysis for Nominal or Categorical Data:
Applicable for data where values of each attribute are divided into different
categories.
Suppose A has c distinct values, namely a1,a2, : : :ac .
B has r distinct values, namely b1,b2, : : :br
The data tuples described by A and B can be shown as a contingency table, with the
c values of A making up the columns and the r values of B making up the rows.
For nominal data, a correlation relationship between two attributes, A and B, can be
discovered by a 2(chi-square) test (using the below formula)
7
Eg3.1. Consider a sample population of 1500 people who are surveyed to see if they
Play Chess or not and if they Like Science Fiction books are not.
The counts given within parenthesis are expected frequency and the remaining one is
the observed frequency.
For Example the Expected frequency for the cell (Play Chess, Like Science Fiction)
is:
= (Count (Play Chess) * Count (Like Science Fiction)) / Total sample population
= (300 * 450) / 1500 = 90
8
retained by storing only a small fraction of the strongest of the wavelet coefficients.
The DWT is closely related to the discrete Fourier transform(DFT), a signal
processing technique involving sines and cosines. In general, however, the DWT
achieves better lossy compression. That is, if the same number of coefficients is
retained for a DWT and a DFT of a given data vector, the DWT version will provide a
more accurate approximation of the original data. Hence, for an equivalent
approximation, the DWT requires less space than the DFT. Unlike the DFT, wavelets
are quite localized in space, contributing to the conservation of local detail.
The general procedure for applying a discrete wavelet transform uses a hierarchical
pyramid algorithm that halves the data at each iteration, resulting in fast
computational speed.
The method is as follows:
1. The length, L, of the input data vector must be an integer power of 2. This condition can be
met by padding the data vector with zeros as necessary (L ≥ n).
2. Each transform involves applying two functions. The first applies some data smoothing,
such as a sum or weighted average. The second performs a weighted difference, which acts to
bring out the detailed features of the data.
3. The two functions are applied to pairs of data points in X, that is, to all pairs of
measurements (x2i , x2i+1). This results in two sets of data of length L=2. In general, these
represent a smoothed or low-frequency version of the input data and the high frequency
content of it, respectively.
4. The two functions are recursively applied to the sets of data obtained in the previous loop,
until the resulting data sets obtained are of length 2.
5. Selected values from the data sets obtained in the above iterations are designated the
wavelet coefficients of the transformed data.
9
1. The input data are normalized, so that each attribute falls within the same range. This step
helps ensure that attributes with large domains will not dominate attributes with smaller
domains.
2. PCA computes k orthonormal vectors that provide a basis for the normalized input data.
These are unit vectors that each point in a direction perpendicular to the others. These vectors
are referred to as the principal components. The input data are a linear combination of the
principal components.
3. The principal components are sorted in order of decreasing “significance” or strength. The
principal components essentially serve as a new set of axes for the data, providing important
information about variance. That is, the sorted axes are such that the first axis shows the most
variance among the data, the second axis shows the next highest variance, and so on. For
example, Figure shows the first two principal components, Y1 and Y2, for the given set of
data originally mapped to the axes X1 and X2. This information helps identify groups or
patterns within the data.
4. Because the components are sorted according to decreasing order of “significance,” the
size of the data can be reduced by eliminating the weaker components, that is, those with low
variance. Using the strongest principal components, it should be possible to reconstruct a
good approximation of the original data.
Basic heuristic methods of attribute subset selection include the following techniques, some
of which are illustrated below:
10
1. Step-wise forward selection: The procedure starts with an empty set of attributes.
The best of the original attributes is determined and added to the set. At each
subsequent iteration or step, the best of the remaining original attributes is added to
the set.
2. Step-wise backward elimination: The procedure starts with the full set of attributes.
At each step, it removes the worst attribute remaining in the set
2.4.2 Numerosity reduction techniques replace the original data volume by alternative,
smaller forms of data representation. These techniques may be parametric or nonparametric.
For 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.)
Regression and log-linear models are examples.
11
Nonparametric methods for storing reduced representations of the data include histograms
clustering , sampling , and data cube aggregation .
Parametric: Assume the data fits some model, then estimate model parameters, and store
only the parameters, instead of actual data.
Regression and Log-Linear Models:
Linear Regression data are modeled to fit in a straight line.
That is data can be modeled to the mathematical equation:
Y = α + β X, where α, β are coefficients
Where X is called the “Response Variable” and Y is called “Predictor Variable”.
Alpha and beta are called the regression coefficients.
Alpha is the Y-intercept and Beta is the Slope of the equation.
These regression coefficients can be solved by using “method of least squares”.
Multiple Regression
Extension of linear regression
Response variable Y is modeled as a multidimensional vector.
Log-Linear Models:
Log-linear models approximate discrete multidimensional probability distributions.
Given a set of tuples in n dimensions (e.g., described by n attributes), we can consider each
tuple as a point in an n-dimensional space. Log-linear models can be used to estimate the
probability of each point in a multidimensional space for a set of discretized attributes, based
on a smaller subset of dimensional combinations. This allows a higher-dimensional data
space to be constructed from lower-dimensional spaces.
Non parametric: In which histogram, clustering ,sampling and data cube aggregation is used
to store reduced form of data.
Histogram
Divide data into buckets and store average (sum) for each bucket
A bucket represents an attribute-value/frequency pair
It can be constructed optimally in one dimension using dynamic programming
It divides up the range of possible values in a data set into classes or groups.
For each group, a rectangle (bucket) is constructed with a base length equal to the
range of values in that specific group, and an area proportional to the number of
observations falling into that group.
The buckets are displayed in a horizontal axis while height of a bucket represents the
average frequency of the values.
12
Example:
The following data are a list of prices of commonly sold items. The numbers have been
sorted.
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.
Draw histogram plot for price where each bucket should have equi-width of 10
The buckets can be determined based on the following partitioning rules, including the
following.
1. Equi-width: histogram with bars having the same width
2. Equi-depth or equi-frequency: histogram with bars having the same height
3. V-Optimal: histogram with least variance (count b * value b)
4. MaxDiff: bucket boundaries defined by user specified threshold
V-Optimal and MaxDiff histograms tend to be the most accurate and practical. Histograms
are highly effective at approximating both sparse and dense data, as well as highly skewed,
and uniform data.
Clustering techniques consider data tuples as objects. They partition the objects into groups
or clusters, so that objects within a cluster are “similar" to one another and “dissimilar" to
objects in other clusters. Similarity is commonly defined in terms of how “close" the objects
are in space, based on a distance function
Quality of clusters measured by their diameter (max distance between any two objects in the
cluster) or centroid distance (avg. distance of each cluster object from its centroid)
13
Sampling
Sampling can be used as a data reduction technique since it allows a large data set to be
represented by a much smaller random sample (or subset) of the data. Suppose that a large
data set, D, contains N tuples. Let's have a look at some possible samples for D.
14
Data cube aggregation: Reduce the data to the concept level needed in the analysis. Queries
regarding aggregated information should be answered using data cube when possible. Data
cubes store multidimensional aggregated information. The following figure shows a data
cube for multidimensional analysis of sales data with respect to annual sales per item type for
each branch.
Each cells holds an aggregate data value, corresponding to the data point in multidimensional
space.
Data cubes provide fast access to pre computed, summarized data, thereby benefiting on-line
analytical processing as well as data mining.
The cube created at the lowest level of abstraction is referred to as the base cuboid. A cube
for the highest level of abstraction is the apex cuboid. The lowest level of a data cube (base
cuboid). Data cubes created for varying levels of abstraction are sometimes referred to as
cuboids, so that a “data cube" may instead refer to a lattice of cuboids. Each higher level of
abstraction further reduces the resulting data size.
The following database consists of sales per quarter for the years 2002-2004.
15
Suppose, the analyzer interested in the annual sales rather than sales per quarter, the above
data can be aggregated so that the resulting data summarizes the total sales per year instead of
per quarter. The resulting data in smaller in volume, without loss of information necessary for
the analysis task.
16
Normalization
In which data are scaled to fall within a small, specified range, useful for classification
algorithms involving neural networks, distance measurements such as nearest neighbor
classification and clustering. There are 3 methods for data normalization. They are:
1) min-max normalization
2) z-score normalization
3) normalization by decimal scaling
Min-max normalization performs a linear transformation on the original data. Suppose that
minA and maxA are the minimum and maximum values of an attribute A. Min-max
normalization maps a value v of A to v1
v - minA
1
v = ------------- (new_maxA – new_minA) + new_minA
maxA - minA
Example:- Suppose that the maximum and minimum values for the attribute income are
$98,000 and $12,000,respectively. Map the income to the range [0; 1]. By min-max
normalization, a value of $73,600 for income is transformed to
73,600 - 12,000
1
v = ----------------------- (1.0 - 0) + 0 = 0.716
98,000 – 12,000
In z-score normalization (or zero-mean normalization), the values for an attribute A are
normalized based on the mean and standard deviation of A. A value v of A is normalized to
v1 by computing
v–A
1
v = --------
σA
where A stands for mean of A and σ A for standard deviation. This method of normalization
is useful when the actual minimum and maximum of attribute A are unknown, or when there
are outliers which dominate the min-max normalization.
A variation of this z-score normalization replaces the standard deviation of above equation
by the mean absolute deviation of A. The mean absolute deviation of A, denoted sA, is
17
Example :- Suppose that the mean and standard deviation of the values for the attribute
income are $54,000 and $16,000, respectively. With z-score normalization, a value of
$73,600 for income is transformed to
73,600 – 54,000
1
v = --------------------- = 1.225
16,000
Discretization:
Discretization techniques can be used to reduce the number of values for a given
continuous attribute, by dividing the range of the attribute into intervals. Interval
labels can then be used to replace actual data values.
Types of Data Discretization Techniques:
1. Supervised Discretization
a. Uses Class information of the data
2. Unsupervised Discretization
a. Does not uses Class information of the data
3. Top-down Discretization (splitting)
a. Identifies ‘Split-Points’ or ‘Cut-Points’ in data values
b. Splits attribute values into intervals at split-points
c. Repeats recursively on resulting intervals
d. Stops when specified number of intervals reached or some stop criteria is
reached.
4. Bottom-up Discretization (merging)
a. Divide the attribute values into intervals where each interval has a distinct
attribute value.
b. Merge two intervals based on some merging criteria
c. Repeats recursively on resulting intervals
d. Stops when specified number of intervals reached or some stop criteria is
reached.
18
3. Discretization by Cluster, Decision Tree, and Correlation Analyses.
Binning:
Top-Down Discretization Technique Used
Un Supervised Discretization Technique
No Class Information Used
User specified number of bins is used.
Same technique as used for Smoothing and Numerosity reduction
Data Discretized using Equi-Width or Equi-Depth method
Replace each bin value by bin mean or bin median.
Same technique applied recursively on resulting bins or partitions to generate Concept
Hierarchy
Outliers are also fitted in separate bins or partitions or intervals
Histogram Analysis:
Un Supervised Discretization; Top-Down Discretization Technique.
Data Values split into buckets – Equi-Width or Equi-Frequency
Repeats recursively on resulting buckets to generate multi-level Concept Hierarchies.
Stops when user specified numbers of Concept Hierarchy Levels are generated.
Cluster Analysis:
Uses Top-Down Discretization or Bottom-up Discretization
Data values of an attribute are partitioned into clusters
Uses the closeness of data values Produces high quality discretization results.
Each cluster is a node in the concept hierarchy
Each cluster further sub-divided into sub-clusters in case of Top-down approach to
create lower level clusters or concepts.
Clusters are merged in Bottom-up approach to create higher level cluster or concepts.
Decision Tree
Techniques to generate decision trees for classification can be applied to
discretization.
Employ a top-down splitting approach
Decision tree approaches to discretization are supervised, that is, they make use of
class label information
Because decision tree–based discretization uses class information, it is more likely
that the interval boundaries (split-points) are defined to occur in places that may help
improve classification accuracy.
Correlation Analyses
19
3. Adjacent intervals with the least 2values are merged together, because low
2 values for a pair indicate similar class distributions.
4. This merging process proceeds recursively until a predefined stopping
criterion is met.
1. Specification of a partial set of attributes at the schema level by the users or domain
experts:
A user or expert can easily define a concept hierarchy by specifying a partial or total
ordering of the attributes at the schema level
Eg. Dimension ‘Location’ in a Data warehouse has attributes ‘Street’, ‘City’, ‘State’
& ‘Country’.
Hierarchical definition of these attributes obtained by ordering these attributes as:
Street < City < State < Country at the schema level itself by user or expert.
20
This is done using the rule that counts and uses the distinct values of each attribute
The attribute that has the most distinct values is placed at the bottom of the hierarchy
And the attribute that has the least distinct values is placed at the top of the hierarchy
This heuristic rule applies for most cases but it fails of some.
Users or experts can examine the concept hierarchy and COUNTRY
can perform manual adjustment.
Eg. Concept Hierarchy for ‘Location’ dimension:
Country (10); State (508), City (10,804), Street (1,234,567) STATE
Street < City < State < Country
In this case user need not modify the generated order / concept hierarchy.
But this heuristic rule may fail for the ‘Time’ dimension.
Distinct Years (100); Distinct Months (12); Distinct Days-of-week (7) CITY
So in this case the attribute ordering or the concept hierarchy is:
Year < Month < Days-of-week
This is not correct.
STREET
4. Specification of only partial set of attributes:
User may have vague idea of the concept hierarchy
So they just specify only few attributes that form the concept hierarchy.
Eg. User specifies just the Attributes Street and City.
To get the complete concept hierarchy in this case we have to link these user specified
attributes with the data semantics specified by the domain experts.
Users have the authority to modify this generated hierarchy.
The domain expert may have defined that the attributes given below are semantically
linked
Number, Street, City, State, Country.
Now the newly generated concept hierarchy by linking the domain expert
specification and the users specification will be that:
Number < Street < City < State < Country
Here the user can inspect this concept hierarchy and can remove the unwanted
attribute ‘Number’ to generate the new Concept Hierarchy as below:
Street < City < State < Country
21