Cross Shop Analysis
Cross-Shopping Analysis Module for Category and Brand Interaction Insights.
Business Context
Cross-shopping analysis reveals how customers navigate between different product categories, brands, or store locations. This intelligence drives critical retail decisions from store layout and category adjacencies to promotional bundling and targeted marketing campaigns.
Real-World Problem
Retailers often make incorrect assumptions about customer behavior. They might place baby products far from beer, not realizing these categories have high cross-shopping rates (the famous "diapers and beer" phenomenon). Cross-shop analysis replaces assumptions with data-driven insights about actual customer purchase patterns.
Business Applications
- Store Layout Optimization
- Place frequently cross-shopped categories near each other
- Create logical customer journey paths through the store
-
Reduce friction in the shopping experience
-
Promotional Strategy
- Bundle products from highly cross-shopped categories
- Time promotions to capture cross-category purchases
-
Design "buy from A, get discount on B" offers
-
Category Management
- Understand category interdependencies
- Identify opportunity categories for existing shoppers
-
Spot categories at risk when others decline
-
Multi-Channel Strategy
- Analyze cross-shopping between online and physical stores
- Optimize channel-specific assortments
-
Design omnichannel customer journeys
-
Competitive Analysis
- Understand customer loyalty across competing brands
- Identify vulnerable competitor segments
- Design conquest strategies for shared customers
Business Value
- Increased Basket Size: Strategic placement increases impulse purchases
- Customer Retention: Better store experience reduces defection
- Marketing Efficiency: Target promotions to actual behavior patterns
- Strategic Insights: Understand true category relationships
- Competitive Advantage: Leverage unique customer behavior insights
Visualization Output
The module generates Venn diagrams showing: - Exclusive shoppers for each category/brand - Overlap segments with cross-shopping behavior - Relative size of each segment by customer count or spend - Percentage breakdowns for strategic planning
CrossShop
Analyzes customer cross-shopping behavior between categories, brands, or locations.
The CrossShop class reveals hidden relationships in customer purchasing patterns, enabling retailers to optimize everything from store layouts to marketing campaigns. By understanding which products customers buy together across shopping trips, retailers can make smarter decisions about product placement, promotions, and assortment.
Business Problem Solved
Many retail decisions assume customer behavior that may not reflect reality. For example: - Are organic shoppers also buying conventional products? - Do online grocery shoppers still visit physical stores? - Which private label categories attract national brand buyers?
This analysis provides definitive answers with actionable percentages.
Source code in pyretailscience/analysis/cross_shop.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
__init__(df, group_1_col, group_1_val, group_2_val, group_2_col=None, group_3_col=None, group_3_val=None, labels=None, group_col=None, value_col=None, agg_func='sum')
Initialize cross-shopping analysis between retail categories, brands, or locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
DataFrame | Table
|
Transaction data with customer purchases. |
required |
group_1_col |
str
|
Column identifying first segment (e.g., "category", "brand", "channel"). |
required |
group_1_val |
str
|
Value to analyze for first segment (e.g., "organic", "Brand_A", "online"). |
required |
group_2_val |
str
|
Value to analyze for second segment. |
required |
group_2_col |
str
|
Column identifying second segment. Defaults to group_1_col. |
None
|
group_3_col |
str
|
Column for three-way analysis. Defaults to group_1_col when group_3_val provided. |
None
|
group_3_val |
str
|
Value for third segment. Defaults to None. |
None
|
labels |
list[str]
|
Custom labels for diagram (e.g., ["Organic", "Local"]). Defaults to alphabetical labels [A, B, C]. |
None
|
group_col |
str
|
Grouping column (e.g., customer_id, store_id, segment_name). Defaults to customer_id from options. |
None
|
value_col |
str
|
Metric to analyze (sales, units, visits). Defaults to spend column from options. |
None
|
agg_func |
str
|
How to combine customer values ("sum", "mean", "count"). Defaults to "sum" for total opportunity sizing. |
'sum'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required columns missing or label count doesn't match groups. |
Business Examples
Analyze organic vs conventional shoppers
cross_shop = CrossShop( ... df=transactions, ... group_1_col="product_type", ... group_1_val="organic", ... group_2_val="conventional", ... labels=["Organic", "Conventional"] ... ) ...
Three-way analysis
cross_shop = CrossShop( ... df=transactions, ... group_1_col="channel", ... group_1_val="online", ... group_2_val="store", ... group_3_val="mobile", ... labels=["Online", "Store", "Mobile"] ... ) ...
Custom customer column
cross_shop = CrossShop( ... df=transactions, ... group_1_col="brand", ... group_1_val="Nike", ... group_2_val="Adidas", ... group_col="user_id" ... )
Source code in pyretailscience/analysis/cross_shop.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
plot(title=None, source_text=None, vary_size=False, figsize=None, ax=None, subset_label_formatter=None, **kwargs)
Generate Venn diagram showing customer segment overlaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title |
str
|
Chart title (e.g., "Cross-Shopping: Organic vs Conventional"). |
None
|
source_text |
str
|
Data source attribution. Defaults to None. |
None
|
vary_size |
bool
|
Scale circles by segment value for visual impact. True = larger segments appear bigger. Defaults to False. |
False
|
figsize |
tuple[int, int]
|
Plot dimensions. Defaults to None. |
None
|
ax |
Axes
|
Existing axes for subplot integration. Defaults to None. |
None
|
subset_label_formatter |
callable
|
Custom formatting for percentages. Default shows one decimal place (e.g., "34.5%"). |
None
|
**kwargs |
dict[str, any]
|
Additional diagram customization options. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
SubplotBase |
SubplotBase
|
Matplotlib axes containing the cross-shop visualization. |