Analyzing Variable Relationships in Data
Analyzing Variable Relationships in Data
UNDERSTANDING RELATIONSHIPS
INTRODUCTION:
A critical step in understanding any dataset is examining the relationships between variables. For instance,
we may want to know whether interest rates are related to inflation, or whether education level is
associated with income. It is important to recognize that the presence of an association does not
necessarily mean that one variable causes the other. These relationships can be explored through summary
tables, data visualizations, and statistical calculations that indicate the strength and reliability of the
association. The following sections describe several methods for examining relationships between pairs of
variables, including visual techniques, summary tables, and calculated metrics. The choice of method
depends on how the variables are categorized and the scale on which they are measured. Data
visualizations play a particularly important role, as they leverage the human visual system’s ability to
detect complex patterns and trends within graphical representations of data.
The nature of the relationship between two variables whether it is linear or nonlinear is also an
important aspect to consider. A linear relationship occurs when changes in the second variable are
proportional to changes in the first, resulting in a straight-line pattern. In contrast, a nonlinear
relationship appears as a curve, indicating that the change in the second variable is not proportional
as the first variable changes. In Figure 4.2, the relationship between sepal length(cm) and petal
length(cm) is primarily linear, with petal length increasing proportionally as sepal length increases.
A scatterplot can also reveal observations that do not follow this pattern, such as the point marked X
in Figure 4.3. These unusual points are known as outliers, as they fall outside the general trend of
the data.
FIGURE 4.3: Observation (marked as X) that does not follow the relationship
Scatterplots can also reveal negative relationships between variables.
EX: In Figure 4.4, we can see that when weight increases, the MPG value goes down, showing a
negative relationship. Sometimes, relationships between variables are not straightforward and may
include both upward and downward trends. In this example, the points form a curved pattern, meaning
the relationship is nonlinear MPG decreases as weight increases, but it does not decrease at a steady or
proportional rate.
In a summary table, a single categorical variable or a continuous variable that has been converted into
categories is used to group the observations, with each row representing one group. These tables
typically display the count or percentage of observations belonging to each category. Additional columns
may be included to summarize a second variable, but because each row represents a group rather than an
individual observation, the values in these columns must also be summary statistics. Common
descriptive statistics used in such tables include the mean, median, mode, sum, minimum, maximum,
variance, and standard deviation, all of which provide meaningful summaries of the grouped data.
FIGURE 4.6: Example of a summary table
In Figure 4.6, the relationship between the variables class and petal width (cm) from Fisher (1936) is
illustrated. The class variable is a nominal categorical variable with three possible values“Iris-
setosa,” “Iris-versicolor,” and “Iris-virginica” which appear in the first column of the table. Each
class contains 50 observations, and each row summarizes the petal width measurements for its
corresponding group of 50 flowers. The table presents summary statistics for petal width, including
the minimum, maximum, mean, median, and standard deviation. From these summaries, it is clear
that “Iris-setosa” has the smallest petal width, with a mean of 0.2 cm. “Iris-versicolor” has a higher
mean petal width of 1.33 cm, while “Iris-virginica” shows the greatest petal width, with a mean of
2.03 cm.
It can also be useful to present this information graphically. For example, in Figure 4.7, a bar chart
is used where the x-axis displays the three nominal class categories and the y-axis shows the mean
petal width (cm) for each class. This visualization makes it easy to compare the relative mean values
across the three classes at a glance.
Summary tables can also be used to explore the relationship between ordinal variables and another
variable. In the example shown in Figure 4.9, the observations are grouped into three ordered categories.
Because these categories have a natural order, it becomes possible to observe how the mean weight
changes across the MPG categories. From the table, it is evident that as the MPG category increases, the
mean weight consistently decreases, clearly illustrating the relationship between these two variables.
In many cases, a binary variable is used to represent data that has only two possible outcomes,
typically coded as 0 and 1. For example, 0 may indicate that a patient has a particular infection,
while 1 indicates that the patient does not. To illustrate, consider a new blood test being evaluated
for its ability to predict whether a patient has a specific type of infection. The test
produces values ranging from −5.0 to +1.0, with higher values suggesting the presence of the
infection and lower values suggesting its absence. Figure 4.11 summarizes these results by patient
class: 23 patients do not have the infection (infection = 0), and 32 patients do have it (infection = 1).
The mean blood test value for infected patients is 3.05, while the mean value for non-infected
patients is −4.13. Although there is a noticeable difference between the two groups, the overlap in
the test results makes interpretation challenging, since some patients' values fall within similar
ranges regardless of infection status.
FIGURE 4.11: Summary table and corresponding box plot chart to summarizing the results of a trial
for a new blood test to predict an infection.
Another way to analyze this data is to use the blood test results as the grouping variable and then
compute descriptive statistics for the binary infection variable. Because the blood test values are
continuous, the first step is to divide them into intervals. In this example, the range boundaries were
set at −5, −4, −3, −2, −1, 0, +1, and +2, and the groups were formed as shown in Figure 4.12. For
each group, the mean value of the binary variable infection is calculated and displayed in the
summary table, and also plotted in a histogram. Since the infection variable is coded as 0 and 1, the
mean for each group must lie between 0 and 1: a mean of 0 indicates that all patients in the group
tested negative, while a mean of 1 indicates that all tested positive. This representation makes the
relationship between the two variables clearer. For lower blood test values (from −5 to −2), there are
very few infection cases, meaning the test correctly predicts most of these as negative. Likewise, for
blood test values from −1 to +2, most cases are positive, and the test correctly identifies them as
such. However, in the range −2 to −1, the mean infection value is 0.55, meaning 55% are predicted
positive and 45% negative. In this range, the test performs poorly, and it would be reasonable to
conclude that blood test results within this interval should not be trusted.
FIGURE 4.12: Summary table and histogram using continuous data that has been binned to
generate the group summarized using the binary variable.
3. Cross-Classification Tables: Cross-classification tables, also known as contingency tables, are
useful for examining the relationship between two categorical variables—or continuous variables
that have been converted into categories. While one of the variables is often dichotomous,
contingency tables can accommodate variables with more than two categories.
Figure 4.13 presents an example of such a table for the variables Test Results and Infection Class
across a group of patients. Infection Class identifies whether a patient has the infection and consists
of two values: “Infection negative” and “Infection positive.” Test Results indicates whether the
blood test outcome was “Blood test negative” or “Blood test positive.” The dataset contains 55
observations, shown in the bottom-right cell of the table. The rightmost column labelled “Totals”
shows the total number of patients in each Test Results category 27 with negative blood test results
and 28 with positive results. The bottom row labeled “Totals” shows the total number of patients in
each Infection Class 23 infection-negative and 32 infection-positive. The inner cells of the table
present the counts of patients for each pair of categories: 17 patients had both a negative blood test
and no infection, 10 had a negative blood test but were infected, 6 had a positive blood test but no
infection, and 22 had both a positive blood test and an infection. This table provides a clear view of
the relationship between the two variables. Although the new blood test does not perfectly identify
infection status, it correctly classified 39 patients (22 + 17) and incorrectly classified 16 patients (10
+ 6).
FIGURE 4.13 Contingency table showing the relationship between two dichotomous variables.
Contingency tables are also useful for examining relationships between categorical variables
whether nominal or ordinal when the variables contain more than two possible values. In Figure
4.14, the dataset is summarized using two such variables: gender and age-group. The gender
variable is dichotomous, with the two categories “female” and “male” shown across the top of
the table on the x-axis. The age-group variable has been divided into nine ordered categories
such as 10–19, 20–29, 30–39, and so on. For each category of each variable, the table displays a
total count. For instance, there are 21,790 observations classified as “male,” and 1,657
observations where the age of the individual falls between 10 and 19 years. The overall number
of observations represented in the table is provided in the bottom-right corner, which in this case
is 32,561.
FIGURE 4.14 Contingency table illustrating the number of females and males in each age-
group.
4.1 CALCULATING METRICS ABOUT RELATIONSHIPS
There are several ways to measure the strength of the relationship between two variables, and the
appropriate metric depends largely on the types of variables involved for example, whether the
comparison is between two categorical variables, two continuous variables, or a mix of both.
Different types of data require different methods to capture how strongly the variables are associated.
The following section outlines commonly used techniques for quantifying the strength of these
relationships and explains how they apply to various types of variables.
1. Correlation Coefficients: For pairs of variables measured on an interval or ratio scale, the
correlation coefficient (r) is commonly used to quantify the strength of their linear relationship.
This coefficient ranges from −1.0 to +1.0 and indicates how closely the data points align with an
optimal straight line drawn through a scatterplot. A positive value of r signifies a positive
correlation between the two variables, while a negative value indicates a negative correlation.
When r is close to 0, it suggests that there is little to no linear relationship between the variables.
For example, the two scatterplots shown in Figure 4.15 illustrate different values for r. The
first graph illustrates a strong positive correlation because the points lie relatively close to an
imaginary line sloping upward from left to right through the center of the points; the second
graph illustrates a weaker correlation.
Figure 4.15 Scatterplots illustrate values for the correlation coefficient (r). The
formula used to calculate r is shown here:
where x and y are variables, xi are the individual values of x, yi are the individual values
of y, is the mean of the x variable, is the mean of the y variable, sx and sy are the
standard deviations of the variables x and y, respectively, and n is the number of observations.
To illustrate the calculation, two variables (x and y) are used and shown
in Table 4.1. The scatterplot of the two variables indicates a positive correlation between them,
as shown in Figure 4.16 The specific value of r is calculated using Table 4.2.
Table 4.1: Table of Data with Values for the x and y Variables
x y
92 6.3
145 7.8
30 3.0
70 5.5
75 6.5
105 5.5
110 6.5
108 8.0
45 4.0
x y
50 5.0
160 7.5
155 9.0
180 8.6
190 10.0
63 4.2
85 4.9
130 6
132 7
xi yi
Sum = 1,357.06
106.94
6.41
sx = sy = 1.86
47.28
FIGURE 4.16: Scatterplot to illustrate the relationship between the x and y variables.
2. Kendall Tau:
Kendall Tau is another method for measuring the association between two variables and is based on
comparing the rankings of observations rather than their actual numerical values. To compute this
measure, the observations for each variable are ordered, and their values are replaced with ranks
from 1 to n, where n represents the total number of observations. The Kendall Tau statistic is then
calculated using the number of concordant and discordant pairs of observations that either maintain
the same order or differ in order across the two variables. Table 4.3 demonstrates this approach
using two variables, Variable X and Variable Y, each containing ranked values for a set of 10
observations labeled A through J.
A 1 2
B 2 4
C 3 1
D 4 3
E 5 6
F 6 5
G 7 7
H 8 8
I 9 10
J 10 9
A pair of observations is concordant if the two variables change in the same direction, i.e., the
observation with the higher value of Variable X also has the higher value of Variable Y (or
both are lower together); mathematically, the differences (X₂ − X₁) and (Y₂ − Y₁) have the
same sign (both positive or both negative). For example, for points A(1,2) and B(2,4), the
differences are (2−1)=+1 and (4−2)=+2 (both positive), so A and B are concordant; reversing
the order gives (−1) and (−2), still the same sign, yielding the same result. Conversely, a pair
is discordant if the variables move in opposite directions, meaning the differences have
opposite signs. For instance, for points B(2,4) and C(3,1), the differences are (3−2)=+1 and
(1−4)=−3 (one positive, one negative), so B and C are discordant. Thus, concordance occurs
when the relative ordering of the two variables agrees, while discordance occurs when the
orderings disagree.
In Table 4.4, the observations (A through J) are first arranged in increasing order of Variable
X. To count concordant and discordant pairs systematically without double-counting or
missing any pair, each observation is compared only with the observations that follow it in
this ordered list. For example, observation A (the smallest X) is paired with each of the
remaining nine observations (B through J); among these, eight pairs (A–B, A–D, A–E, A–F,
A–G, A–H, A–I, A–J) are concordant and one pair (A–C) is discordant. Observation B is then
compared only with C through J, observation C with D through J, and so on, until the last
observation J has no further pairs. The concordant and discordant counts for each observation
are recorded in the last two columns of the table, and finally, all individual concordant counts
are summed to give the total number of concordant pairs (C) and all discordant counts are
summed to give the total number of discordant pairs (D) across the entire data set, ensuring
every unique pair of observations is considered exactly once.
A 1 2 8 1
B 2 4 6 2
C 3 1 7 0
D 4 3 6 0
E 5 6 4 1
F 6 5 4 0
G 7 7 2 1
H 8 8 2 0
I 9 10 0 1
J 10 9 0 0
Sum: 39 6
A final Kendall Tau measure is computed based on these computed sums (the total number of
concordant and discordant pairs obtained from the table). Kendall Tau measures associations
between variables with 1 indicating a perfect ranking (complete agreement between the two
variables' orderings) and −1 a perfect disagreement of the rankings (completely reversed
orderings). A zero value assigned when the ranks are tied indicates a lack of association, or
in other words, that the two variables are independent. The simplest form of the Kendall Tau
calculation is referred to as Tau A and has the formula:
where nc and nd are the number of concordant and discordant pairs, respectively, and
n is the number of observations. In this example, the Tau A (τA) would be:
In most practical situations, there are ties based on either variable. In these situations, the
formula Tau B is often used. It considers the ties in the first variable (tx) and the ties in
the second variable (ty) and is computed using the following formulas:
In most software applications the Kendall Tau B function is used.
t-Tests Comparing Two Groups: In the context of describing data, we previously used a
one-sample t-test to determine whether the observed mean of a variable differs significantly
from a specific hypothesized value, allowing us to conclude that such a difference is unlikely
to be due to normal sampling variation or chance alone. This same principle of statistical
significance testing can now be extended when we want to compare the means of two distinct
groups or subsets within our data. Instead of comparing one mean to a fixed number, we
examine whether the difference between the means of the two groups is large enough to be
considered meaningful, or whether it could reasonably occur just by chance.
Although the basic idea remains the same as the earlier single-sample case, the comparison of
two groups requires a different approach and formula. The two-sample t-test not only
considers the size of the difference between the two group means but also takes into account
the amount of variation (spread or deviation) within each group. The test assumes that the
observations in the two groups are independent, approximately normally distributed, and that
the population variances are equal or very similar. By combining information about both the
mean difference and the within-group variability, the formula enables us to assess whether
the two groups truly differ in their underlying population means or whether the observed
difference is likely due to random variation alone.
where is the mean value of the first group, is the mean value of the second
group, and n1 and n2 are the number of observations in the first and second group
respectively, and sp is an estimate of the standard deviation (pooled estimate). The sp is
calculated using the following formula:
where n1 and n2 are again the number of observations in group 1 and group 2 respectively,
and s2 , s2 are the calculated variances for group 1 and group 2. This formula follows a t-
distribution, with the number of degrees of freedom (df) calculated as
where it cannot be assumed that the variances across the two groups are equal, another
formula is used:
where are the average values for the two groups (1 and 2), s2 and s21 are 2
the calculated variances for the two groups, and n1 and n2 are the number of
observations in the two groups.
Again, it follows a t-distribution and the number of degrees of freedom (df) is calculated
using the following formula:
The calculated t-value will be positive when the mean of Group 1 (x̄ ₁) is larger than the mean
of Group 2 (x̄ ₂), and negative when the mean of Group 2 is larger than the mean of Group 1.
Just as we did earlier when describing data, this t-value is used in a formal hypothesis test:
Null hypothesis (H₀): The population means of the two groups are equal (μ₁ = μ₂).
Alternative hypothesis (H₁): The population means of the two groups are not equal
(μ₁ ≠ μ₂) a two-tailed test.
The decision to accept or reject the null hypothesis follows the same process as before:
compare the absolute value of the computed t with the critical t-value from the t-distribution
table (using the calculated degrees of freedom), or compute a p-value. A small p-value
(typically < 0.05) or a |t| larger than the critical value leads to rejection of H₀, meaning the
difference between the two group means is statistically significant. The entire procedure
obtaining the t-statistic, determining significance, and interpreting the p-value is carried out
in exactly the same way as we learned earlier for the one-sample case.
3. ANOVA: One-way analysis of variance (ANOVA) is a statistical method used to compare
the means of three or more independent groups at the same time. It tests whether there is
evidence that at least one group has a different population mean. The completely
randomized one-way ANOVA is suitable when the groups are independent, the data in each
group are approximately normally distributed, and the population variances are equal.
Example: An online computer retailer has four call centers of similar size, and we want to
determine if the average number of daily calls processed differs significantly among them
(i.e., whether some centers are performing better or worse than others). The daily call data are
shown in Table 4.5. One-way ANOVA will be applied to these data to test the null hypothesis
that all four call centers have the same mean daily calls against the alternative that at least
one center differs.
139 146
As with other hypothesis tests, it is necessary to state a null and alternative hypothesis.
Generally, the hypothesis statement will take the standard form:
H0: The means are equal.
Ha: The means are not equal.
To determine whether a difference exists between the means or whether the difference is
due to random variation, we must perform a hypothesis test. This test will look at both
the variation within the groups and the variation between the groups. The test performs
the following steps:
4. Determine the F-statistic, which is based on the between-group and within group
ratio.
5. Test the significance of the F-statistic.
In Table 4.6., for each call center a count along with the mean and variance has been
calculated. In addition, the total number of groups (k = 4) and the total number of
observations (N = 29) is listed. An average of all values (=140.8) is calculated by
summing all values and dividing it by the number of observations:
139 146
In this example
Determine the between-group variation
Next, the between-group variation or mean square between (MSB) is calculated. The
MSB is the variance between the group means. It is calculated using a weighted
sum of the squared difference between the group mean ( )and the average of all
where ni is the number for each group and is the average for each group. In
this example,
In this example:
where N is the total number of observations in all groups and k is the number of groups.
The degrees of freedom for the MSB (dfbetween) is calculated using the following formula:
In this example,
We have already computed the F-statistic as 53.39. This value shows that the average
variation between the four call-center groups is much larger than the average variation within
the groups that is due to random error. To determine whether this difference is statistically
significant, we compare the calculated F-statistic with the critical F-value obtained from the
F-table (refer to the Further Readings section for the table). The critical value is found using
the significance level α (here α = 0.05), the degrees of freedom between groups (v₁ or
df_between), and the degrees of freedom within groups (v₂ or df_within). For these data, the
critical F-value at α = 0.05 is 3.01. Because the calculated F-statistic of 53.39 is greater than
the critical value of 3.01, we reject the null hypothesis and conclude that the means of the
different call centers are not all equal.
6. Chi- Square:
The chi-square test for indepedence is a hypothesis test for use with variables measured on a
nominal or ordinal scale. It allows an analysis of whether there is a relationship between two
categorical variables. As with other hypothesis tests, it is necessary to state a null and
alternative hypothesis. Generally, these hypothesis statements are as follows:
H0: There is no relationship.
Ha: There is a relationship.
Using Table 4.7 we will look at whether a relationship exists between where a consumer
lives (represented by a zip code) and the brand of washing powder they buy (brand X,
brand Y, and brand Z). The ``r'' and ``c'' refer to the row (r) and column (c) in a
contingency table.
Sum = 191.2
The Chi-Square test compares the observed frequencies with the expected frequencies.
The expected frequencies are calculated using the following formula:
where Er,c is the expected frequency for a particular cell in a contingency table, r is the row
count, c is the column count and n is the total number of observations in the sample.
For example, to calculate the expected frequency for the table cell where the washing powder is
brand X and the zip code is 43221 would be
where k is the number of all categories, Oi is the observed cell frequency and Ei is the
expected cell frequency. The test is usually performed when all observed cell frequencies are
greater than [Link] 4.7 shows the computed χ2 for this example
There is a critical value at which the null hypothesis is rejected (χ 2 ) and this value is
c
found using a standard Chi-Square table (see Further Reading Section). The value is
dependent on the degrees of freedom (df ), which is calculated:
For example, the number of degrees of freedom for the above example is (3 − 1) × (3 − 1)
which equals 4. Looking up the critical value for df = 4 and α = 0.05, the critical value is
9.488. Since 9.488 is less than the calculated chi-square value of 191.2, we reject the null
hypothesis and state that there is a relationship between zip codes and brands of washing
powder.
TABLE 4.8 shows a series of retail transactions monitored by the main office of a computer
store.
Additionally, grouping helps highlight observations that do not fit well into any major cluster
these outliers stand out from the main patterns and should be carefully examined, as they may
represent data errors, rare events, or genuinely unusual but important cases.
Identifying meaningful groups within a dataset is not only a frequent and valuable outcome of
data analysis projects, but also plays an important supporting role in other data-mining tasks,
particularly in building predictive models (as discussed in Chapter 6). The process of
discovering and interpreting these groups gives the analyst a deeper understanding of the
data’s structure, which directly improves the quality of subsequent modeling efforts.
Moreover, clustering often reveals specific subsets of the data where relationships are clearer
and stronger than in the full dataset. Building separate, tailored models for these
homogeneous subgroups can result in simpler, more accurate, and more interpretable
predictions than a single model applied to the entire dataset. For example, when predicting
house prices, houses in certain neighborhoods or locations may show a much stronger and
simpler relationship with variables like size or age; creating dedicated models for each such
subgroup typically yields better forecasting performance than one overall model.
Clustering:
Clustering is an unsupervised machine learning technique that groups similar data points
together into clusters based on their characteristics, without using any labeled data. The
objective is to ensure that data points within the same cluster are more similar to each other
than to those in different clusters, enabling the discovery of natural groupings and hidden
patterns in complex datasets.
Goal: Discover the natural grouping or structure in unlabeled data without
predefined categories.
How: Data points are assigned to clusters based on similarity or distance measures.
Similarity Measures: Can include Euclidean distance, cosine similarity or other
metrics depending on data type and clustering method.
Output: Each group is assigned a cluster ID, representing shared characteristics within
the cluster.
For example, if we have customer purchase data, clustering can group customers with
similar shopping habits. These clusters can then be used for targeted marketing,
personalized recommendations or customer segmentation.
Types of Clustering
Let's see the types of clustering,
1. Hard Clustering: In hard clustering, each data point strictly belongs to exactly one
cluster, no overlap is allowed. This approach assigns a clear membership, making it easier
to interpret and use for definitive segmentation tasks.
Example: If clustering customer data into 2 segments, each customer belongs fully to
either Cluster 1 or Cluster 2 without partial memberships.
Use cases: Market segmentation, customer grouping, document clustering.
Limitations: Cannot represent ambiguity or overlap between groups; boundaries are
crisp.
Let's see an example to see the difference between the hard and soft clustering using a
distribution,
2. Soft Clustering: Soft clustering assigns each data point a probability or degree of
membership to multiple clusters simultaneously, allowing data points to partially belong to
several groups.
Example: A data point may have a 70% membership in Cluster 1 and 30% in Cluster 2,
reflecting uncertainty or overlap in group characteristics.
Use cases: Situations with overlapping class boundaries, fuzzy categories like customer
personas or medical diagnosis.
Benefits: Captures ambiguity in data, models gradual transitions between clusters.
Types of Clustering Methods
Clustering methods can be classified on the basis of how they form clusters,
1. Centroid-based Clustering (Partitioning Methods)
Centroid-based clustering organizes data points around central prototypes called centroids,
where each cluster is represented by the mean (or medoid) of its members. The number of
clusters is specified in advance and the algorithm allocates points to the nearest centroid,
making this technique efficient for spherical and similarly sized clusters but sensitive to
outliers and initialization.
Algorithms:
K-means: Iteratively assigns points to nearest centroid and recalculates centroids to
minimize intra-cluster variance.
K-medoids: Similar to K-means but uses actual data points (medoids) as centers, robust
to outliers.
Pros:
Fast and scalable for large datasets.
Simple to implement and interpret.
Cons:
Requires pre-knowledge of kk.
Sensitive to initialization and outliers.
Not suitable for non-spherical clusters.
2. Density-based Clustering (Model-based Methods)
Density-based clustering defines clusters as contiguous regions of high data density
separated by areas of lower density. This approach can identify clusters of arbitrary shapes,
handles noise well and does not require predefining the number of clusters, though its
effectiveness depends on chosen density parameters.
Algorithms:
DBSCAN (Density-Based Spatial Clustering of Applications with Noise): Groups
points with sufficient neighbors; labels sparse points as noise.
OPTICS (Ordering Points To Identify Clustering Structure): Extends DBSCAN to
handle varying densities.
Pros:
Handles clusters of varying shapes and sizes.
Does not require cluster count upfront.
Effective in noisy datasets.
Cons:
Difficult to choose parameters like epsilon and min points.
Less effective for varying density clusters (except OPTICS).
3. Connectivity-based Clustering (Hierarchical Clustering)
Connectivity-based (or hierarchical) clustering builds nested groupings of data by
evaluating how data points are connected to their neighbors. It creates a dendrogram a tree-
like structure that reflects relationships at various granularity levels and does not require
specifying cluster numbers in advance, but can be computationally intensive.
Approaches:
Agglomerative (Bottom-up): Start with each point as a cluster; iteratively merge closest
clusters.
Divisive (Top-down): Start with one cluster; iteratively split into smaller clusters.
Pros:
Provides a full hierarchy, easy to visualize.
No need to specify number of clusters upfront.
Cons:
Computationally intensive for large datasets.
Merging/splitting decisions are irreversible.
4. Distribution-based Clustering
Distribution-based clustering assumes data is generated from a mixture of probability
distributions, such as Gaussian distributions and assigns points to clusters based on
statistical likelihood. This method supports clusters with flexible shapes and overlaps, but
usually requires specifying the number of distributions.
Algorithm:
Gaussian Mixture Model (GMM): Fits data as a weighted mixture of Gaussian
distributions; assigns data points based on likelihood.
Pros:
Flexible cluster shapes.
Provides probabilistic memberships.
Suitable for overlapping clusters.
Cons:
Requires specifying number of components.
Computationally more expensive.
Sensitive to initialization.
5. Fuzzy Clustering
Fuzzy clustering extends traditional methods by allowing each data point to belong to
multiple clusters with varying degrees of membership. This approach captures ambiguity
and soft boundaries in data and is particularly useful when the clusters overlap or
boundaries are not clear-cut.
Algorithm:
Fuzzy C-Means: Similar to K-means but with fuzzy memberships updated iteratively.
Pros:
Models data ambiguity explicitly.
Useful for complex or imprecise data.
Cons:
Choosing fuzziness parameter can be tricky.
Computational overhead compared to hard clustering.
Use Cases
Customer Segmentation: Grouping customers based on behavior or demographics for
targeted marketing and personalized services.
Anomaly Detection: Identifying outliers or fraudulent activities in finance, network
security and sensor data.
Image Segmentation: Dividing images into meaningful parts for object detection,
medical diagnostics or computer vision tasks.
Recommendation Systems: Clustering user preferences to recommend movies,
products or content tailored to different groups.
Market Basket Analysis: Discovering products frequently bought together to
optimize store layouts and promotions.
K-means:
K-Means Clustering groups similar data points into clusters without needing labeled
data. It is used to uncover hidden patterns when the goal is to organize data based on
similarity.
Helps identify natural groupings in unlabeled datasets
Works by grouping points based on distance to cluster centers
Commonly used in customer segmentation, image compression, and pattern
discovery
Useful when you need structure from raw, unorganized data
Working of K-Means Clustering
Suppose we are given a data set of items with certain features and values for these
features like a vector. The task is to categorize those items into groups. To achieve this
we will use the K-means algorithm. "k" represents the number of groups or clusters we
want to classify our items into.
The algorithm will categorize the items into "kk" groups or clusters of similarity. To
calculate that similarity we will use the Euclidean distance as a measurement. The
algorithm works as follows:
1. Initialization: We begin by randomly selecting k cluster centroids.
2. Assignment Step: Each data point is assigned to the nearest centroid, forming
clusters.
3. Update Step: After the assignment, we recalculate the centroid of each cluster by
averaging the points within it.
4. Repeat: This process repeats until the centroids no longer change or the maximum
number of iterations is reached.
The goal is to partition the dataset into k clusters such that data points within each
cluster are more similar to each other than to those in other clusters.
Association Rule
Association rules are a fundamental concept used to find relationships, correlations or
patterns within large sets of data items. They describe how often itemsets occur together in
transactions and express implications of the form:
X→YX→Y
Where XX and YY are disjoint sets of items. This rule suggests that when items in XX appear,
items in YY tend to appear as well. Association rules originated from market basket analysis
and help retailers and analysts understand customer behavior by discovering item
associations in transaction data. For example, a rule stating
{Bread,Butter}→{Milk}
indicates that customers who buy bread and butter also tend to buy milk.
Key Components
Antecedent (X): The "if" part representing one or more items found in transactions.
Consequent (Y): The "then" part, representing the items likely to be purchased when
antecedent items appear.
Rules are evaluated based on metrics that quantify their strength and usefulness:
Lift > 1 implies a positive association — items occur together more than expected.
Lift = 1 implies independence.
Lift < 1 implies a negative association.
Apriori Algorithm:
Apriori Algorithm is a basic method used in data analysis to find groups of items that often
appear together in large sets of data. It helps to discover useful patterns or rules about how
items are related which is particularly valuable in market basket analysis.