Data Understanding
Data Understanding
4 Relationships in data
Correlation and Pearson correlation
Spearman’s rank correlation
Pearson’s chi–square test for categorical data
Correlation versus causation
5 Excercises, References, and Summary
1 Business understanding
2 Data understanding
3 Data preparation
4 Modeling
5 Evaluation
6 Deployment
This phase focuses on understanding the objectives and requirements of the project. It
includes four tasks:
1 Determine business objectives:
thoroughly understand, from a business perspective, what the customer/company
really wants to accomplish, and then define business success criteria.
2 Assess situation:
determine resources availability, project requirements, assess risks and contingencies,
and conduct a cost–benefit analysis.
3 Determine data mining goals:
in addition to defining the business objectives, you should also define what success
looks like from a technical data mining perspective.
4 Produce project plan:
select technologies and tools and define detailed plans for each project phase.
This phase drives the focus to identify, collect, and analyze the data sets that can help
you accomplish the project goals. This phase also has four tasks:
1 Collect initial data:
acquire the necessary data and (if necessary) load it into your analysis tool.
2 Describe data:
examine the data and document its surface properties like data format, number of
records, or field identities.
3 Explore data:
dig deeper into the data. Query it, visualize it, and identify relationships among the
data.
4 Verify data quality:
how clean/dirty is the data? Document any quality issues.
An ordinal attribute:
Has meaningful order or ranking among its values.
But the magnitude between successive values is not known.
Examples:
Size of drinks: small, medium, large.
Grade: A+, A, B+, B, etc.
Rating: 1 (very dissatisfied), 2 (dissatisfied), 3 (neutral), 4 (satisfied), and 5 (very satisfied ).
A numeric attribute
is a quantitative and measurable quantity, represented in integer or real values.
Numeric attributes can be:
Interval-scaled
Ratio-scaled
An attribute is countably infinite if the set of possible values is infinite but the
values can be put in a one-to-one correspondence with natural numbers. For
example, the attribute CustomerID is countably infinite.
4 Relationships in data
Correlation and Pearson correlation
Spearman’s rank correlation
Pearson’s chi–square test for categorical data
Correlation versus causation
5 Excercises, References, and Summary
Univariate data is a type of data which consists observations from only one variable
( X ) , i.e., a single characteristic or attribute:
(1)
Examples:
The Covid-19 test results of a sample of 12 persons:
D = {neg, pos, neg, neg, neg, pos, neg, neg, pos, neg, neg, neg}
Marks of a student for the last 15 courses:
D = {A,A+ ,B ,B ,A,B + , A+ ,A,B , C ,C , A,B + , B ,A}
Messi’s goals for Barcelona from 2004–2005to 2020–2021:
D = {1, 8, 17, 16, 38, 47, 53, 73, 60, 41, 58, 41, 54, 45, 51, 31, 38}
The average high temperature in Hanoi for 12 months (oC):
D = {19.7, 20.1, 22.9, 27.2, 31.4, 32.9, 33.1, 32.3, 31.2, 28.8, 25.3, 22.0}
Univariate data analysis involves descriptive statistics like central tendency (mean,
median, mode), dispersion (range, variance, quartiles, standard deviation), etc.
Univariate data visualization can be frequency distribution tables, bar charts,
histograms, pie charts, etc.
Bivariate data is a type of data which consists observations from two variables ( X ,
Y ), i.e., considering two characteristics or attributes at the same time:
(2)
(3)
In the row view, the data can be considered as a set of n points or vectors in the
d-dimensional attribute space:
xi = (x i 1 , x i 2 , . . . , x id ) T
(4)
Covariance matrix:
(5)
IID data mean the all the observations (data points) in the a data sample are
independent and identically (distributed) drawn from variable(s).
Univariate, bivariate, and multivariate data described above are assumed to be IID.
Univariate data: x i (i = 1..n) are i.i.d from variable/attribute X .
Bivariate data: (x i , y i ) (i = 1..n) are i.i.d from two variables/attributes ( X , Y ).
Multivariate data: (x i 1 , x i 2 , . . . , x i d ) (i = 1..n) are i.i.d from d variables/attributes (X 1 ,
X 2 , . . . , X d ).
However, i.i.d is a strong assumption. In reality, data points are not completely
independent. There are some explicit or implicit dependencies among them.
The dependencies among data points can be temporal (time), spatial (e.g., position,
neighbors, etc.), structural (e.g., edges, links, etc.), referential, etc.
Data with dependencies can be called dependency–oriented data or complex and
structured data.
Time–series data
Discrete sequences and strings
Spatial data
Spatiotemporal data
Network and graph data
Other forms of data
For example, consider the case where two sensors at a particular location monitor
the temperature and pressure every second for a minute. This corresponds to a
multidimensional series with d = 2 and n = 60. In some cases, the timestamps t 1, t 2,
. . . , t n may be replaced by index values from 1 through n, especially when the
timestamp values are equally spaced apart.
Time-series data are relatively common in many sensor applications, health, weather
forecasting, and financial market analysis.
For example, consider a sequence of Web accesses, in which the Web page address
and the originating IP address of the request are collected for 100 different accesses.
This represents a discrete sequence of length n = 100 and dimensionality d = 2.
A particularly common case in sequence data is the univariate scenario, in which the
value of d is 1. Such sequence data are also referred to as strings.
In theory, it is possible to have series that are mixed between categorical and
numerical data.
Another important variation is the case where a sequence does not contain
categorical attributes, but a set of any number of unordered categorical values. For
example, supermarket transactions may contain a sequence of sets of items. Each set
may contain any number of items. Such setwise sequences are not really multivariate
sequences, but are univariate sequences.
Thus, discrete sequences can be defined in a wider variety of ways, as compared to
time–series data because of the ability to define sets on discrete elements.
d ata u nderstanding 35 / 106
Discrete sequences and strings (cont’d)
Discrete sequences are often more challenging for mining algorithms because they do
not have the smooth value continuity of time–series data.
In spatial data, many nonspatial attributes (e.g., temperature, pressure, image pixel
color intensity) are measured at spatial locations.
For example, sea-surface temperatures are often collected by meteorologists to
forecast the occurrence of hurricanes. In such cases, the spatial coordinates
correspond to contextual attributes, whereas attributes such as the temperature
correspond to the behavioral attributes.
Typically, there are two spatial attributes. As in the case of time–series data, it is
also possible to have multiple behavioral attributes. For example, in the sea-surface
temperature application, one might also measure other behavioral attributes such as
the pressure.
The aforementioned definition provides broad flexibility in terms of how record X¯i
and location L i may be defined.
For example, the behavioral attributes in record X¯i may be numeric or categorical,
or a mixture of the two. In the meteorological application, X¯i may contain the
temperature and pressure attributes at location L i .
Furthermore, L i may be specified in terms of precise spatial coordinates, such as
latitude and longitude, or in terms of a logical location, such as the city or state.
Spatial data mining is closely related to time–series data mining, in that the
behavioral attributes in most commonly studied spatial applications are continuous,
although some applications may use categorical attributes as well.
Therefore, value continuity is observed across contiguous spatial locations, just as
value continuity is observed across contiguous time stamps in time–series data.
A particular form of spatial data is spatiotemporal data, which contains both spatial
and temporal attributes.
The precise nature of the data also depends on which of the attributes are contextual
and which are behavioral. Two kinds of spatiotemporal data are most common:
Both spatial and temporal attributes are contextual : This kind of data can be viewed as
a direct generalization of both spatial data and temporal data. This kind of data is
particularly useful when the spatial and temporal dynamics of particular behavioral
attributes are measured simultaneously. For example, consider the case where the
variations in the sea-surface temperature need to be measured over time. In such cases,
the temperature is the behavioral attribute, whereas the spatial and temporal
attributes are contextual.
The temporal attribute is contextual, whereas the spatial attributes are behavioral :
Strictly speaking, this kind of data can also be considered time–series data. However,
the spatial nature of the behavioral attributes also provides better interpretability and
more focused analysis in many scenarios. The most common form of this data arises in
the context of trajectory analysis.
In network and graph data, the data values may correspond to nodes in the network,
whereas the relationships among the data values may correspond to the edges in the
network.
In some cases, attributes may be associated with nodes in the network.
Although it is also possible to associate attributes with edges in the network, it is
much less common to do so.
Network data [2]:
A network G = ( N , E ) contains a set of nodes N and a set of edges E , where the edges in E
represent the relationships between the nodes. In some cases, an attribute set X¯i may be
associated with node i, or an attribute set Y¯ij may be associated with edge (i, j ) .
The edge (i, j ) may be directed or undirected. For example, the Web graph may
contain directed edges corresponding to directions of hyper–links between pages,
whereas friendships in Facebook are undirected.
A second class of graph mining problems is that of a database containing many
small graphs such as chemical compounds. The challenges in these two classes of
problems are very different. Some examples of data that are represented as graphs:
Web graph: The nodes correspond to the Web pages, and the edges correspond to
hyperlinks. The nodes have text attributes corresponding to the content in the page.
Social networks: The nodes correspond to social network actors; the edges correspond
to friendship links. The nodes may have attributes corresponding to social page
content. Some specialized forms of social networks are email or chat-messenger
networks, the edges may have content associated with them.
Chemical compound databases: The nodes correspond to the elements and the edges
correspond to the chemical bonds between the elements. The structures in these
chemical compounds are very useful for identifying important reactive and
pharmacological properties of these compounds.
Network data are a very general representation and can be used for solving many
similarity–based applications on other data types;
For example, multidimensional data may be converted to network data by creating a
node for each record in the database, and representing similarities between nodes by
edges. Such a representation is used quite often for many similarity–based data
mining applications, such as clustering.
It is possible to use community detection algorithms to determine clusters in the
network data and then map them back to multidimensional data.
Text data: can be seen as discrete sequences; each element is a word or token.
Natural language data: can be seen as discrete sequences; each element can be
character, token, word, phrase, sentence, paragraph.
Speech data: can be seen as discrete sequences or time–series data.
Image data: can be seen as spatial data.
Video data: can be seen as discrete sequences or time–series data where each
element is a frame.
(6)
Examples:
Messi’s goals for Barcelona from 2004–2005to 2020–2021:
D = {1, 8, 17, 16, 38, 47, 53, 73, 60, 41, 58, 41, 54, 45, 51, 31, 38}
1 + 8 + 17 + ···+ 51 + 31 + 38 672
x̄ = = = 39.53
17 17
Salary (in $k) of 12 employees in a company (shown in increasing order):
D = { 30, 36, 47, 50, 52, 52, 56, 60, 62, 70, 110, 215}
30 + 36 + 47 + ···+ 70 + 110 + 215 840
x̄ = = = 70
12 12
d ata u nderstanding 46 / 106
Weighted mean or weighted average
Sometimes, each value x i in D may be associated with a weight w i (for i = 1..n). The
weights reflect the significance, importance, or occurrence frequency attached to their
respective values. In this case, the weighted mean (weighted average) is:
(7)
Although the mean is the most well–known quantity for describing a data sample, it
is not always the best way of measuring the center of the data.
A major problem with the mean is its sensitivity to extreme values (e.g.,
outliers). Even a small number of extreme values can corrupt the mean.
For example, the mean salary above may be substantially pushed up by that of a
few highly paid managers ($110k, $215k). Similarly, the mean score of a class in an
exam could be pulled down quite a bit by a few very low scores.
To offset the effect caused by a small number of extreme values, we can instead use
the trimmed mean, which is the mean obtained after chopping off values at the
high and low extremes. For example, we can sort the values observed for salary and
remove the top and bottom 2% before computing the mean.
The midrange can also be used to assess the central tendency of a numeric data
set. It is the average of the largest and smallest values in the set.
Examples: salary (in $k) of 12 employees in a company:
D = { 30, 36, 47, 50, 52, 52, 56, 60, 62, 70, 110, 215} . midrange = 30+215
2 = 122.5.
The midrange value is even more affected by outlier values than the mean.
Mean, median, and mode of symmetric versus positively and negatively skewed data [1]
In a unimodal frequency curve with perfect symmetric data distribution, the mean,
median, and mode are all at the same center value (figure a).
Data in most real applications are not symmetric. They may instead be either
positively skewed, where the mode occurs at a value that is smaller than the
median (figure b), or negatively skewed, where the mode occurs at a value greater
than the median (figure c).
d ata u nderstanding 53 / 106
Measuring the dispersion of data
1 Range
2 Quantiles
3 Quartiles
4 Interquartile range
5 Five–number summary
6 Boxplots
7 Outliers
8 Variance and standard deviation
Suppose that the data points/values in the data sample D are sorted in increasing
numeric order.
Imagine that we can pick certain data points so as to split D into equal-size
consecutive sets/parts.
These data points are called quantiles. Quantiles are points taken at regular
intervals of a data sample, dividing it into essentially equal-size consecutive
sets/parts.
The k th q-quantile for a given data sample is the value x such that at most k/q of
the data values are less than x and at most (q −k)/q of the data values are more
than x, where k is an integer such that 0< k < q. There are q −1 q-quantiles.
There are some well-known q-quantiles:
4-quantiles (Quartiles): 3 quartiles split the data into four parts
10-quantiles (Deciles): 9 deciles split the data into 10 parts
100-quantiles (Percentiles): 99 percentiles split the data into 100 parts
10–quantiles (also called deciles) are 9 values (D 1 , D 2 , . . . , D 9 ) dividing the data distribution into 10 equal–size
consecutive parts [source: Internet]
Quartiles divide the distribution into four equal–size consecutive subsets [1]
Quartiles are three values (Q 1 , Q 2 , Q 3 ) dividing the (sample) distribution into four
equal–size consecutive parts.
The first quartile (Q 1 ) corresponds to the 25th percentile.
The second quartile (Q 2 ) corresponds to the 50th percentile, i.e., the median.
The third quartile (Q 3 ) corresponds to the 75th percentile.
d ata u nderstanding 58 / 106
Interquartile range
The distance between the first and third quartiles is a simple measure of spread that
gives the range covered by the middle half of the data. This distance is called the
interquartile range (IQR) and is defined as
I Q R = Q 3 −Q 1 (9)
Example:
Salary (in $k) of 12 employees in a company (shown in increasing order):
D = { 30, 36, 47, 50, 52, 52, 56, 60, 62, 70, 110, 215} .
Q 1 = $47,000 and Q 3 = $62,000.
I Q R = $62,000- $47,000 = $15,000.
d ata u nderstanding 59 / 106
Five–number summary
No single numeric measure of spread (e.g., I Q R ) is very useful for describing skewed
distributions.
In the symmetric distribution, the median (and other measures of central tendency)
splits the data into equal–size halves. This does not occur for skewed distributions.
Therefore, it is more informative to also provide the two quartiles Q 1 and Q 3 , along
with the median.
Because Q 1 , the median, and Q 3 together contain no information about the end–
points (e.g., tails) of the data, a fuller summary of the shape of a distribution can
be obtained by providing the lowest and highest data values as well.
This is known as the five–number summary. The five–number summary of a
distribution consists of the median (Q 2 ), the quartiles Q 1 and Q 3 , and the smallest
and largest individual observations, written in the order of
{ M inimum, Q 1 , M edian, Q 3 , M aximum }
M inimum = 1
Q 1 = 31
Median (Q 2 ) = 41
Q 3 = 53
M aximum = 73
d ata u nderstanding 63 / 106
Boxplot examples (cont’d)
Boxplots are especially useful for showing the central tendency, the data dispersion, the
skewness of data distributions, and the outliers:
The position of the median → the central tendency.
The box length → the data dispersion.
The position of the box relative to the both ends (i.e., M inimum and Maximum)
→ the skewness of the distribution.
The data values too far from Q 1 (i.e., smaller than Q 1 −1.5 × I Q R ) and Q 3 (i.e.,
larger than Q 3 + 1.5 × I Q R ) → outliers.
Variance and standard deviation are measures of data dispersion. They indicate how
spread out a data distribution is.
A low standard deviation means that the data observations tend to be very close to
the mean, while a high standard deviation indicates that the data are spread out
over a large range of values.
Let D = {x 1 , x 2 , . . . , x n } be a sample of n data observations/values from a numeric
variable/attribute X . Let x¯be the mean of D. The variance (σ 2 ) of the
observations in S is
(10)
The standard deviation, σ, of the observations is the square root of the variance.
Salary case: blue line is the sample distribution; yellow line is the inferred (normal) distribution –
[Link](70, 47.71, 200)
Messi case: blue line is the real sample distribution; yellow line is the inferred (normal) distribution –
[Link](39.53, 18.96, 200)
d ata u nderstanding 69 / 106
Relationships in data- Correlation
Correlation is a type of statistical relationship that reflects the strength and direction
of association between two random variables or two data attributes (i.e., bivariate data).
Positive correlation means that both variables change in the same direction.
Negative correlation means that the variables change in opposite directions.
Zero correlation means there is no dependency or relationship between the
variables.
One of the most familiar measure of dependence between two variables is Pearson
correlation. It is a measure of linear correlation between two sets of data. Pearson
correlation works well if the relationship between variables is linear and if the variables
are roughly normal. However, it is not robust for handling outliers, non–linear as well as
skewed distributions. In this case, Spearman’s rank correlation should be used.
(14)
(15)
where:
x¯ and y¯are the sample means of { x 1 , x 2 , . . . , x n } and {y 1 , y 2 , . . . , y n }, respectively.
d ata u nderstanding 73 / 106
Pearson correlation coefficient for a sample (cont’d)
Spearman’s rank correlation is an alternative that mitigates the effect of outliers and
skewed distributions;
To compute Spearman’s correlation, we have to compute the rank of each value,
which is its index in the sorted sample;
For example, in the sample [1, 2, 5, 7] the rank of the value 5 is 3, because it appears
third in the sorted list. Then we compute Pearson’s correlation for the ranks.
(17)
Let ( X i , Y j ) denote the joint event that X takes on value a i and Y takes on value bj ,
or X = a i and Y = bj for short.
The sum in equation (18) is computed over all of the r × c cells of the contingency
table.
Note that the cells that contribute the most to the χ 2 value are those for which the
actual count (n ij ) is very different from the expected frequency (e ij ).
For the Pearson’s chi–square test, the null hypothesis H o is that X and Y are
independent, i.e., there is no correlation between them. The alternative
hypothesis H a is that there is a correlation relationship between X and Y .
The test is based on a significance level, with (r −1) × (c −1) degrees of freedom.
If the null hypothesis can be rejected, then we say that X and Y are statistically
correlated.
A group of 1500 people was surveyed. The gender of each person was noted. Each
person was polled as to whether his or her preferred type of reading material was
fiction or nonfiction.
Thus, we have two attributes, gender and preferred_reading. The observed
frequency (or count) of each possible joint event is summarized in the contingency
table above. In which, the numbers in parentheses are the expected frequencies. For
example: count(f emale) × count(f iction) 1200 × 450
e12 = = = 360
n 1500
d ata u nderstanding 84 / 106
Pearson’s chi–square test example (cont’d)
1 Suppose that the data for analysis includes the attribute age. The age values for the
data tuples are (in increasing order) {13, 15, 16, 16, 19, 20, 20, 21, 22, 22, 25, 25, 25,
25, 30, 33, 33, 35, 35, 35, 35, 36, 40, 45, 46, 52, 70}.
a. What is the mean of the data? What is the median?
b. What is the mode of the data? Comment on the data’s modality (i.e., bimodal,
trimodal, etc.).
c What is the midrange of the data?
d Can you find (roughly) the first quartile (Q 1 ) and the third quartile (Q 3 ) of the data?
e Give the five–number summary of the data.
f Show a boxplot of the data.
g What is the variance and standard deviation of the data?
2 Suppose that a hospital tested the age and body fat data for 18 randomly selected
adults with the following results:
a Calculate the mean, median, variance, and standard deviation of age and %fat.
b Draw the boxplots for age and %fat.
c Draw a scatter plot for these two variables.
d Calculate the Pearson and Spearman correlation coefficients between the two
attributes.
3 LetD (in the previous slide) be the number of appearances, goals, and assists of
Cristiano Ronaldo in Champions League from season 2003/2004 to 2021/2022.
a. Calculate the mean, median, mode, variance, standard deviation of three attributes
appearances, goals, and assists.
b. Find the first quartile (Q 1 ) and the third quartile (Q 3 ) of three three attributes
appearances, goals, and assists.
c. Show the boxplots of the three attributes appearances, goals, and assists.
d. Show the scatter plots of appearances and goals; of appearances and assists; of goals
and assists.
e. Compute the covariance matrix of the three attributes appearances, goals, and assists.
4 800students of three majors (math, history, and computer science) were asked
whether they like playing computer games or not. The survey data are summarized
in the following contingency table:
Like games Do not like games Total
Math 130 100 230
History 35 165 200
Computer science 280 90 370
Total 445 355 800
1 J. Han, M. Kamber, and J. Pei. Data Mining: Concepts and Techniques. Morgan
Kaufmann, Elsevier, 2012 [Book1].
2 C. Aggarwal. Data Mining: The Textbook. Springer, 2015 [Book2].
3 J. Leskovec, A. Rajaraman, and J. D. Ullman. Mining of Massive Datasets.
Cambridge University Press, 2014 [Book3].
4 M. J. Zaki and W. M. Jr. Data Mining and Analysis: Fundamental Concepts and
Algorithms. Cambridge University Press, 2013 [Book4].
5 D. Easley and J. Kleinberg. Networks, Crowds, and Markets: Reasoning About a
Highly Connected World. Cambridge University Press, 2010 [Book5].
6 J. VanderPlas. Python Data Science Handbook: Essential Tools for Working with
Data. O’Reilly, 2017 [Book6].
7 J. Grus. Data Science from Scratch: First Principles with Python. O’Reilly, 2015
[Book7].
Giải thích lý do tại sao việc hiểu dữ liệu lại rất quan trọng trước khi thực hiện bất kỳ
nhiệm vụ phân tích và khai thác dữ liệu nào.
Hiểu biết về các loại thuộc tính dữ liệu khác nhau như phân loại, nhị phân, số,...
Giới thiệu các dạng dữ liệu khác nhau như đơn biến, hai biến, đa biến cũng như
các dữ liệu phức tạp và có cấu trúc hơn như chuỗi thời gian, trình tự, dữ liệu
không gian, mạng/đồ thị và dữ liệu luồng..
Hiểu và biết cách đo lường xu hướng trung tâm cũng như sự biến thiên của dữ
liệu; biết một số công cụ thống kê và trực quan hóa như biểu đồ hộp để hiểu phân
bố mẫu.
Nghiên cứu các mối quan hệ tiềm năng giữa các biến/thuộc tính dữ liệu thông qua
các khái niệm quan trọng như hiệp phương sai, tương quan, hệ số tương quan
Pearson, Spearman, kiểm định chi bình phương Pearson, cũng như giải thích sự
khác biệt giữa tương quan và nhân quả.