Week 5 - Data Mining Exploring Data With R
Week 5 - Data Mining Exploring Data With R
▪ Attributes/Features
▪ Types of Data Sets
▪ Data Quality
▪ Data Preprocessing
▪ Similarity and Dissimilarity
▪ Density
What is Data?
▪ Collection of data objects Attributes
and their attributes
Objects
• Attribute is also known as 5 No Divorced 95K Yes
variable, field, characteristic
6 No Married 60K No
▪ A collection of attributes 7 Yes Divorced 220K No
describe an object
8 No Single 85K Yes
• Object is also known as
record, point, case, sample, 9 No Married 75K No
entity, or instance 10 No Single 90K Yes
Attribute Values
Nominal The values of a nominal attribute are zip codes, employee mode, entropy,
just different names, i.e., nominal ID numbers, eye color, contingency
attributes provide only enough sex: {male, female} correlation, 2 test
information to distinguish one object
from another. (=, )
Ratio For ratio variables, both differences temperature in Kelvin, geometric mean,
and ratios are meaningful. (*, /) monetary quantities, harmonic mean,
counts, age, mass, percent variation
length, electrical
current
Attribute Transformation Comments
Level
▪ Discrete Attribute
—Has only a finite or countably infinite set of values
—Examples: zip codes, counts, or the set of words in a collection of documents
—Often represented as integer variables.
—Note: binary attributes are a special case of discrete attributes
▪ Continuous Attribute
—Has real numbers as attribute values
—Examples: temperature, height, or weight.
—Practically, real values can only be measured and represented using a finite
number of digits.
—Continuous attributes are typically represented as floating-point variables.
Examples
▪ Attributes/Features
▪ Types of Data Sets
▪ Data Quality
▪ Data Preprocessing
▪ Similarity and Dissimilarity
▪ Density
Types of data sets
▪ Record
—Data Matrix
—Document Data
—Transaction Data
▪ Graph
—World Wide Web
—Molecular Structures
▪ Ordered
—Spatial Data
—Temporal Data
—Sequential Data
—Genetic Sequence Data
Important Characteristics of Structured Data
▪ Dimensionality
— Curse of Dimensionality
▪ Sparsity
— Only presence counts
▪ Resolution
— Patterns depend on the scale
Record Data
▪ If data objects have the same fixed set of numeric attributes, then
the data objects can be thought of as points in a multi-dimensional
space, where each dimension represents a distinct attribute
▪ Such data set can be represented by an m by n matrix, where there
are m rows, one for each object, and n columns, one for each
attribute
n attributes
Sepal.Length Sepal.Width Petal.Length Petal.Width
timeout
season
coach
game
score
team
ball
lost
pla
wi
n
y
Document 1 3 0 5 0 2 6 0 2 0 2
Document 2 0 7 0 2 1 0 0 3 0 0
Document 3 0 1 0 0 1 2 2 0 3 0
Transaction Data
TID Items
1 Bread, Coke, Milk
2 Beer, Bread
3 Beer, Coke, Diaper, Milk
4 Beer, Bread, Diaper, Milk
5 Coke, Diaper, Milk
Graph Data
▪ Examples: Generic graph and HTML Links
<a href="papers/papers.html#bbbb">
Data Mining </a>
<li>
2 <a href="papers/papers.html#aaaa">
Graph Partitioning </a>
<li>
5 1 <a href="papers/papers.html#aaaa">
Parallel Solution of Sparse Linear System of Equations </a>
<li>
2 <a href="papers/papers.html#ffff">
N-Body Computation and Dense Linear System Solvers
5
Graph Data
2
5 1
2
5
▪ Sequences of transactions
Items/Events
An element of
the sequence
Ordered Data
GGTTCCGCCTTCAGCCCCGCGCC
CGCAGGGCCCGCCCCGCGCCGTC
GAGAAGGGCCCGCCTGGCGGGCG
GGGGGAGGCGGGGCCGCCCGAGC
CCAACCGAGTCCGACCAGGTGCC Subsequences
CCCTCTGCTCGGCCTAGACCTGA
GCTCATTAGGCGGCAGCGGACAG
GCCAAGTAGAACACGCGAAGCGC
TGGGCTGCCTGCTGCGACCAGGG
Ordered Data: Time Series Data
Ordered Data: Spatio-Temporal
, Feb, Mar, …
Average Monthly
Temperature of
land and ocean
Topics
▪ Attributes/Features
▪ Types of Data Sets
▪ Data Quality
▪ Data Preprocessing
▪ Similarity and Dissimilarity
▪ Density
Data Quality
▪ Causes?
Missing Values
▪ Data set may include data objects that are duplicates, or "close
duplicates" of one another
—Major issue when merging data from heterogeneous sources
▪ Examples:
—Same person with multiple email addresses
▪ Data cleaning
—Process of dealing with duplicate data issues
—ETL tools typically support deduplication
Topics
▪ Attributes/Features
▪ Types of Data Sets
▪ Data Quality
▪ Data Preprocessing
▪ Similarity and Dissimilarity
▪ Density
Data Preprocessing
▪ Aggregation
▪ Sampling
▪ Dimensionality Reduction
▪ Feature subset selection
▪ Feature creation
▪ Discretization and Binarization
▪ Attribute Transformation
Aggregation
▪ Purpose
—Data reduction
• Reduce the number of attributes or objects
—Change of scale
• Cities aggregated into regions, states, countries, etc
—More “stable” data
• Aggregated data tends to have less variability (e.g., reduce seasonality by aggregation to
yearly data)
Aggregation
Variation of Precipitation in Australia
▪ What sample size is necessary to get at least one object from each of 10
groups.
▪ Purpose:
—Avoid curse of dimensionality
—Reduce amount of time and memory required by data mining algorithms
—Allow data to be more easily visualized
—May help to eliminate irrelevant features or reduce noise
▪ Techniques
—Principle Component Analysis
—Singular Value Decomposition
—Others: supervised and non-linear techniques
Dimensionality Reduction: Principal
Components Analysis (PCA)
▪ Goal: Map points to a lower dimensional space while preserving
distance information.
▪ Goal: Unroll the “swiss roll!“ (i.e., preserve distances on the roll)
▪ Method: Use a non-metric space, i.e., distances are not measured by
Euclidean distance, but along the surface of the roll (geodesic distances).
1. Construct a neighbourhood graph (k-nearest neighbors or within a radius).
2. For each pair of points in the graph, compute the shortest path distances =
geodesic distances.
3. Create a lower dimensional embedding using the geodesic distances (multi-
dimensional scaling; MDS)
Low-dimensional Embedding
▪ General notion of representing objects described in one space (i.e., set of features) in
a different space using a map 𝑓 ∶ 𝑋 → 𝑌
▪ PCA is an example where Y is the space spanned by the principal components and
objects close in the original space X are embedded in space Y.
▪ Low-dimensional embeddings can be produced with various other methods:
—T-SNA: T-distributed Stochastic Neighbor Embedding; non-linear for visualization of
high-dimensional datasets.
—Autoencoders (deep learning): non-linear
—Word embedding: Word2vec, GloVe, BERT
Word Embedding
Autoencoder
Feature Subset Selection
▪ Redundant features
—duplicate much or all of the information contained in one or more other
attributes (are correlated)
—Example: purchase price of a product and the amount of sales tax paid
▪ Irrelevant features
—contain no information that is useful for the data mining task at hand
—Example: students' ID is often irrelevant to the task of predicting students'
GPA
Feature Subset Selection
▪ Embedded approaches:
— Feature selection occurs naturally as part of the data mining algorithm (e.g.,
regression, decision trees).
▪ Filter approaches:
— Features are selected before data mining algorithm is run
—(e.g., highly correlated features)
▪ Brute-force approach:
—Try all possible feature subsets as input to data mining algorithm and choose
the best.
▪ Wrapper approaches:
— Use the data mining algorithm as a black box to find best subset of
attributes (often using greedy search)
Feature Creation
A
B
C
D
3 categories for both x and y 5 categories for both x and y
Attribute Transformation
′
𝑥 − 𝑥ҧ
𝑥 =
𝑠𝑥
𝑥ҧ … column (attribute) mean
𝑠𝑥 … column (attribute) standard deviation
Topics
▪ Attributes/Features
▪ Types of Data Sets
▪ Data Quality
▪ Data Preprocessing
▪ Similarity and Dissimilarity
▪ Density
Similarity and Dissimilarity
▪ Similarity
—Numerical measure of how alike two data objects are.
—Is higher when objects are more alike.
—Often falls in the range [0,1]
▪ Dissimilarity
—Numerical measure of how different are two data objects
—Lower when objects are more alike
—Minimum dissimilarity is often 0
—Upper limit varies
▪ Proximity refers to a similarity or dissimilarity
Similarity/Dissimilarity for Simple Attributes
p and q are the attribute values for two data objects.
𝑠=𝑓 𝑑
f can be any strictly
decreasing function.
point x y
Euclidean Distance p 0 2
q 2 0
𝑛
𝑑𝐸 = 𝑝𝑘 − 𝑞𝑘 2 = 𝒑−𝒒 2
𝑘=1
p1 p2 p3 p4
p1 0.00 2.83 3.16 5.10
p2 2.83 0.00 1.41 3.16
p3 3.16 1.41 0.00 2.00
p4 5.10 3.16 2.00 0.00
Distance Matrix
point x y
Minkowski Distance p 0 2
q 2 0
▪ Do not confuse r with n, i.e., all these distances are defined for all
numbers of dimensions.
Minkowski Distances Distance Matrix
𝑳𝟏 p1 p2 p3 p4
p1 0 4 4 6
p2 4 0 2 4
p3 4 2 0 2
p4 6 4 2 0
point x y
p1 0 2 𝑳𝟐 p1 p2 p3 p4
p1 0.00 2.83 3.16 5.10
p2 2 0
p2 2.83 0.00 1.41 3.16
p3 3 1
p3 3.16 1.41 0.00 2.00
p4 5 1
p4 5.10 3.16 2.00 0.00
𝑳∞ p1 p2 p3 p4
p1 0 2 3 5
p2 2 0 1 3
p3 3 1 0 2
p4 5 3 2 0
Mahalanobis Distance
𝑑𝑚𝑎ℎ𝑎𝑙𝑎𝑛𝑜𝑏𝑖𝑠 𝒑, 𝒒 = 𝒑 − 𝒒 𝑇 𝑆 −1 𝒑 − 𝒒
Measures how many standard deviations two points are away from each other →
scale invariant measure
Example: For red points, the Euclidean distance is 14.7, Mahalanobis distance is 6.
Mahalanobis Distance
y Covariance Matrix:
.3 .2
𝑆=
.2 .3
C
A: (0.5, 0.5)
B B: (0, 1)
C: (1.5, 1.5)
A
𝑑𝑚𝑎ℎ𝑎𝑙 𝐴, 𝐵 = 5
𝑑𝑚𝑎ℎ𝑎𝑙 (𝐴, 𝐶) = 4
x
Data varies in direction A-C more than in A-B!
Cosine Similarity
Example:
A= 3205000200
B= 1000000102
𝑨⋅𝑩 = 3∗1 + 2∗0 + 0∗0 + 5∗0 + 0∗0 + 0∗0 + 0∗0 + 2∗1 + 0∗0 + 0∗2 = 5
𝑨 = 3 ∗ 3 + 2 ∗ 2 + 0 ∗ 0 + 5 ∗ 5 + 0 ∗ 0 + 0 ∗ 0 + 0 ∗ 0 + 2 ∗ 2 + 0 ∗ 0 + 0 ∗ 0 0.5 = 6.481
𝑩 = (1 ∗ 1 + 0 ∗ 0 + 0 ∗ 0 + 0 ∗ 0 + 0 ∗ 0 + 0 ∗ 0 + 0 ∗ 0 + 1 ∗ 1 + 0 ∗ 0 + 2 ∗ 2) 0.5 = 2.245
𝑠𝑐𝑜𝑠𝑖𝑛𝑒 = .3150
Cosine similarity is often used for word count vectors to compare documents.
Similarity Between Binary Vectors
p= 1000000000
q= 0000001001
where ∙ is the dot product between two vectors and ||∙||2 is the
Euclidean norm (length of the vector).
x y
A 2 1
B 4 3
C 1 1
▪ Estimation:
▪ Attributes/Features
▪ Types of Data Sets
▪ Data Quality
▪ Data Preprocessing
▪ Similarity and Dissimilarity
▪ Density
Density
▪ Examples:
—Probability density (function) = describes the likelihood of a random variable
taking a given value
▪ Attributes/Features
▪ Types of Data Sets
▪ Data Quality
▪ Data Preprocessing
▪ Similarity and Dissimilarity
▪ Density
Examples of Classification Task
▪ Example: the 50th percentile is the value 𝑥50% such that 50% of all
values of x are less than 𝑥50% .
Median – 50% of the
Percentiles cases has a smaller value & 50%
are larger
xp
xp
Multivariate Summary Statistics
2 2 4
sij =
m− 1
∑ k= 1
( xki − x̄ i )(x kj − x̄ j )
... ... ...
m 18 4 ▪ Correlation
sij
r ij=
si s j
▪ 𝑠𝑖 is the variance of feature i
Topics
▪ The following shows the Sea Surface Temperature (SST) for July 1982
▪ Tens of thousands of data points are summarized in a single figure
Representation
…
Distribution: Histograms
▪ Invented by J. Tukey
▪ Simplified version of a PDF/histogram.
outlier
75th percentile +
1.5 IQR
75th percentile
25th percentile –
1.5 IQR
PDF or histogram
Examples of Box Plots
Celsius
Matrix Plots
Reordered features
Other Visualization Techniques
▪ Star Plots
—Similar approach to parallel coordinates, but axes radiate from a central
point
—The line connecting the values of an object is a polygon
▪ Chernoff Faces
—Approach created by Herman Chernoff
—This approach associates each attribute with a characteristic of a face
—The values of each attribute determine the appearance of the corresponding
facial characteristic
—Each object becomes a separate face
—Relies on human’s ability to distinguish faces
Star Plots for Iris Data
▪ Setosa
▪ Versicolor
▪ Virginica
Chernoff Faces for Iris Data
▪ Setosa
▪ Versicolor
▪ Virginica
•Created by Ross Ihaka and Robert Gentleman at the
University of Auckland, New Zealand
•Currently developed by the R Development Core Team.
R vs. RStudio
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
R-Studio UI
Write your Global Environment-
code here See your datasets here
Console - see
your code run
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
Outline for this Session
1. Introduction to R
2. Data Post-processing
3. Graphics and Plotting
4. Regression Analysis using R
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing
https://phlconnect.ched.gov.ph/content/view/business-analytics-data-post-processing