Skip to content

Commit c65b6d7

Browse files
committed
feat: added production association rule module
1 parent 4db1168 commit c65b6d7

File tree

6 files changed

+1375
-0
lines changed

6 files changed

+1375
-0
lines changed

docs/analysis_modules.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,60 @@ time_plot(
9292
move_legend_outside=True,
9393
)
9494
```
95+
96+
## Analysis Modules
97+
98+
### Product Association Rules
99+
100+
The product association module implements functionality for generating product association rules, a powerful technique
101+
in retail analytics and market basket analysis.
102+
103+
Product association rules are used to uncover relationships between different products that customers tend to purchase
104+
together. These rules provide valuable insights into consumer behavior and purchasing patterns, which can be leveraged
105+
by retail businesses in various ways:
106+
107+
1. Cross-selling and upselling: By identifying products frequently bought together, retailers can make targeted product
108+
recommendations to increase sales and average order value.
109+
110+
2. Store layout optimization: Understanding product associations helps in strategic product placement within stores,
111+
potentially increasing impulse purchases and overall sales.
112+
113+
3. Inventory management: Knowing which products are often bought together aids in maintaining appropriate stock levels
114+
and predicting demand.
115+
116+
4. Marketing and promotions: Association rules can guide the creation ofeffective bundle offers and promotional
117+
campaigns.
118+
119+
5. Customer segmentation: Patterns in product associations can reveal distinct customer segments with specific
120+
preferences.
121+
122+
6. New product development: Insights from association rules can inform decisions about new product lines or features.
123+
124+
The module uses metrics such as support, confidence, and uplift to quantifythe strength and significance of product
125+
associations:
126+
127+
- Support: The frequency of items appearing together in transactions.
128+
- Confidence: The likelihood of buying one product given the purchase of another.
129+
- Uplift: The increase in purchase probability of one product when another is bought.
130+
131+
Example:
132+
133+
```python
134+
from pyretailscience.product_association import ProductAssociation
135+
136+
pa = ProductAssociation(
137+
df,
138+
value_col="product_name",
139+
group_col="transaction_id",
140+
)
141+
pa.df.head()
142+
```
143+
<!-- markdownlint-disable MD013 -->
144+
| product_name_1 | product_name_2 | occurrences_1 | occurrences_2 | cooccurrences | support | confidence | uplift |
145+
|:-----------------|:-----------------------------|---------------:|---------------:|---------------:|---------:|-----------:|-------:|
146+
| 100 Animals Book | 100% Organic Cold-Pressed... | 78 | 78 | 1 | 0.000039 | 0.0128205 | 4.18 |
147+
| 100 Animals Book | 20K Sousaphone | 78 | 81 | 3 | 0.000117 | 0.0384615 | 12.10 |
148+
| 100 Animals Book | 360 Sport 2.0 Boxer Briefs | 78 | 79 | 1 | 0.000039 | 0.0128205 | 4.13 |
149+
| 100 Animals Book | 4-Series 4K UHD | 78 | 82 | 1 | 0.000039 | 0.0128205 | 3.98 |
150+
| 100 Animals Book | 700S Eterna Trumpet | 78 | 71 | 1 | 0.000039 | 0.0128205 | 4.60 |
151+
<!-- markdownlint-enable MD013 -->

docs/api/product_association.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Product Associations
2+
3+
::: pyretailscience.product_association

0 commit comments

Comments
 (0)