Mod2 - Data Preprocessing
Mod2 - Data Preprocessing
Module 2
What is Data Preprocessing?
• Data preprocessing refers to cleaning, transforming and integrating
data in order to make it ready for data analysis
• The goal of data pre-processing is to improve the quality of the data
to make it more suitable to the specific data mining task
• Some common steps in data pre-processing include:
• Data cleaning
• Data integration
• Data transformation
• Data reduction
• Data discretization
• Data cleaning: Data cleaning routines work to “clean” the data by
filling in missing values, smoothing noisy data, identifying or removing
outliers, and resolving inconsistencies
• Data integration: This step involves combining data from multiple
sources, such as databases, spreadsheets, text files. The goal of the
integration is to create a single, consistent view of the data.
• Data transformation: Converting the data into a format that is more
suitable for the data mining task. This can include normalizing
numerical data, and encoding categorical data.
• Data reduction: selecting a subset of the data that is relevant to the
data mining task. It can be feature selection (selecting a subset of the
variables) or feature extraction (extracting new features ).
• Data discretization: Convert continuous numerical data into
categorical data.
Data Cleaning
It involves handling of missing data, noisy data etc.
1. Missing Data
This situation arises when some data is missing in the data. It can be handled
in various ways. Some of them are:
Ignore the tuples: This approach is suitable only when the dataset we have is
quite large and multiple values are missing within a tuple
Fill the missing values: There are various ways to do this task. You can
choose to
- fill the missing values manually,
- by attribute mean or
- the most probable value.
- Use a global constant to fill in the missing value
Data Cleaning
• Noisy data
Noise is a random error or variance in a measured variable. Noisy data is a
meaningless data that can’t be interpreted by machines. It can be generated due to
faulty data collection, data entry errors etc. It can be handled in following data
smoothing techniques:
Binning : 1)Data is sorted,
2)Data are distributed into a number of buckets or bins.
Smoothing by bin means: each value in a bin is replaced by the mean value of the
bin.
Smoothing by bin medians: each bin value is replaced by the bin median.
Smoothing by bin boundaries: the minimum and maximum values in a given bin
are identified as the bin boundaries. Each bin value is then replaced by the closest
boundary value.
Data Cleaning
Noisy Data
• Regression:
The data is made smooth with the help of using regression function.
Regression can be linear or multiple. Linear regression has only one
independent variable, and multiple regression have more than one
independent variables.
Linear regression
Y = a + b.X
• Outlier Analysis
- Clustering
- Similar values are organized into groups, or “clusters.” Intuitively,
values that fall outside of the set of clusters may be considered
outliers.
Data Transformation
Converting the raw data into a format that is more suitable for the data mining
task. This can include normalizing numerical data, and encoding categorical data.
• Smoothing: removes noise from the data. Such techniques include binning,
regression, and clustering.
• Aggregation, where summary or aggregation operations are applied to the data.
For example, the daily sales data may be aggregated so as to compute monthly
and annual total amounts. This step is typically used in constructing a data cube
for analysis of the data at multiple granularities.
• Generalization of the data, where low-level or “primitive” (raw) data are replaced
by higher-level concepts through the use of concept hierarchies. For example,
categorical attributes, like street, can be generalized to higher-level concepts, like
city or country.
• Data normalization: where the attribute data are scaled so as to fall within a
small specified range, such as −(-1.0, 1.0) or (0.0 to 1.0).
• Attribute selection
• Discretization
• Concept hierarchy generation
Data Transformation
Normalization
• min-max normalization,
• z-score normalization, and
• normalization by decimal scaling
Data Transformation
Normalization
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 v’ in the range [new_minA, new_maxA]
by computing
• Min-max normalization preserves the relationships among the original data values.
Suppose that the minimum and maximum values for the attribute income are $12,000 and
$98,000, respectively. Map income to the range [0.0,1.0].
v= $73,600
v’ = [(73,600−12,000) / (98,000−12,000)] x (1.0−0) +0 = 0.716
Data Transformation
• Normalization
• 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 v’ by computing
•Data Sparsity: Data points become increasingly spread out, making it hard to find patterns or
relationships.
•Computational Complexity: The computational burden of algorithms increases exponentially.
•Overfitting: Models become more likely to memorize the training data without generalizing well.
•Distortion of Distance Metrics: Traditional distance metrics become less reliable in measuring proximity.
•Visualization Challenges: Projecting high-dimensional data onto lower dimensions leads to loss of
information.
•Algorithmic Efficiency: Algorithms need to be scalable and efficient to handle the complexity of high-
dimensional spaces.
•Interpretability Issues: Understanding the decision-making process of high-dimensional models becomes
increasingly difficult.
•Data Storage Requirements: Efficient data storage and retrieval strategies are essential for managing large
volumes of high-dimensional data
Dimensionality Reduction
b = y̅̅̅̅ - wx̅̅
• Multiple linear regression extends the idea of modeling the response
variable by considering linear relationships among two or more
predictor variables.
y=b0+b1x1+b2x2
x y X-x̅ Y-y̅ (X-x̅)2
2 3
4 7
6 5 b = y̅̅ - wx̅
8 10
W = 0.95; b = 1.5
Σ Σ Σ
y = .95 x + 1.5
Data Reduction – Numerosity Reduction
Log-linear Models
• The log-linear model discovers the relationship between two or more
discrete attributes. Assume, we have a set of tuples in n-dimensional space;
the log-linear model helps to derive the probability of each tuple in this 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 combination. This allows a higher-dimensional data
space to be constructed from lower-dimensional spaces.
• They may be used to estimate the probability value associated with data
cube cells
• Hence, applies to dimensionality reduction also.
Log-linear Models
• MaxDiff: In a MaxDiff histogram, we consider the difference between each pair of adjacent
values.
- Suppose we need β buckets. Then, a bucket boundary is established between two values
that are adjacent (in sort parameter order) if the difference between these values is one of
the β -1 largest such differences.
- The goal is to avoid grouping attribute values with vastly different source parameter values
into a bucket.
• The following data are a list of prices of
commonly sold items at AllElectronics
(rounded to the nearest dollar). 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.
Data Cube Aggregation
• multidimensional aggregation
• Aggregation at various levels of a data cube
• For example, suppose you have the data of All
Electronics sales per quarter for the year 2018 to
the year 2022. If you want to get the annual sale
per year, you just have to aggregate the sales per
quarter for each year. In this way, aggregation
provides you with the required data, which is much
smaller in size, and thereby we achieve data
reduction even without losing any data.
• The data cube present precomputed and
summarized data
Sampling
• Simple random sample without replacement (SRSWOR) of size s: This is
created by drawing s of the N tuples from D (s < N), where the probability
of drawing any tuple in D is 1/N, that is, all tuples are equally likely to be
sampled.
• Simple random sample with replacement (SRSWR) of size s: This is similar
to SRSWOR, except that each time a tuple is drawn from D, it is recorded
and then replaced. That is, after a tuple is drawn, it is placed back in D so
that it may be drawn again.
• Cluster sample: If the tuples in D are grouped into M mutually disjoint
“clusters,” then an SRS of s clusters can be obtained, where s < M.
• Stratified sample: If D is divided into mutually disjoint parts called strata, a
stratified sample of D is generated by obtaining an SRS at each stratum.
This helps ensure a representative sample, especially when the data are
skewed.
Discretization and concept hierarchy
generation
• Discretization is the process of transforming numerical variables into
categorical counterparts.
E.g. Converting Age into categories/intervals such as 0-19, 20-39, 40-59
• Discretization improves the accuracy by reducing the noise
• Discretization allows easy identification of outliers, invalid and missing
values of numerical variables
Discretization and Concept Hierarchy
Generation for Numerical Data
• Binning
• Histogram Analysis
• Entropy-Based Discretization
• Interval Merging by χ2 Analysis
• Cluster Analysis
• Discretization by Intuitive Partitioning
Entropy-based Discretization
• In supervised discretization, cut points/split points are determined by
referring to the class information.
• Entropy-based discretization is a supervised discretization
• It finds the best split point so that the intervals are as pure as possible (that
is the majority of the values in a bin correspond to have the same class
label.)
• It helps us split our data at points where we will gain the most insights
• Formally, it is characterized by finding the split with maximal information
gain/ minimum entropy.
• We use the split-point to partition the range of A into two intervals,
corresponding to A ≤ split-point and A > split-point.
• To discretize a numerical attribute, A, the method selects the value of A
that has the minimum entropy/maximum information gain as a split-point
and recursively partitions the resulting intervals to arrive at a hierarchical
discretization. Such discretization forms a concept hierarchy for A.
Entropy-based Discretization
• Do entropy-based discretization for the following dataset.
𝟐 𝟐 𝟔 𝟔
Entropy for (b) = -[ x log 2 + x log 2 ] = .812
𝟖 𝟖 𝟖 𝟖
𝟏 𝟖
Total entropy for the entire partitioning = * Entropy for (a) + * Entropy for (b)
𝟗 𝟗
𝟏 𝟖
= *0 + *.812 = .721
𝟗 𝟗
2) For age = 22, splits are a) age<=22 b) age>22
Age Grade Age Grade
21 F 24 P
22 F 25 F
27 P
27 P
𝟐 𝟐
Entropy for (a) = -[ * log 2 𝟐] =0 27 P
𝟐
35 P
41 P
𝟏 𝟏 𝟔 𝟔
Entropy for (b) = -[ x log 2𝟕+𝟕 x log 2 𝟕] = .592
𝟕
𝟐 𝟕
Total entropy for the entire partitioning = * Entropy for (a) + * Entropy for (b)
𝟗 𝟗
𝟐 𝟕
= *0 + *.592 = .460
𝟗 𝟗
3) For age = 24, splits are a) age<=24 Age Grade
b) age>24
Age Grade
21 F
22 F 25 F
24 P 27 P
27 P
𝟐 𝟐 𝟏 𝟏 27 P
Entropy for (a) = -[ * log 2𝟑 + ∗ log 2 ] = 0.592 35 P
𝟑 𝟑 𝟑
41 P
𝟏 𝟏 𝟓 𝟓
Entropy for (b) = -[ x log 2 + x log 2 ] = .095
𝟔 𝟔 𝟔 𝟔
𝟑 𝟔
Total entropy for the entire partitioning = * Entropy for (a) + * Entropy for (b)
𝟗 𝟗
𝟐 𝟕
= *.592 + *.095 = .205
𝟗 𝟗
4) For age = 25, splits are a) age<=25 Age Grade b) age>25 Age Grade
21 F 27 P
22 F 27 P
24 P 27 P
25 F 35 P
41 P
𝟏 𝟏 𝟑 𝟑
Entropy for (a) = -[ * log 2 + ∗ log 2 ] = .811
𝟒 𝟒 𝟒 𝟒
𝟓 𝟓
Entropy for (b) = -[ x log 2 ]=0
𝟓 𝟓
𝟒 𝟓
Total entropy for the entire partitioning = * Entropy for (a) + * Entropy for (b)
𝟗 𝟗
𝟒 𝟓
= *.811 + * 0.0 = .360
𝟗 𝟗
5) For age = 27, splits are a) age<=27 Age Grade b) age>27 Age Grade
21 F 35 P
22 F 41 P
24 P
25 F
27 P
27 P
27 P
𝟑 𝟑 𝟒 𝟒
Entropy for (a) = -[ * log 2 + ∗ log 2 ] = .986
𝟕 𝟕 𝟕 𝟕
𝟐 𝟐
Entropy for (b) = -[ x log 2 ]=0
𝟐 𝟐
𝟕 𝟐
Total entropy for the entire partitioning = * Entropy for (a) + * Entropy for (b)
𝟗 𝟗
𝟕 𝟐
= * .986 + * 0.0 = .767
𝟗 𝟗
6) For age = 35, splits are a) age<=35 Age Grade b) age>35 Age Grade
21 F 41 P
22 F
24 P
25 F
27 P
27 P
27 P
35 P
𝟑 𝟑 𝟓 𝟓
Entropy for (a) = -[ * log 2𝟖 + ∗ log 2 ] = .954
𝟖 𝟖 𝟖
𝟏 𝟏
Entropy for (b) = -[ x log 2 ]=0
𝟏 𝟏
𝟖 𝟏
Total entropy for the entire partitioning = * Entropy for (a) + * Entropy for (b)
𝟗 𝟗
𝟖 𝟏
= * .954 + * 0 = .848
𝟗 𝟗
The lowest entropy is at 24. Hence the data set is divided into
intervals for age<=24 and age>24.
Split-point Entropy
Age Grade Age Grade
At 21 .721
21 F 25 F
At 22 .460 22 F 27 P
At 24 .205 24 P 27 P
27 P
At 25 .360
35 P
At 27 .767 [21-41] 41 P
At 35 .848