Objective of the Project
The primary objective of this project is to explore transactional data using Association Rule Mining. This data mining technique identifies relationships between items within transactions. Specifically, the goal is to:
Identify frequently purchased item combinations (frequent itemsets).
Extract association rules that reveal dependencies between products, such as: “If a customer buys Product A, they are likely to also purchase Product B.”
Applications of Association Rules
Association rules are widely used in business analytics, particularly in Market Basket Analysis. Common applications include:
Optimizing product placement in stores.
Creating bundled offers and product recommendations.
Analyzing customer behavior to tailor personalized promotions.
By uncovering patterns in transactional data, association rule mining provides actionable insights that help businesses improve sales strategies and enhance customer experience.
Dataset Description
The dataset used in this project is sourced from the https://archive.ics.uci.edu/dataset/352/online+retail, containing real-world e-commerce transaction data from a UK-based company operating between 2010 and 2011.Key attributes in the dataset include:
InvoiceNo: A unique identifier for each transaction (invoice).
StockCode: A unique code for each product.
Description: The product description.
Quantity: The number of units of the product purchased in a given transaction.
InvoiceDate: The date and time of the transaction.
UnitPrice: The price per unit of the product.
CustomerID: A unique identifier for each customer.
Country: The country where the customer is based.
The dataset is rich with information but requires preprocessing to convert it into the basket format, where each transaction consists of a list of products purchased together.
library(dplyr)
library(tidyr)
library(readxl)
library(readr)
library(arules)
library(arulesViz)
data <- read_excel("Online Retail.xlsx")
head(data)
## # A tibble: 6 × 8
## InvoiceNo StockCode Description Quantity InvoiceDate UnitPrice
## <chr> <chr> <chr> <dbl> <dttm> <dbl>
## 1 536365 85123A WHITE HANGING HEAR… 6 2010-12-01 08:26:00 2.55
## 2 536365 71053 WHITE METAL LANTERN 6 2010-12-01 08:26:00 3.39
## 3 536365 84406B CREAM CUPID HEARTS… 8 2010-12-01 08:26:00 2.75
## 4 536365 84029G KNITTED UNION FLAG… 6 2010-12-01 08:26:00 3.39
## 5 536365 84029E RED WOOLLY HOTTIE … 6 2010-12-01 08:26:00 3.39
## 6 536365 22752 SET 7 BABUSHKA NES… 2 2010-12-01 08:26:00 7.65
## # ℹ 2 more variables: CustomerID <dbl>, Country <chr>
The goal of the data preparation step is to clean and transform the raw dataset into a format suitable for Association Rule Mining. This involves:
Filtering irrelevant or noisy data.
Grouping transactions to create a basket format.
Preparing the data for analysis by converting it into a transaction object.
transformed_data <- data %>%
group_by(InvoiceNo) %>%
summarise(Product = paste(na.omit(Description), collapse = ", ")) %>%
mutate(TransactionID = row_number()) %>%
select(TransactionID, Product)
print(transformed_data)
## # A tibble: 25,900 × 2
## TransactionID Product
## <int> <chr>
## 1 1 WHITE HANGING HEART T-LIGHT HOLDER, WHITE METAL LANTERN, CREAM…
## 2 2 HAND WARMER UNION JACK, HAND WARMER RED POLKA DOT
## 3 3 ASSORTED COLOUR BIRD ORNAMENT, POPPY'S PLAYHOUSE BEDROOM, POPP…
## 4 4 JAM MAKING SET WITH JARS, RED COAT RACK PARIS FASHION, YELLOW …
## 5 5 BATH BUILDING BLOCK WORD
## 6 6 ALARM CLOCK BAKELIKE PINK, ALARM CLOCK BAKELIKE RED, ALARM CLO…
## 7 7 PAPER CHAIN KIT 50'S CHRISTMAS
## 8 8 HAND WARMER RED POLKA DOT, HAND WARMER UNION JACK
## 9 9 WHITE HANGING HEART T-LIGHT HOLDER, WHITE METAL LANTERN, CREAM…
## 10 10 VICTORIAN SEWING BOX LARGE
## # ℹ 25,890 more rows
# Export the transformed data to a text file in basket format
write.table(
transformed_data$Product,
file = "transactions.txt",
row.names = FALSE,
col.names = FALSE,
quote = FALSE
)
After completing this step, the prepared dataset consists of:
TransactionID: Sequential IDs for transactions.
Product: A list of items purchased in each transaction.
This transformation ensures the data is ready for Market Basket Analysis and rule generation in the next step.
The cleaned and transformed data, saved in basket format (transactions.txt), is imported using the arules library. This library supports transactional data and is optimized for Association Rule Mining.
# Read the prepared data in basket format
transactions <- read.transactions("transactions.txt", format = "basket", sep = ",")
# Display a summary of the transactions
summary(transactions)
## transactions as itemMatrix in sparse format with
## 25900 rows (elements/itemsets/transactions) and
## 8978 columns (items) and a density of 0.001815558
##
## most frequent items:
## WHITE HANGING HEART T-LIGHT HOLDER REGENCY CAKESTAND 3 TIER
## 1969 1883
## JUMBO BAG RED RETROSPOT PARTY BUNTING
## 1736 1464
## LUNCH BAG RED RETROSPOT (Other)
## 1382 413738
##
## element (itemset/transaction) length distribution:
## sizes
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
## 1454 4598 1741 1214 952 895 785 718 700 683 615 644 547 529 547 561
## 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
## 536 480 457 494 433 406 329 316 286 249 262 235 224 231 221 171
## 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
## 172 146 148 140 118 120 101 116 100 95 97 94 72 72 73 69
## 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
## 69 64 54 67 46 52 55 52 39 33 44 37 31 34 20 26
## 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
## 27 23 31 26 27 19 22 21 15 17 23 11 16 14 12 10
## 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
## 18 18 15 8 9 15 14 16 11 8 8 12 12 8 7 7
## 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
## 4 8 9 4 8 6 4 5 6 2 3 7 9 4 8 4
## 112 113 114 116 117 118 119 120 121 122 123 124 125 126 127 128
## 2 7 1 4 6 5 1 3 6 4 3 2 5 5 2 1
## 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
## 1 4 3 5 5 2 4 3 1 1 1 3 7 5 3 3
## 145 146 147 148 150 151 152 153 154 155 156 157 158 159 160 162
## 4 7 2 3 3 3 2 4 7 3 3 5 1 4 5 1
## 163 164 167 168 169 170 171 172 173 174 175 176 177 178 179 180
## 2 2 3 4 2 2 3 2 1 3 5 1 1 4 3 2
## 181 182 183 184 185 186 187 189 192 193 194 196 197 198 201 202
## 1 1 1 2 1 1 2 2 1 4 1 3 3 1 1 1
## 204 205 206 207 208 209 212 213 215 217 219 220 224 226 227 228
## 2 1 1 2 3 2 1 1 2 1 3 1 3 3 1 1
## 230 232 234 236 238 240 241 248 249 250 252 256 257 258 260 261
## 2 1 1 1 2 1 2 1 1 2 1 1 1 1 2 1
## 263 265 266 270 272 274 281 284 285 291 298 301 303 305 312 314
## 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1
## 320 321 326 327 329 332 338 339 344 348 350 360 365 367 375 391
## 2 1 1 1 1 1 1 1 2 1 1 2 1 1 3 1
## 394 398 400 402 411 419 429 431 442 447 460 468 471 477 509 514
## 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1
## 530 587 640
## 1 1 1
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0 2.0 8.0 16.3 20.0 640.0
##
## includes extended item information - examples:
## labels
## 1 *Boombox Ipod Classic
## 2 *USB Office Mirror Ball
## 3 ?
As we can see, there is 25900 transactions and 8978 different products. The most frequently purchased items are WHITE HANGING HEART T-LIGHT HOLDER,REGENCY CAKESTAND 3 TIER and JUMBO BAG RED RETROSPOT.
To identify the most commonly purchased products, I calculated item frequencies and visualized them in both relative and absolute terms.
Why Visualize Relative and Absolute Frequencies?
Relative Frequency: Highlights the proportion of transactions containing a specific product.
Absolute Frequency: Shows the total number of transactions involving each product.
Together, they provide a comprehensive view of product popularity.
# Plot the relative frequency of the top 10 items
itemFrequencyPlot(
transactions,
type = "relative",
topN = 10,
col = "dodgerblue",
main = "Top 10 Items by Relative Frequency",
ylab = "Relative Frequency",
cex.names = 0.8 # Reduce label size for readability
)
# Plot the absolute frequency of the top 10 items
itemFrequencyPlot(
transactions,
type = "absolute",
topN = 10,
col = "darkgreen",
main = "Top 10 Items by Absolute Frequency",
ylab = "Absolute Frequency",
cex.names = 0.8 # Reduce label size for readability
)
# Inspect the first 10 transactions
inspect(transactions[1:10])
## items
## [1] {CREAM CUPID HEARTS COAT HANGER,
## GLASS STAR FROSTED T-LIGHT HOLDER,
## KNITTED UNION FLAG HOT WATER BOTTLE,
## RED WOOLLY HOTTIE WHITE HEART.,
## SET 7 BABUSHKA NESTING BOXES,
## WHITE HANGING HEART T-LIGHT HOLDER,
## WHITE METAL LANTERN}
## [2] {HAND WARMER RED POLKA DOT,
## HAND WARMER UNION JACK}
## [3] {ASSORTED COLOUR BIRD ORNAMENT,
## BOX OF 6 ASSORTED COLOUR TEASPOONS,
## BOX OF VINTAGE ALPHABET BLOCKS,
## BOX OF VINTAGE JIGSAW BLOCKS,
## DOORMAT NEW ENGLAND,
## FELTCRAFT PRINCESS CHARLOTTE DOLL,
## HOME BUILDING BLOCK WORD,
## IVORY KNITTED MUG COSY,
## LOVE BUILDING BLOCK WORD,
## POPPYS PLAYHOUSE BEDROOM, POPPYS PLAYHOUSE KITCHEN,
## RECIPE BOX WITH METAL HEART}
## [4] {BLUE COAT RACK PARIS FASHION,
## JAM MAKING SET WITH JARS,
## RED COAT RACK PARIS FASHION,
## YELLOW COAT RACK PARIS FASHION}
## [5] {BATH BUILDING BLOCK WORD}
## [6] {ALARM CLOCK BAKELIKE GREEN,
## ALARM CLOCK BAKELIKE PINK,
## ALARM CLOCK BAKELIKE RED,
## CHARLOTTE BAG DOLLY GIRL DESIGN,
## CIRCUS PARADE LUNCH BOX,
## INFLATABLE POLITICAL GLOBE,
## LUNCH BOX I LOVE LONDON,
## MINI JIGSAW CIRCUS PARADE,
## MINI JIGSAW SPACEBOY,
## MINI PAINT SET VINTAGE,
## PANDA AND BUNNIES STICKER SHEET,
## POSTAGE,
## RED TOADSTOOL LED NIGHT LIGHT,
## ROUND SNACK BOXES SET OF4 WOODLAND,
## SET 2 TEA TOWELS I LOVE LONDON,
## SET/2 RED RETROSPOT TEA TOWELS,
## SPACEBOY LUNCH BOX,
## STARS GIFT TAPE,
## VINTAGE HEADS AND TAILS CARD GAME,
## VINTAGE SEASIDE JIGSAW PUZZLES}
## [7] {PAPER CHAIN KIT 50S CHRISTMAS}
## [8] {HAND WARMER RED POLKA DOT,
## HAND WARMER UNION JACK}
## [9] {CREAM CUPID HEARTS COAT HANGER,
## EDWARDIAN PARASOL RED,
## GLASS STAR FROSTED T-LIGHT HOLDER,
## KNITTED UNION FLAG HOT WATER BOTTLE,
## RED WOOLLY HOTTIE WHITE HEART.,
## RETRO COFFEE MUGS ASSORTED,
## SAVE THE PLANET MUG,
## SET 7 BABUSHKA NESTING BOXES,
## VINTAGE BILLBOARD DRINK ME MUG,
## VINTAGE BILLBOARD LOVE/HATE MUG,
## WHITE HANGING HEART T-LIGHT HOLDER,
## WHITE METAL LANTERN,
## WOOD 2 DRAWER CABINET WHITE FINISH,
## WOOD S/3 CABINET ANT WHITE FINISH,
## WOODEN FRAME ANTIQUE WHITE,
## WOODEN PICTURE FRAME WHITE FINISH}
## [10] {VICTORIAN SEWING BOX LARGE}
The purpose of this step is to discover patterns and relationships within the transactional dataset by generating association rules. This involves:
Mining frequent itemsets using the Apriori algorithm.
Generating rules based on minimum thresholds for support, confidence, and lift.
Filtering and interpreting the rules to identify actionable insights.
Mining Association Rules
The Apriori algorithm is used to discover frequent itemsets and generate association rules. To optimize the results:
Support: Measures how often an itemset appears in transactions.
Confidence: Indicates how often a consequent item is purchased given the antecedent item(s).
Lift: Measures the strength of the association, controlling for the popularity of items.
# Generate rules using the Apriori algorithm
rules <- apriori(
transactions,
parameter = list(supp = 0.005, conf = 0.4, maxlen = 3)
)
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.4 0.1 1 none FALSE TRUE 5 0.005 1
## maxlen target ext
## 3 rules TRUE
##
## Algorithmic control:
## filter tree heap memopt load sort verbose
## 0.1 TRUE TRUE FALSE TRUE 2 TRUE
##
## Absolute minimum support count: 129
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[8978 item(s), 25900 transaction(s)] done [0.12s].
## sorting and recoding items ... [986 item(s)] done [0.01s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 done [0.02s].
## writing ... [1256 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
# Display a summary of the rules
inspect(rules[1:100])
## lhs rhs support confidence coverage lift count
## [1] {COFFEE MUG PEARS DESIGN} => {COFFEE MUG APPLES DESIGN} 0.005405405 0.7526882 0.007181467 82.60434 140
## [2] {COFFEE MUG APPLES DESIGN} => {COFFEE MUG PEARS DESIGN} 0.005405405 0.5932203 0.009111969 82.60434 140
## [3] {SET/10 BLUE POLKADOT PARTY CANDLES} => {SET/10 PINK POLKADOT PARTY CANDLES} 0.006447876 0.7767442 0.008301158 66.17656 167
## [4] {SET/10 PINK POLKADOT PARTY CANDLES} => {SET/10 BLUE POLKADOT PARTY CANDLES} 0.006447876 0.5493421 0.011737452 66.17656 167
## [5] {ELEPHANT} => {BIRTHDAY CARD} 0.005444015 1.0000000 0.005444015 80.68536 141
## [6] {BIRTHDAY CARD} => {ELEPHANT} 0.005444015 0.4392523 0.012393822 80.68536 141
## [7] {QUEENS GUARD COFFEE MUG} => {LONDON BUS COFFEE MUG} 0.005057915 0.5622318 0.008996139 52.38058 131
## [8] {LONDON BUS COFFEE MUG} => {QUEENS GUARD COFFEE MUG} 0.005057915 0.4712230 0.010733591 52.38058 131
## [9] {COFFEE MUG DOG + BALL DESIGN} => {COFFEE MUG CAT + BIRD DESIGN} 0.005173745 0.7928994 0.006525097 93.34588 134
## [10] {COFFEE MUG CAT + BIRD DESIGN} => {COFFEE MUG DOG + BALL DESIGN} 0.005173745 0.6090909 0.008494208 93.34588 134
## [11] {CHILDRENS CUTLERY DOLLY GIRL} => {CHILDRENS CUTLERY SPACEBOY} 0.007027027 0.7459016 0.009420849 65.71038 182
## [12] {CHILDRENS CUTLERY SPACEBOY} => {CHILDRENS CUTLERY DOLLY GIRL} 0.007027027 0.6190476 0.011351351 65.71038 182
## [13] {MONSTERS STENCIL CRAFT} => {HAPPY STENCIL CRAFT} 0.005135135 0.7964072 0.006447876 90.46906 133
## [14] {HAPPY STENCIL CRAFT} => {MONSTERS STENCIL CRAFT} 0.005135135 0.5833333 0.008803089 90.46906 133
## [15] {CHILDRENS CUTLERY POLKADOT BLUE} => {CHILDRENS CUTLERY RETROSPOT RED} 0.005019305 0.5439331 0.009227799 55.24653 130
## [16] {CHILDRENS CUTLERY RETROSPOT RED} => {CHILDRENS CUTLERY POLKADOT BLUE} 0.005019305 0.5098039 0.009845560 55.24653 130
## [17] {CHILDRENS CUTLERY POLKADOT BLUE} => {CHILDRENS CUTLERY POLKADOT PINK} 0.006718147 0.7280335 0.009227799 56.45529 174
## [18] {CHILDRENS CUTLERY POLKADOT PINK} => {CHILDRENS CUTLERY POLKADOT BLUE} 0.006718147 0.5209581 0.012895753 56.45529 174
## [19] {FRONT DOOR} => {KEY FOB} 0.006254826 1.0000000 0.006254826 61.52019 162
## [20] {WATERING CAN PINK BUNNY} => {WATERING CAN BLUE ELEPHANT} 0.005675676 0.6150628 0.009227799 56.29020 147
## [21] {WATERING CAN BLUE ELEPHANT} => {WATERING CAN PINK BUNNY} 0.005675676 0.5194346 0.010926641 56.29020 147
## [22] {WOOD S/3 CABINET ANT WHITE FINISH} => {WOOD 2 DRAWER CABINET WHITE FINISH} 0.006293436 0.4244792 0.014826255 21.68444 163
## [23] {IVORY DINER WALL CLOCK} => {BLUE DINER WALL CLOCK} 0.005945946 0.4106667 0.014478764 32.03695 154
## [24] {BLUE DINER WALL CLOCK} => {IVORY DINER WALL CLOCK} 0.005945946 0.4638554 0.012818533 32.03695 154
## [25] {IVORY DINER WALL CLOCK} => {RED DINER WALL CLOCK} 0.006833977 0.4720000 0.014478764 29.60000 177
## [26] {RED DINER WALL CLOCK} => {IVORY DINER WALL CLOCK} 0.006833977 0.4285714 0.015945946 29.60000 177
## [27] {FELTCRAFT CUSHION BUTTERFLY} => {FELTCRAFT CUSHION RABBIT} 0.007297297 0.6472603 0.011274131 50.64665 189
## [28] {FELTCRAFT CUSHION RABBIT} => {FELTCRAFT CUSHION BUTTERFLY} 0.007297297 0.5709970 0.012779923 50.64665 189
## [29] {FELTCRAFT CUSHION BUTTERFLY} => {FELTCRAFT CUSHION OWL} 0.006100386 0.5410959 0.011274131 35.75098 158
## [30] {FELTCRAFT CUSHION OWL} => {FELTCRAFT CUSHION BUTTERFLY} 0.006100386 0.4030612 0.015135135 35.75098 158
## [31] {HERB MARKER CHIVES} => {HERB MARKER BASIL} 0.005907336 0.8595506 0.006872587 109.12921 153
## [32] {HERB MARKER BASIL} => {HERB MARKER CHIVES} 0.005907336 0.7500000 0.007876448 109.12921 153
## [33] {HERB MARKER CHIVES} => {HERB MARKER PARSLEY} 0.006254826 0.9101124 0.006872587 119.05005 162
## [34] {HERB MARKER PARSLEY} => {HERB MARKER CHIVES} 0.006254826 0.8181818 0.007644788 119.05005 162
## [35] {HERB MARKER CHIVES} => {HERB MARKER THYME} 0.006177606 0.8988764 0.006872587 116.40449 160
## [36] {HERB MARKER THYME} => {HERB MARKER CHIVES} 0.006177606 0.8000000 0.007722008 116.40449 160
## [37] {HERB MARKER CHIVES} => {HERB MARKER MINT} 0.006216216 0.9044944 0.006872587 112.62694 161
## [38] {HERB MARKER MINT} => {HERB MARKER CHIVES} 0.006216216 0.7740385 0.008030888 112.62694 161
## [39] {HERB MARKER CHIVES} => {HERB MARKER ROSEMARY} 0.006216216 0.9044944 0.006872587 114.83532 161
## [40] {HERB MARKER ROSEMARY} => {HERB MARKER CHIVES} 0.006216216 0.7892157 0.007876448 114.83532 161
## [41] {SET OF 3 WOODEN TREE DECORATIONS} => {SET OF 3 WOODEN STOCKING DECORATION} 0.005637066 0.7300000 0.007722008 85.94091 146
## [42] {SET OF 3 WOODEN STOCKING DECORATION} => {SET OF 3 WOODEN TREE DECORATIONS} 0.005637066 0.6636364 0.008494208 85.94091 146
## [43] {SET OF 3 WOODEN TREE DECORATIONS} => {SET OF 3 WOODEN HEART DECORATIONS} 0.005482625 0.7100000 0.007722008 57.10870 142
## [44] {SET OF 3 WOODEN HEART DECORATIONS} => {SET OF 3 WOODEN TREE DECORATIONS} 0.005482625 0.4409938 0.012432432 57.10870 142
## [45] {EDWARDIAN PARASOL RED} => {EDWARDIAN PARASOL BLACK} 0.005212355 0.4963235 0.010501931 38.03189 135
## [46] {EDWARDIAN PARASOL RED} => {EDWARDIAN PARASOL NATURAL} 0.005135135 0.4889706 0.010501931 27.06055 133
## [47] {HOT PINK} => {FEATHER PEN} 0.005907336 1.0000000 0.005907336 101.96850 153
## [48] {FEATHER PEN} => {HOT PINK} 0.005907336 0.6023622 0.009806950 101.96850 153
## [49] {SET OF 3 WOODEN SLEIGH DECORATIONS} => {SET OF 3 WOODEN STOCKING DECORATION} 0.005096525 0.6534653 0.007799228 76.93069 132
## [50] {SET OF 3 WOODEN STOCKING DECORATION} => {SET OF 3 WOODEN SLEIGH DECORATIONS} 0.005096525 0.6000000 0.008494208 76.93069 132
## [51] {BLUE DINER WALL CLOCK} => {RED DINER WALL CLOCK} 0.006833977 0.5331325 0.012818533 33.43373 177
## [52] {RED DINER WALL CLOCK} => {BLUE DINER WALL CLOCK} 0.006833977 0.4285714 0.015945946 33.43373 177
## [53] {PINK HAPPY BIRTHDAY BUNTING} => {BLUE HAPPY BIRTHDAY BUNTING} 0.009111969 0.6781609 0.013436293 51.20807 236
## [54] {BLUE HAPPY BIRTHDAY BUNTING} => {PINK HAPPY BIRTHDAY BUNTING} 0.009111969 0.6880466 0.013243243 51.20807 236
## [55] {SET/6 COLLAGE PAPER CUPS} => {SET/6 COLLAGE PAPER PLATES} 0.005250965 0.8831169 0.005945946 123.63636 136
## [56] {SET/6 COLLAGE PAPER PLATES} => {SET/6 COLLAGE PAPER CUPS} 0.005250965 0.7351351 0.007142857 123.63636 136
## [57] {SET OF 3 WOODEN STOCKING DECORATION} => {SET OF 3 WOODEN HEART DECORATIONS} 0.005637066 0.6636364 0.008494208 53.37945 146
## [58] {SET OF 3 WOODEN HEART DECORATIONS} => {SET OF 3 WOODEN STOCKING DECORATION} 0.005637066 0.4534161 0.012432432 53.37945 146
## [59] {VINTAGE CREAM CAT FOOD CONTAINER} => {VINTAGE CREAM DOG FOOD CONTAINER} 0.006177606 0.5904059 0.010463320 45.64631 160
## [60] {VINTAGE CREAM DOG FOOD CONTAINER} => {VINTAGE CREAM CAT FOOD CONTAINER} 0.006177606 0.4776119 0.012934363 45.64631 160
## [61] {SET OF 6 TEA TIME BAKING CASES} => {SET OF 6 SNACK LOAF BAKING CASES} 0.006216216 0.5570934 0.011158301 51.90187 161
## [62] {SET OF 6 SNACK LOAF BAKING CASES} => {SET OF 6 TEA TIME BAKING CASES} 0.006216216 0.5791367 0.010733591 51.90187 161
## [63] {SET OF 6 TEA TIME BAKING CASES} => {SET OF 12 MINI LOAF BAKING CASES} 0.006602317 0.5916955 0.011158301 45.33998 171
## [64] {SET OF 12 MINI LOAF BAKING CASES} => {SET OF 6 TEA TIME BAKING CASES} 0.006602317 0.5059172 0.013050193 45.33998 171
## [65] {SET OF 6 TEA TIME BAKING CASES} => {SET OF 12 FAIRY CAKE BAKING CASES} 0.007335907 0.6574394 0.011158301 39.69157 190
## [66] {SET OF 12 FAIRY CAKE BAKING CASES} => {SET OF 6 TEA TIME BAKING CASES} 0.007335907 0.4428904 0.016563707 39.69157 190
## [67] {HERB MARKER BASIL} => {HERB MARKER PARSLEY} 0.006833977 0.8676471 0.007876448 113.49525 177
## [68] {HERB MARKER PARSLEY} => {HERB MARKER BASIL} 0.006833977 0.8939394 0.007644788 113.49525 177
## [69] {HERB MARKER BASIL} => {HERB MARKER THYME} 0.006795367 0.8627451 0.007876448 111.72549 176
## [70] {HERB MARKER THYME} => {HERB MARKER BASIL} 0.006795367 0.8800000 0.007722008 111.72549 176
## [71] {HERB MARKER BASIL} => {HERB MARKER MINT} 0.006911197 0.8774510 0.007876448 109.25952 179
## [72] {HERB MARKER MINT} => {HERB MARKER BASIL} 0.006911197 0.8605769 0.008030888 109.25952 179
## [73] {HERB MARKER BASIL} => {HERB MARKER ROSEMARY} 0.006988417 0.8872549 0.007876448 112.64658 181
## [74] {HERB MARKER ROSEMARY} => {HERB MARKER BASIL} 0.006988417 0.8872549 0.007876448 112.64658 181
## [75] {HAND WARMER RED LOVE HEART} => {HAND WARMER UNION JACK} 0.005366795 0.4680135 0.011467181 31.56653 139
## [76] {HAND WARMER RED LOVE HEART} => {HAND WARMER SCOTTY DOG DESIGN} 0.005328185 0.4646465 0.011467181 29.56841 138
## [77] {HAND WARMER RED LOVE HEART} => {HAND WARMER OWL DESIGN} 0.005945946 0.5185185 0.011467181 26.96713 154
## [78] {LOVE HOT WATER BOTTLE} => {HOT WATER BOTTLE KEEP CALM} 0.006525097 0.4720670 0.013822394 20.27618 169
## [79] {PAINTED METAL PEARS ASSORTED} => {ASSORTED COLOUR BIRD ORNAMENT} 0.008996139 0.6934524 0.012972973 13.82634 233
## [80] {HAND WARMER RED RETROSPOT} => {HAND WARMER SCOTTY DOG DESIGN} 0.005675676 0.4949495 0.011467181 31.49679 147
## [81] {HAND WARMER RED RETROSPOT} => {HAND WARMER OWL DESIGN} 0.005830116 0.5084175 0.011467181 26.44179 151
## [82] {CHILDRENS CUTLERY RETROSPOT RED} => {CHILDRENS CUTLERY POLKADOT PINK} 0.005907336 0.6000000 0.009845560 46.52695 153
## [83] {CHILDRENS CUTLERY POLKADOT PINK} => {CHILDRENS CUTLERY RETROSPOT RED} 0.005907336 0.4580838 0.012895753 46.52695 153
## [84] {HERB MARKER PARSLEY} => {HERB MARKER THYME} 0.006911197 0.9040404 0.007644788 117.07323 179
## [85] {HERB MARKER THYME} => {HERB MARKER PARSLEY} 0.006911197 0.8950000 0.007722008 117.07323 179
## [86] {HERB MARKER PARSLEY} => {HERB MARKER MINT} 0.007027027 0.9191919 0.007644788 114.45707 182
## [87] {HERB MARKER MINT} => {HERB MARKER PARSLEY} 0.007027027 0.8750000 0.008030888 114.45707 182
## [88] {HERB MARKER PARSLEY} => {HERB MARKER ROSEMARY} 0.006949807 0.9090909 0.007644788 115.41889 180
## [89] {HERB MARKER ROSEMARY} => {HERB MARKER PARSLEY} 0.006949807 0.8823529 0.007876448 115.41889 180
## [90] {HERB MARKER THYME} => {HERB MARKER MINT} 0.006872587 0.8900000 0.007722008 110.82212 178
## [91] {HERB MARKER MINT} => {HERB MARKER THYME} 0.006872587 0.8557692 0.008030888 110.82212 178
## [92] {HERB MARKER THYME} => {HERB MARKER ROSEMARY} 0.007181467 0.9300000 0.007722008 118.07353 186
## [93] {HERB MARKER ROSEMARY} => {HERB MARKER THYME} 0.007181467 0.9117647 0.007876448 118.07353 186
## [94] {FELTCRAFT PRINCESS OLIVIA DOLL} => {FELTCRAFT PRINCESS LOLA DOLL} 0.005791506 0.6493506 0.008918919 50.20353 150
## [95] {FELTCRAFT PRINCESS LOLA DOLL} => {FELTCRAFT PRINCESS OLIVIA DOLL} 0.005791506 0.4477612 0.012934363 50.20353 150
## [96] {FELTCRAFT PRINCESS OLIVIA DOLL} => {FELTCRAFT PRINCESS CHARLOTTE DOLL} 0.005482625 0.6147186 0.008918919 44.59723 142
## [97] {REGENCY SUGAR BOWL GREEN} => {REGENCY MILK JUG PINK} 0.008262548 0.7353952 0.011235521 65.22855 214
## [98] {REGENCY MILK JUG PINK} => {REGENCY SUGAR BOWL GREEN} 0.008262548 0.7328767 0.011274131 65.22855 214
## [99] {REGENCY SUGAR BOWL GREEN} => {REGENCY TEAPOT ROSES} 0.007683398 0.6838488 0.011235521 49.61256 199
## [100] {REGENCY TEAPOT ROSES} => {REGENCY SUGAR BOWL GREEN} 0.007683398 0.5574230 0.013783784 49.61256 199
Explanation of Parameters:
supp = 0.005: At least 0.5% of transactions must contain the itemset.
conf = 0.4: At least 40% confidence is required for the rule.
maxlen = 3: Limits the rule length to a maximum of 3 items for simplicity.
Visualization helps to better understand and communicate the discovered association rules. By representing the rules graphically, we can:
Highlight key patterns and dependencies.
Present the rules in an intuitive manner for business stakeholders.
Explore relationships between items in a more interactive and engaging way.
# Scatter plot of rules
library(arulesViz)
plot(
rules,
method = "scatterplot",
measure = c("support", "confidence"),
shading = "lift",
main = "Scatter Plot of Association Rules"
)
# Graph visualization of rules
if (length(rules) > 0) {
plot(
rules,
method = "graph",
measure = "support",
shading = "lift",
engine = "html"
)
}
General Insights from Rules:
Rules with high confidence and lift > 1 are actionable and can guide promotions or bundling strategies.
Rules with lift < 1 (negative association) indicate that items are less likely to be purchased together and might not be suitable for joint promotions.
Example Rule Interpretation
Rule: {Item A} => {Item B}
Support = 0.014 This means 1.4% of all transactions include both Item A and Item B together.
Confidence = 0.127 If Item A is purchased, there is a 12.7% likelihood that Item B is also purchased in the same transaction.
Lift = 0.804 The lift value of 0.804 indicates a negative association. This means Item A and Item B are purchased together less frequently than expected if they were independent of each other. In other words, customers do not strongly associate these two items when making purchases.
The association rule mining process has uncovered valuable insights into the purchasing behavior of customers. The analysis highlights strong associations between products that can guide inventory management, marketing strategies, and sales promotions. Future work could focus on refining support and confidence thresholds to uncover more granular insights.
Limitations
While the analysis provided valuable insights, there are some limitations to consider:
Data Quality:
Single-Timeframe Analysis:
Threshold Sensitivity: