# Basket Analysis

### About **Model**

In many retail and e-commerce environments, customers rarely purchase a single item. Instead, they buy groups of items that naturally belong together. Understanding these hidden relationships is invaluable for improving store layout, driving cross-sell and upsell strategies, designing bundles, and planning promotions.

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2FR6fEWdVVftYeGuhEruKX%2Fimage.png?alt=media&#x26;token=762086ae-73c3-42e0-ac4f-2b77b5898b5a" alt=""><figcaption></figcaption></figure>

Basket Analysis uncovers these meaningful combinations. It identifies which items frequently appear together in the same transaction and highlights strong associations among them. The model returns three key insights:

* **Frequent Items:** Which products appear most often.
* **Pair Rules:** Which two items tend to be purchased together.
* **Triplet Rules:** Which three-item combinations frequently co-occur.

Basket Analysis is powered by association-rule mining and uses standard industry metrics—**support**, **confidence**, and **lift**—to measure the strength of product relationships.

The goal is simple:\
Help companies understand what customers naturally buy together so they can take immediate action to increase revenue, improve merchandising, and optimize stock decisions.

***

### **Required Columns**

To run a Basket Analysis, your dataset must include three required fields:

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2FoaZ55bIpNklO0PrDbNYf%2Fimage.png?alt=media&#x26;token=c6d99f32-a797-4e74-9f78-cc8739a17d0e" alt=""><figcaption></figcaption></figure>

#### **1. Order ID**

A unique identifier representing each customer transaction or basket.\
Examples: invoice number, bill number, transaction ID.

#### **2. Items**

The name or identifier of the purchased product in each row.\
Every row represents *one item inside a specific transaction*.

#### **3. Item Quantities**

The number of units sold for that item within the transaction.

Graphite Note automatically handles multiple units, duplicates inside the same order, and cleans the dataset before analysis.

***

### **Advanced Settings**

Basket Analysis includes configurable thresholds that balance model performance, speed, and insight quality. These parameters allow users to control how rare or frequent an itemset must be to be considered relevant.

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2FhkpUmwOHNKjyOyDyVyiS%2Fimage.png?alt=media&#x26;token=9568ed32-ca5c-4e3c-9932-cf515c1e3b0b" alt=""><figcaption></figcaption></figure>

#### **Step 1: Ignore Very Rare Items**

This parameter filters out items that appear in only a tiny fraction of transactions.

* **Why it matters:**\
  Very rare items introduce noise and lead to extremely large rule sets with little business value.
* **Allowed range:** 0.000001 – 0.05
* **Example:** A value of 0.00005 (0.005%) means any item appearing in less than 0.005% of transactions will be excluded.

Higher thresholds produce faster, cleaner results.

***

#### **Step 2: Minimum Basket Frequency**

This determines how common a pair or triplet must be to be analyzed.

* **Why it matters:**\
  Setting a minimum ensures you focus on patterns with meaningful sample size.
* **Allowed range:** 0.0001 – 0.20
* **Example:** 0.001 (0.1%) means a pair must appear in at least 0.1% of all orders.

Lower values allow rare but potentially interesting combinations to surface.\
Higher values return only very frequent itemsets.

***

#### **Step 3: Rule Strength Metric**

You can choose how association strength is evaluated:

* **Lift** (default): Measures how much more likely items appear together than by random chance.
* **Confidence:** Probability that B is purchased when A is purchased.

Use Lift when you want reliable cross-sell signals.\
Use Confidence when evaluating predictability.

**Minimum Rule Strength** filters out weak relationships.

* **Lift range:** 1–50
* **Confidence range:** 0.05–1.0

***

#### **Exclude Items (Optional)**

You can remove specific items from the analysis (e.g., shipping fees, packaging material).

Enter comma-separated, quoted names.\
Example: `"SERVICE FEE", "PACKAGING"`.

***

## **Model Results**

Once the scenario runs, Basket Analysis provides four structured results sections:

***

### **Overview**

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2FrEI35DFg89om5tepvQCo%2Fimage.png?alt=media&#x26;token=d70cfee9-ef6f-460e-acc5-3b8f34b4c979" alt=""><figcaption></figcaption></figure>

The Overview page summarizes your dataset after cleaning and transformation. It includes:

* **Transactions Analyzed** – Total number of baskets processed.
* **Total Unique Items (before cleaning)** – All item types found in the dataset.
* **Items Kept After Cleaning** – Items retained after removing ultra-rare entries.
* **Average Basket Size** – Typical number of items per transaction.
* **Pruning Ratio** – Percentage of items removed due to rarity thresholds.

This gives you a clear view of data quality and model scope before diving into pair and triplet patterns.

***

### **Frequent Items**

This tab highlights the **Top Items by Support**, showing which products appear most often across all transactions.

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2F6aqyUN0cbtoU8WVmrPO6%2Fimage.png?alt=media&#x26;token=307ef056-a66e-469f-930f-73a37d1c33b8" alt=""><figcaption></figcaption></figure>

Support is defined as:

> **Support = (Number of transactions containing the item) ÷ (Total transactions)**

This view is useful for:

* Identifying top sellers
* Planning replenishment and stock levels
* Understanding core product demand patterns

Each listed item displays:

* The number of orders it appears in
* Its support percentage
* A visual bar indicator for quick comparison

***

### **Pair Rules**

Pair Rules uncover strong two-item associations.\
This section answers:\
\&#xNAN;**“If a customer buys item A, which item B do they also tend to buy?”**

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2FJtRyBJdtEct56ouOnnz7%2Fimage.png?alt=media&#x26;token=7e5fc3e4-a528-4ef1-bddf-b48c345cd973" alt=""><figcaption></figcaption></figure>

Each rule includes:

* **Occurrences** – How many transactions contain both items.
* **Confidence** – Probability B appears when A appears.
* **Support** – How common this pair is across all transactions.
* **Lift** – How much stronger the association is compared to random chance.

High-lift rules indicate meaningful cross-sell opportunities—ideal for:

* Recommender systems
* Combo deals
* Checkout suggestions
* Shelf placement optimization

***

### **Triplet Rules**

Triplet Rules identify combinations of **three items** that frequently appear together.\
This reveals natural bundles and multi-product purchasing patterns.

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2FWH24DfN0fHKXbF3RIoNx%2Fimage.png?alt=media&#x26;token=ba9eab06-1d23-409e-9317-b5e5b8cacd4a" alt=""><figcaption></figcaption></figure>

For each triplet, you see:

* **Occurrences across transactions**
* **Confidence of the three-item combination**
* **Support percentage**
* **Lift score**, showing the strength of the trio relationship

Triplet rules are often used to design bundles, seasonal sets, curated gift packs, or promotions around complementary items.

***

### **Details**

The Details tab provides full access to:

* Frequency tables for items
* All pairwise rules (in sortable table form)
* All triplet rules
* Internal metrics used in rule creation
* Filtered itemsets after pruning
* Support and confidence thresholds applied

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2FoZFGToRGCK0Q35reCH7w%2Fimage.png?alt=media&#x26;token=0d1a8232-50f3-4871-ba96-88b26c333092" alt=""><figcaption></figcaption></figure>

This is the best place for analysts who want granular, technical output.

***

## **Actionable Insights**

Graphite Note automatically generates an **Executive Strategy Brief**, converting the statistical results into clear business recommendations.

The brief includes:

#### **1. Executive Summary**

A plain-language overview of what the analysis revealed, including key product relationships and opportunities.

#### **2. Metrics Explained (for Business Users)**

Definitions and clear examples of:

* **Support**
* **Confidence**
* **Lift**

Written so non-technical stakeholders can understand what makes a rule strong or weak.

<figure><img src="https://3727300098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgnR78y9L7FDWeb4jdvdW%2Fuploads%2FxzXMPw3Zp2BfSzyz3lmu%2Fimage.png?alt=media&#x26;token=2fdd6f21-f591-4ae7-970f-bf77c6f4482f" alt=""><figcaption></figcaption></figure>

#### **3. What We Analyzed**

Overview of dataset filtering, thresholds applied, and the focus of the model (frequent items, pairs, triplets).

#### **4. Recommended Actions**

Graphite Note generates ready-to-implement steps such as:

* Cross-sell suggestions
* Bundle ideas
* Merchandising improvements
* Promotional opportunities
* Product placement strategies

All grounded directly in the discovered rules.

***

## **API Access**

You can retrieve model results programmatically through the **Model Results API**.\
This allows automated ingestion into dashboards, recommendation engines, or custom applications.

#### **Python Example**

```python
import requests

url = "https://app.graphite-note.com/api/model/fetch-result/<your-model-id>"
headers = {
    "Authorization": "Bearer <YOUR_GN_API_TOKEN>",
    "Content-Type": "application/json"
}
payload = {
    "page-size": 100,
    "page": 1
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

The API returns paginated data, including:

* Frequent items
* Pair rules
* Triplet rules
* All model metadata
* All computed metrics

This enables seamless integration into downstream systems.
