Data Normalization and Preprocessing Techniques
Data Normalization and Preprocessing Techniques
1. Data cleaning: fill in missing values, smooth noisy data, identify or remove
outliers, and resolve inconsistencies.
2. Data integration: using multiple databases, data cubes, or files.
3. Data transformation: normalization and aggregation.
4. Data reduction: reducing the volume but producing the same or similar
analytical results.
Data cleaning
• Χ2 (chi-square) test
(Observed − Expected ) 2
2 =
Expected
• 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
9
Chi-Square Calculation: An Example
• Min-max normalization preserves the relationships among the original data values.
• It encounter an “out-of-bounds” error ifa future input case for normalization
falls outside of the original data range for A.
• It does not center the mean at 0.
• It makes the variance vary across variables.
• It may not maintain the shape of the original distribution.
• The minimum and maximum values are in the range
FEATURES of [ 0 , 1 ] .
• This method is very sensitive to outliers.
Min-Max normalization Example
1. Let income range be from $12,000 to $98,000. Map income to the range
[0.0, 1.0](ie normalized to). By min-max normalization, a value of
$73,600 for income is transformed to
• Ᾱ and σA are the mean and standard deviation for attribute A respectively.
• Data can include multiple dimensions.
• Feature standardization makes the values of each feature in the data have zero-
mean (when subtracting the mean in the numerator) and unit-variance but not
normal distribution it can be still skewed.
• This method is widely used for normalization in many machine learning algorithms
(e.g., support vector machines, logistic regression, and artificial neural networks
FEATURES
• It scales the variance at 1.
• It centers the mean at 0.
• It preserves the shape of the
original distribution.
• It preserves outliers if they
exist.
• Minimum and maximum
values vary.
COMPARISON
Helpful in the
Min-max Guarantees that
normalization of the data
all the features will have
but not with
the exact same scale.
the exact same scale.
Decimal scaling
• This method normalizes the value of attribute A by moving the decimal point in
the value. This movement of a decimal point depends on the maximum
absolute value of A.
The formula for the decimal scaling is:
• Assuming a dataset S consisting of N examples, M Age 10,11,13,14,17,19,30, 31, 32, 38, 40, 42,70 , 72, 73, 75
• Partitioning rules: 25
20
• Equal-width: equal bucket
15
range 10
46
Discretization using Histogram Analysis
• Similar to Binning
• Unsupervised Discretization Technique because does not use class
information
• Partition the value of attributes into disjoint range called buckets/bins
• Partitioning Rules:
• Equal Width
• Equal Frequency
• Concept of Hierarchy
Partitioning Rules
• How bucket determined and the attribute value partitioned?
• Equal width: Width of each bucket is uniform
• Equal Frequency: the buckets are created , keep in mind the
frequency of each bucket is constant. ([Link] bucket contains roughly
same number of contiguous data samples).
Hierarchy Representation
• organizational structure or mapping in which items are ranked
according to their levels of importance
OR ,
• hierarchy concept refers to a sequence of mappings with a set of
more general concepts to complex concepts.
52
Concept Hierarchy Generation
for Nominal 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}
53
Automatic Concept Hierarchy Generation
• Top-down mapping generally starts with the top with some general
information and ends with the bottom to the specialized information.
Bottom-up mapping
• A cluster refers to a collection of data points aggregated together because of certain similarities.
• K-mean algorithm is one of the centroid based technique. it is also referred to as Lloyd's algorithm.
• K means algorithm takes the unlabeled dataset as input, divides the dataset into k-number of clusters,
and repeats the process until it does not find the best clusters without the need for any training.
• K refers to the number of pre-defined clusters that need to be created in the process, as if K=2, there
will be two clusters, and for K=3, there will be three clusters.
• Each cluster is associated with a centroid and algorithm aims to minimize the sum of distances
between the data point and their corresponding cluster centroids.
K-Means Algorithm Steps
1. Select the number K to decide the number of
clusters. K can be determined using some
techniques like Elbow Method using WCSS(Within
Cluster Sum of Squares), Silhouette Method.
2. Compute random seed points as the centroids or
K points of the clusters of the current partitioning
( A centroid is the imaginary or real location
representing the center of the cluster or mean
point of the cluster .)
3. Assign each object to the cluster with the nearest
seed point based on eulidean distance. Using a
different distance function other than (squared)
Euclidean distance may prevent the algorithm
from converging. Partition objects
into k nonempty subsets by seeing
the closest centroids for each data points.
4. Calculate the variance and place a new centroid of
each cluster based on mean value of the cluster.
Better choice is to place them as much as possible
far away from each other
5. Go back to Step 3, stop when the assignment does
choose the value of "K number of clusters" inK-
means Clustering
• WCSS=∑Pi in Cluster1 distance(Pi C1)2 +∑Piin Cluster2distance(Pi C2)2+∑Pi in
CLuster3 distance(Pi C3)
2
• ∑Pi in Cluster1 distance(Pi C1)2: It is the sum of the square of the distances
between each data point and its centroid within a cluster1 and the
same for the other two terms.
• To find the optimal value of clusters, the elbow method follows the
below steps:
• It executes the K-means clustering on a given dataset for different K
values (ranges from 1-10).
• For each value of K, calculates the WCSS value.
• Plots a curve between calculated WCSS values and the number of
clusters K.
• The sharp point of bend or a point of the plot looks like an arm, then
that point is considered as the best value of K.
Stopping Criteria for
K-Means Clustering
• New Clusters : 1 1: {A1, A4, A8}, 2: {A3, A5, A6}, 3: {A2, A7}
• centroids C1=(3.66, 9), C2=(7, 4.33) and C3=(1.5, 3.5).
Advantagesand Disadvantagesof K-
Means Clustering
ADVANTAGES
• It is very simple to implement.
• It is scalable to a huge data set and also faster to large datasets.
• it adapts the new examples very frequently.
• Generalization of clusters for different shapes and sizes.
DISADVANTAGES
• Slow for large number of samples: As this algorithm access each point of the dataset, it becomes slow when the sample size
grows.
• The k-means algorithm is sensitive to outliers ! Since an object with an extremely large value may substantially distort the
distribution of the data
• Value of K need to be specified beforehand. Choosing the k values manually is a tough job.
• As the number of dimensions increases its scalability decreases.
• It is not suitable to identify clusters with non-convex shapes.
KMedoid
• A medoid can be defined as the point in the cluster, whose dissimilarities with all
the other points in the cluster is minimum. Tthat is, it is a most centrally located
point in the cluster.
• PAM -Partitioning Around Medoids( Kaufmann & Rousseeuw 1987)
• Splits the data set of n objects into k clusters, where the number k of clusters
assumed known a priori (which implies that the programmer must specify)
• Starts from an initial set of medoids and iteratively replaces one of the medoids
by one of the non-medoids if it improves the total distance of the resulting
clustering
• PAM works effectively for small data sets, but does not scale well for large data
sets.
• The dissimilarity of the medoid(Ci) and o b j e c t ( P i ) is calculated by using E =
|Pi - Ci|
• The runtime complexity of the original PAM algorithm per iteration of is O(k(n-
k)2)
ALGORITHM
Build phase:
1. Select k objects to become the medoids, or in
case these objects were provided use them as
the medoids;
2. Calculate the dissimilarity matrix if it was not
provided;
3. Assign every object to its closest medoid;
Swap phase:
4. For each cluster compute the disatnce between
the non-medoid data point o and medoid m.
5. Consider the swap of m and o, and compute the
cost change. See if it decreases the average
dissimilarity coefficient; if it does, select
the entity that decreases this coefficient
6. If the cost change is the current best, remember
this m and o combination
• Medoid process is continued until no any medoid
move
EXAMPLE X Y
2 6
3 4
3 8
• Cluster the given data set of
ten objects into two clusters 4 7
i.e. k= 2. Let the initial
medoids be (3,4) and (7,4) 6 2
6 4
7 3
7 4
8 5
7 6
EXAMPLE
• Cluster the given data set of ten objects into two clusters i.e. k= 2. Let
the initial medoids be (3,4) and (7,4)
x y D1(3,4) D2(7,4) Cluster Cluster1 = {(3,4) (2,6) (3,8)
2 6 3 7 C1 (4,7
Cluster2 = {(7,4) (6,2) (6,4)
3 4 0 4 C1 (7,3 1]
3 8 4 8 C1
4 7 4 6 C1 Cost (Distance)
=3+0+4+4+3+1+1+0+2+2
6 2 5 3 C2 =20
6 4 3 1 C2
7 3 5 1 C2
7 4 4 0 C2
8 5 6 2 C2
7 6 6 2 C2
EXAMPLE
• Let the new medoid O' be (7,3). So new medoids are (3,4) and (7,3)
Let the randomly selected 2 medoids, so select k = 2 and let C1 -(4, 5) and C2 -
(8, 5) are the two medoids.
EXAMPLE
Advantages:
• It is simple to understand and easy to implement.
• K-Medoid Algorithm is fast and converges in a fixed number of steps.
• PAM is less sensitive to outliers than other partitioning algorithms.
Disadvantages:
• The main disadvantage of K-Medoid algorithms is that it is not suitable for clustering non-
spherical (arbitrary shaped) groups of objects. This is because it relies on minimizing the
distances between the non-medoid objects and the medoid (the cluster centre) – briefly, it
uses compactness as clustering criteria instead of connectivity.
• It may obtain different results for different runs on the same dataset because the first k
medoids are chosen randomly.
Given Datapoints:
{2,4,10,12,3,20,30,11,25}
Challenge and Cluster number : 2.
Apply K-Means and K-
Medoid Algorithm
k-mean k-medoid
• Datapoints: {2,4,10,12,3,20,30,11,25} • Given data points: {2, 4, 10, 12, 3, 20, 30, 11, 25}
• Cluster number : 2. Initila centroids 2 and 3 • Number of clusters k=2 . Initial medoids 2 and 3
• Step 1: Value of clusters K1{ 2 } K2{ 3 6 8 12 • Step: 1: {2} {3 6 8 12 15 18 22 25} C: 2&3:S=85
15 18 22 25 } • Step: 2: {2 3 } {6 8 12 15 18 22 25} C:2 &6:S=65
•Centroid m1 and m2 : mean values • Step: 3: {2 3} {8 6 12 15 18 22 25} C:2&8:S=55
m1=2.0 m2=13.625 . Distance: • Step: 4: {2 3 6} {12 8 15 18 22 25} C:2&12:S= 41
• Step 2: Value of clusters K1 {2 3 6} K2 {8 12 15 • Step: 5: {2 3 6 8} {15 12 18 22 25} C:2 &18:S=31
• 18 22 25} Value of m m1=3.66 m2=16.66 • Step: 6: {2 3 6 8} {18 12 15 22 25 } C:2 & 15: S=34.
Stop Iteration as cost increases
• Step 3: Value of clusters K1 {2 3 6 8 } K2 {12
15 18 22 25} Value of m m1=4.75 m2=18.4 • Step: 7: The final clusters by K-Medoids are as
• Step 4: Value of clusters K1 {2 3 6 8 } K2 {12 follows: {2 3 6 8} {18 12 15 22 25}
• 15 18 22 25} Value of m m1=4.75 m2=18.4
• Step 5: The final clusters by K-means are as
follows: K1 {2 3 6 8 } K2 {12 15 18 22 25}
k-mean k-medoid
1. In K-means, the center of a cluster is not 1. In K-medoids chooses actual data points as centers
necessarily one of the input data points . It (medoids or exemplars), which are
is the average/mean between the points in selected randomly and thereby allows for greater
the cluster/data to compute centroid. interpretability of the cluster centers. remaining all
data objects are placed in a cluster having medoid
2. K-means generally requires Euclidean nearest (or most similar) to that data object
distance for efficient solutions.
2. K-medoids can be used with arbitrary dissimilarity
3. Tries to minimize total squared distance or
measures, because k-medoids minimizes a sum of
error pairwise dissimilarities instead of a sum of squared
4. Less robust to noise and outliers Euclidean distances
3. Tries to minimize the absolute distance between
the points and the selected centroid(sum
of dissimilarities between points labeled to be in a
cluster and a point designated as the center of that
cluster)
4. more robust to noise and outliers
Discretization using classification techniques
Discretization using classification techniques
• Classification is one of the important tasks in Data Mining or
Knowledge Discovery with prolific applications.
• Satisfactory classification depends on characteristics of the
dataset too.
• Numerical and nominal attributes are commonly occurred in
the dataset.
• However, classification performance may be aided by
discretization of numerical attributes.
• At present, several discretization methods and numerous
techniques for implementing classifiers exist.
Objective behind Discretization
Classification Technique
• First is to study the effectiveness of discretization of attributes,
• Second is to compare the efficiency of eight discretization methods.
• Methods:
1. ChiMerge
2. Chi2
3. Modified Chi2
4. , Extended Chi2,
5. Class-Attribute Interdependence Maximization (CAIM),
6. Class-Attribute Contingency Coefficient (CACC),
7. Autonomous Discretization Algorithm (Ameva),
8. Minimum Description Length Principle (MDLP).
• Third objective is the study investigates suitability of the eight
discretization methods when applied to the five commonly known
classifiers, Neural Network, K Nearest Neighbour (K-NN), Naive
Bayes, C4.5, and Support Vector machine (SVM).
Data Reduction Techniques
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
91
• Data compression
Data Reduction 1: Dimensionality Reduction
• Curse of dimensionality
• When dimensionality increases, data becomes increasingly sparse
• Density and distance between points, which is critical to clustering, outlier
analysis, becomes less meaningful
• The possible combinations of subspaces will grow exponentially
• Dimensionality reduction
• Avoid the curse of dimensionality
• Help eliminate irrelevant features and reduce noise
• Reduce time and space required in data mining
• Allow easier visualization
• Dimensionality reduction techniques
• Wavelet transforms
• Principal Component Analysis
• Supervised and nonlinear techniques (e.g., feature selection)
92
Mapping Data to a New Space
◼ Fourier transform
◼ Wavelet transform
93
What Is Wavelet Transform?
• Decomposes a signal into
different frequency subbands
• Applicable to n-dimensional
signals
• Data are transformed to preserve
relative distance between objects
at different levels of resolution
• Allow natural clusters to become
more distinguishable
• Used for image compression
94
Wavelet Transformation
Haar2 Daubechie4
• Discrete wavelet transform (DWT) for linear signal processing,
multi-resolution analysis
• Compressed approximation: store only a small fraction of the
strongest of the wavelet coefficients
• Similar to discrete Fourier transform (DFT), but better lossy
compression, localized in space
• Method:
• Length, L, must be an integer power of 2 (padding with 0’s, when
necessary)
• Each transform has 2 functions: smoothing, difference
• Applies to pairs of data, resulting in two set of data of length L/2
• Applies two functions recursively, until reaches the desired length
95
Wavelet Decomposition
• Wavelets: A math tool for space-efficient hierarchical decomposition of functions
• 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]
• Compression: many small detail coefficients can be replaced by 0’s, and only the
significant coefficients are retained
96
Haar Wavelet Coefficients Coefficient “Supports”
Hierarchical
2.75
2.75 +
decomposition
structure (a.k.a. + -1.25 + -
“error tree”) + -1.25
-
0.5 0
0.5 + -
+ - + - 0 + -
0 -1 -1 0
+
- + - + - + -
0 + -
2 2 0 2 3 5 4 4 -1 + -
-1 + -
Original frequency distribution 0 + -
97
Why Wavelet Transform?
• Use hat-shape filters
• Emphasize region where points cluster
• Suppress weaker information in their boundaries
• Effective removal of outliers
• Insensitive to noise, insensitive to input order
• Multi-resolution
• Detect arbitrary shaped clusters at different scales
• Efficient
• Complexity O(N)
• Only applicable to low dimensional data
98
Principal Component Analysis (PCA)
x2
x1
99
Principal Component Analysis (Steps)
• 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)
• Works for numeric data only
100
Data Filtering
Data Filtering
• Data filtering is the process of choosing a smaller part of your data set
and using that subset for viewing or analysis.
• Filtering is generally (but not always) temporary – the complete data
set is kept, but only part of it is used for the calculation.
Data filtering-noise removal
• It is the process of getting rid of noise such as outlier values and error
data from raw data to make the data clean and be proper for further
processing.
• Example , In the process of weather forecast, there will be collecting a
large amount of data as data will be collected every day or every three
hours.
General Used of Filtering
• Look at results for a particular period of time.
• The table below shows some of the rows of a data set from a survey
about peoples’ preferred Cola.
• Conducting the analysis using only the information contained in those selected
observations.
• For example, the table below show the data filtered for Males only.
• The darker colored rows are kept in the analysis while the remaining rows are
excluded.
• Results computed for Males are then calculated based on the highlighted rows
(ID’s 2, 9, 11, 12, 13, 14).
• If we want to know the average rating for Coca-Cola among males, we would
compute that as (5 + 5 + 4 + 5 + 5 + 3) / 6 = 4.5.
Results for different groups
• A basic need for most research is to obtain results for different groups
in the data.
• In each case, a logical rule defines whether each case in the sample is
excluded or included.
Example Filtering Transform Results
• From the example above, we may wish to compute the average
rating for each beverage within for the Males in the sample.
Such filtering transforms the results like this:
Data Filtering Techniques
• Moving average filtering
• Local regression filtering
• Savitzky- Golay filtering
• Hamming window filtering
Method 1: Moving average filtering
• Moving average filtering is a simple data filtering technique by
calculating the average value of every point in the selected window.
• This filtering technique will specify weight for every data point
• Here window selected by using regression weight function. Given in Eq.
• wi is regression weight of points i,
• x is the predictor value associated with the response value to be smooth,
• xi are the nearest neighbors of x as defined by the selected window, and
• d(x) is the distance along the abscissa from x to the most distant predictor value
within the selected window.
Types of Local regression filtering
1. lowess local regression: uses the method of linear regression
analysis.
2. loess local regression: uses the method of polynomial square
regression analysis
3. rlowess local regression: This method the robust function can be
used to get rid of outlier values. It can be applied with lowess local
regression and
4. rloess local regression: which applied to loess local regression.
additionally , robust function can be used to get rid of outlier
values.
Method 3- Savitzky-Golay filtering
• Data filtering techniques - a characteristic of frequency-wave.
• This technique uses the simple polynomial least–square calculation,
which will not filter too many details out of the data.
• The control parameters are the size of the window and the
polynomial degree.
• Here the size of window has higher value than the polynomial degree.
Formula for calculation of filtered Data
Parameters used for Savitzky-Golay filtering
• (yk)s is the filtered data (smoothing) at point k,
• yk is the data at the point k (before smoothing),
• n is a number of positions of points in each side (left side or right
side), –n ≤ i ≤ n,
• Ai is the value of coefficient weight at position i.
Usage of this Filtering Method
• .This filtering technique has been applied in many fields such as
decreasing noise in ultra sound image, radar image and etc.
Method 4- Hamming window filtering
• It is the data filtering technique that uses signal processing technique.
• It is a method for frequency filtering of finite impulse response .
here w(k) is the window function, k is a value of data at point k, and K is a number
of data points of the window function.
Sampling
Sampling
• Sampling: obtaining a 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)
124
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
125
Sampling: With or without Replacement
Raw Data
126
Sampling: Cluster or Stratified Sampling
127
Attribute Subset Selection
Techniques
Attribute Subset Selection Techniques
• Attribute subset Selection is a technique which is used for data
reduction in data mining process.
• Data reduction reduces the size of data so that it can be used for
analysis purposes more efficiently.
Need of Attribute Subset Selection
• The data set may have a large number of attributes. But some of
those attributes can be irrelevant or redundant.
• The goal of attribute subset selection is to find a minimum set of
attributes such that dropping of those irrelevant attributes does not
much affect the utility of data and the cost of data analysis could be
reduced.
• Mining on a reduced data set also makes the discovered pattern
easier to understand.
Process of Attribute Subset Selection-
• The brute force approach can be very expensive in which each subset (2^n
possible subsets) of the data having n attributes can be analysed.
• The best way to do the task is to use the statistical significance tests such
that best (or worst) attributes can be recognized.
• Statistical significance test assumes that attributes are independent of one
another.
• This is a kind of greedy approach in which a significance level is decided
(statistically ideal value of significance level is 5%) and the models are
tested again and again until p-value (probability value) of all attributes is
less than or equal to the selected significance level.
• The attributes having p-value higher than significance level are discarded.
• This procedure is repeated again and again until all the attribute in data set
has p-value less than or equal to the significance level.
• This gives us the reduced data set having no irrelevant attributes.
Methods of Attribute Subset Selection-
1. Stepwise Forward Selection.
2. Stepwise Backward Elimination.
3. Combination of Forward Selection and Backward Elimination.
4. Decision Tree Induction.
• All the above methods are greedy approaches for attribute subset
selection.
Features of Methods
• These methods are usually greedy in that while searching
through attribute space, they always create what looks to be the
better choice at the time. Their strategy is to make a locally
optimal choice in the hope that this will lead to a globally optimal
solution. Such greedy approaches are efficient in practice and
can come close to estimating an optimal solution.
• The best and worst attributes are generally determined using
tests of statistical significance, which consider that the attributes
are separate from one another. Some other attribute evaluation
measures can be used, including the information gain measure
used in building decision trees for classification.
Stepwise Forward Selection:
The process starts with a null set of attributes as the reduced set.
no yes yes
140
Algorithm for Decision Tree Induction
• Basic algorithm (a greedy algorithm)
• Tree is constructed in a top-down recursive divide-and-conquer
manner
• At start, all the training examples are at the root
• Attributes are categorical (if continuous-valued, they are
discretized in advance)
• Examples are partitioned recursively based on selected
attributes
• Test attributes are selected on the basis of a heuristic or
statistical measure (e.g., information gain)
• Conditions for stopping partitioning
• All samples for a given node belong to the same class
• There are no remaining attributes for further partitioning –
majority voting is employed for classifying the leaf
• There are no samples left
141
Brief Review of Entropy
m=2
142
ID3 in brief
• D3 stands for Iterative Dichotomiser 3 and is named such because the
algorithm iteratively (repeatedly) dichotomizes(divides) features into
two or more groups at each step.
• Invented by Ross Quinlan, ID3 uses a top-down greedy approach to
build a decision tree. In simple words, the top-down approach means
that we start building the tree from the top and the greedy approach
means that at each iteration we select the best feature at the present
moment to create a node.
• Most generally ID3 is only used for classification problems
with nominal features only.
Metrics in ID3
where,
n is the total number of classes in the target column
(in our case n = 2 i.e YES and NO)
pᵢ is the probability of class ‘i’ or the ratio of “number of rows with class
i in the target column” to the “total number of rows” in the dataset.
Computation of Information Gain
• IG(S, A) = Entropy(S) - ∑((|Sᵥ| / |S|) * Entropy(Sᵥ))
• where Sᵥ is the set of rows in S for which the feature column A has
value v,
• |Sᵥ| is the number of rows in Sᵥ and likewise |S| is the number of rows
in S
• A is the Feature Column(Attribute)
ID3 Steps:
[Link] the Information Gain of each feature.
[Link] that all rows don’t belong to the same class, split the
dataset S into subsets using the feature for which the Information
Gain is maximum.
[Link] a decision tree node using the feature with the maximum
Information gain.
[Link] all rows belong to the same class, make the current node as a leaf
node with the class as its label.
[Link] for the remaining features until we run out of all features, or
the decision tree has all leaf nodes.
Attribute Selection Measure:
Information Gain (ID3/C4.5)
◼ Select the attribute with the highest information gain
◼ Let pi be the probability that an arbitrary tuple in D belongs to
class Ci, estimated by |Ci, D|/|D|
◼ Expected information (entropy) needed to classify a tuple in D:
m
Info( D ) = − pi log 2 ( pi )
i =1
◼ Information needed (after using A to split D into v partitions) to
classify D: v | D |
Info A ( D) = Info( D j )
j
j =1 | D |
◼ Information gained by branching on attribute A
Gain(income) = 0.029
>40 low yes excellent no
31…40 low yes excellent yes
<=30 medium no fair no
<=30
>40
low
medium
yes fair
yes fair
yes
yes
Gain( student) = 0.151
<=30
31…40
medium
medium
yes excellent
no excellent
yes
yes Gain(credit _ rating ) = 0.048
149 31…40 high yes fair yes
>40 medium no excellent no
Example Covid 19 data set
• ID | Fever | Cough | Breathing issues | Infected |
+----+-------+-------+------------------+----------+
| 1 | NO | NO | NO | NO |
+----+-------+-------+------------------+----------+
| 2 | YES | YES | YES | YES |
+----+-------+-------+------------------+----------+
| 3 | YES | YES | NO | NO |
+----+-------+-------+------------------+----------+
| 4 | YES | NO | YES | YES |
+----+-------+-------+------------------+----------+
| 5 | YES | YES | YES | YES |
+----+-------+-------+------------------+----------+
| 6 | NO | YES | NO | NO |
+----+-------+-------+------------------+----------+
| 7 | YES | NO | YES | YES |
+----+-------+-------+------------------+----------+
| 8 | YES | NO | YES | YES |
+----+-------+-------+------------------+----------+
| 9 | NO | YES | YES | YES |
+----+-------+-------+------------------+----------+
| 10 | YES | YES | NO | YES |
+----+-------+-------+------------------+----------+
| 11 | NO | YES | NO | NO |
+----+-------+-------+------------------+----------+
| 12 | NO | YES | YES | YES |
+----+-------+-------+------------------+----------+
| 13 | NO | YES | YES | NO |
+----+-------+-------+------------------+----------+
| 14 | YES | YES | NO | NO |
+----+-------+-------+------------------+----
Computation Entropy
• From the total of 14 rows in our dataset S, there are 8 rows with the
target value YES and 6 rows with the target value NO.
• Next, from the remaining two unused features, namely, Fever and
Cough, we decide which one is the best for the left branch of
Breathing Issues.
• Next, from the remaining two unused features,
namely, Fever and Cough, we decide which one is the best for the left
branch of Breathing Issues.
Since the left branch of Breathing Issues denotes YES, we will work
with the subset of the original data i.e the set of rows having YES as
the value in the Breathing Issues column
• Fever | Cough | Breathing issues | Infected |
+-------+-------+------------------+----------+
| YES | YES | YES | YES |
+-------+-------+------------------+----------+
| YES | NO | YES | YES |
+-------+-------+------------------+----------+
| YES | YES | YES | YES |
+-------+-------+------------------+----------+
| YES | NO | YES | YES |
+-------+-------+------------------+----------+
| YES | NO | YES | YES |
+-------+-------+------------------+----------+
| NO | YES | YES | YES |
+-------+-------+------------------+----------+
| NO | YES | YES | YES |
+-------+-------+------------------+----------+
| NO | YES | YES | NO |
+-------+-------+------------------+----------+
• Next, we calculate the IG for the features Fever and Cough using the
subset Sʙʏ (Set Breathing Issues Yes) which is shown above :
• Note: For IG calculation the Entropy will be calculated from the subset
Sʙʏ and not the original dataset S.
IG calculation the Entropy will be calculated from
the subset Sʙʏ and not the original dataset S
• IG(Sʙʏ, Fever) = 0.20
IG(Sʙʏ, Cough) = 0.09
• G of Fever is greater than that of Cough, so we select Fever as the left
branch of Breathing Issues:
• Next, we find the feature with the maximum IG for the right branch
of Breathing Issues. But, since there is only one unused feature left
we have no other choice but to make it the right branch of the root
node.
• There are no more unused
------+-------+------------------+----------+
features, so we stop here | Fever | Cough | Breathing issues | Infected
and jump to the final step of |
+-------+-------+------------------+----------+
creating the leaf nodes. | YES | YES | YES | YES |
For the left leaf node of +-------+-------+------------------+----------+
Fever, we see the subset of | YES | NO | YES | YES |
+-------+-------+------------------+----------+
rows from the original data | YES | YES | YES | YES |
set that has Breathing +-------+-------+------------------+----------+
| YES | NO | YES | YES |
Issues and Fever both +-------+-------+------------------+----------+
values as YES. | YES | NO | YES | YES |
+-------+-------+------------------+----------+
• Since all the values in the target column are YES, we label the left leaf node
as YES, but to make it more logical we label it Infected.
• Similarly, for the right node of Fever we see the subset of rows from the
original data set that have Breathing Issues value as YES and Fever as NO.
• -------+-------+------------------+----------+
| Fever | Cough | Breathing issues | Infected |
+-------+-------+------------------+----------+
| NO | YES | YES | YES |
+-------+-------+------------------+----------+
| NO | YES | YES | NO |
+-------+-------+------------------+----------+
| NO | YES | YES | NO |
+-------+-------+------------------+----------+
• Here not all but most of the values are NO, hence NO or Not
Infected becomes our right leaf node
• We repeat the same process for the node Cough, however here both
left and right leaves turn out to be the same i.e. NO or Not
Infected as shown below:
•
• Pruning is a mechanism that reduces the size and complexity of a
Decision tree by removing unnecessary nodes.
• Another drawback of ID3 is overfitting or high variance i.e. it learns
the dataset it used so well that it fails to generalize on new data.
ID3 Algorithms Conclusion
• We covered the process of the ID3 algorithm in detail and saw how
easy it was to create a Decision Tree using this algorithm by using only
two metrics viz. Entropy and Information Gain.
Outlier Analysis
What Are Outliers?
• Outlier: A data object that deviates significantly from the normal objects as if it were generated
by a different mechanism
• Ex.: Unusual credit card purchase, sports: Michael Jordon, Wayne Gretzky, ...
• Outliers are different from the noise data
• Noise is random error or variance in a measured variable
• Noise should be removed before outlier detection
• Outliers are interesting: It violates the mechanism that generates the normal data
• Outlier detection vs. novelty detection: early stage, outlier; but later merged into the model
• Applications:
• Credit card fraud detection
• Telecom fraud detection
• Customer segmentation
• Medical analysis
170
Types of Outliers (I)
• Three kinds: global, contextual and collective outliers
• Global outlier (or point anomaly) Global Outlier
• Object is Og if it significantly deviates from the rest of the data set
• Ex. Intrusion detection in computer networks
• Issue: Find an appropriate measurement of deviation
• Contextual outlier (or conditional outlier)
• Object is Oc if it deviates significantly based on a selected context
• Ex. 80o F in Urbana: outlier? (depending on summer or winter?)
• Attributes of data objects should be divided into two groups
• Contextual attributes: defines the context, e.g., time & location
• Behavioral attributes: characteristics of the object, used in outlier
evaluation, e.g., temperature
• Can be viewed as a generalization of local outliers—whose density
significantly deviates from its local area
• Issue: How to define or formulate meaningful context?
171
Types of Outliers (II)
• Collective Outliers
• A subset of data objects collectively deviate significantly
from the whole data set, even if the individual data objects
may not be outliers
• Applications: E.g., intrusion detection: Collective Outlier
• When a number of computers keep sending denial-of-
service packages to each other
◼ Detection of collective outliers
◼ Consider not only behavior of individual objects, but also that of
groups of objects
◼ Need to have the background knowledge on the relationship
◼ The border between normal and outlier objects is often a gray area
between normal objects and outliers. It may help hide outliers and
reduce the effectiveness of outlier detection
◼ Understandability
◼ Understand why these are outliers: Justification of the detection
174
Outlier Detection I: Supervised Methods
• Two ways to categorize outlier detection methods:
• Based on whether user-labeled examples of outliers can be obtained:
• Supervised, semi-supervised vs. unsupervised methods
• Based on assumptions about normal data and outliers:
• Statistical, proximity-based, and clustering-based methods
• Outlier Detection I: Supervised Methods
• Modeling outlier detection as a classification problem
• Samples examined by domain experts used for training & testing
• Methods for Learning a classifier for outlier detection effectively:
• Model normal objects & report those not matching the model as
outliers, or
• Model outliers and treat those not matching the model as normal
• Challenges
• Imbalanced classes, i.e., outliers are rare: Boost the outlier class and
make up some artificial outliers
• Catch as many outliers as possible, i.e., recall is more important than
accuracy (i.e., not mislabeling normal objects as outliers)
175
Outlier Detection II: Unsupervised Methods
• Assume the normal objects are somewhat ``clustered'‘ into multiple groups,
each having some distinct features
• An outlier is expected to be far away from any groups of normal objects
• Weakness: Cannot detect collective outlier effectively
• Normal objects may not share any strong patterns, but the collective
outliers may share high similarity in a small area
• Ex. In some intrusion or virus detection, normal activities are diverse
• Unsupervised methods may have a high false positive rate but still miss
many real outliers.
• Supervised methods can be more effective, e.g., identify attacking some key
resources
• Many clustering methods can be adapted for unsupervised methods
• Find clusters, then outliers: not belonging to any cluster
• Problem 1: Hard to distinguish noise from outliers
• Problem 2: Costly since first clustering: but far less outliers than normal
objects
• Newer methods: tackle outliers directly
176
Outlier Detection III: Semi-Supervised Methods
• Situation: In many applications, the number of labeled data is often small:
Labels could be on outliers only, normal objects only, or both
• If only some labeled outliers are available, a small number of labeled outliers
many not cover the possible outliers well
• To improve the quality of outlier detection, one can get help from models
for normal objects learned from unsupervised methods
177
Outlier Detection (1): Statistical Methods
• Statistical methods (also known as model-based methods) assume that the normal
data follow some statistical model (a stochastic model)
• The data not following the model are outliers.
178
Outlier Detection (2): Proximity-Based Methods
• An object is an outlier if the nearest neighbors of the object are far away, i.e., the
proximity of the object is significantly deviates from the proximity of most of the
other objects in the same data set
180