Skip to content

Commit 76e5a5f

Browse files
Ibraheem OlasupoIbraheem Olasupo
authored andcommitted
Add governed recommendation baseline
1 parent 550c4d7 commit 76e5a5f

30 files changed

Lines changed: 3367 additions & 9 deletions

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ jobs:
5757

5858
- name: Verify deterministic segmentation evidence
5959
run: make verify-segmentation-evidence
60+
61+
- name: Verify deterministic recommendation evidence
62+
run: make verify-recommendation-evidence

‎Makefile‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: install format lint type-check test quality project-info generate-sample ingest-sample verify-ingestion-evidence analyse-funnels-sample verify-funnel-evidence analyse-retention-sample verify-retention-evidence train-churn-sample verify-churn-evidence segment-users-sample verify-segmentation-evidence
1+
.PHONY: install format lint type-check test quality project-info generate-sample ingest-sample verify-ingestion-evidence analyse-funnels-sample verify-funnel-evidence analyse-retention-sample verify-retention-evidence train-churn-sample verify-churn-evidence segment-users-sample verify-segmentation-evidence build-recommendations-sample verify-recommendation-evidence
22

33
install:
44
python3 -m pip install --upgrade pip
@@ -60,3 +60,10 @@ segment-users-sample:
6060
verify-segmentation-evidence:
6161
python3 scripts/generate_segmentation_evidence.py
6262
git diff --exit-code -- docs/evidence/milestone-7
63+
64+
build-recommendations-sample:
65+
python3 scripts/generate_recommendation_evidence.py
66+
67+
verify-recommendation-evidence:
68+
python3 scripts/generate_recommendation_evidence.py
69+
git diff --exit-code -- docs/evidence/milestone-8

‎README.md‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The repository is written for product data scientists, product analysts, growth
2525

2626
Planned capabilities include synthetic product event generation, clickstream ingestion, validation, funnel analytics, cohort retention, churn prediction, segmentation, recommendation modelling, controlled A/B testing, customer feedback intelligence, GenAI-assisted product insights, Power BI-ready outputs, and Azure-aligned security, governance, monitoring, and deployment patterns.
2727

28-
Milestones 1, 2, 3, 4, 5, 6, and 7 implement the repository foundation, deterministic synthetic NexaFlow data generation, local event ingestion with data-quality validation, governed funnel analytics, governed retention/cohort analytics, leakage-aware churn prediction, and governed user segmentation. Later recommendation, experimentation, GenAI, dashboard, and Azure deployment work remains planned.
28+
Milestones 1, 2, 3, 4, 5, 6, 7, and 8 implement the repository foundation, deterministic synthetic NexaFlow data generation, local event ingestion with data-quality validation, governed funnel analytics, governed retention/cohort analytics, leakage-aware churn prediction, governed user segmentation, and governed recommendation baselines. Later experimentation, GenAI, dashboard, and Azure deployment work remains planned.
2929

3030
## Azure Service Mapping
3131

@@ -35,8 +35,9 @@ Milestones 1, 2, 3, 4, 5, 6, and 7 implement the repository foundation, determin
3535
| Raw, trusted, and quarantine storage | Azure Data Lake Storage Gen2 | Local raw, interim accepted, and quarantine zones implemented |
3636
| Stream processing | Azure Stream Analytics or Azure Functions | Local deterministic micro-batch simulation implemented |
3737
| Analytical serving | Azure Synapse Analytics | Local governed funnel outputs implemented |
38-
| Model training and tracking | Azure Machine Learning | Local deterministic churn training implemented |
38+
| Model training and tracking | Azure Machine Learning | Local deterministic churn and recommendation baseline training implemented |
3939
| User segmentation | Azure Machine Learning | Local governed rule-based and KMeans segmentation implemented |
40+
| Recommendation batch generation | Azure Machine Learning | Local governed recommendation outputs implemented |
4041
| GenAI insights | Azure AI Foundry and Azure OpenAI | Planned |
4142
| Dashboards | Power BI | Planned |
4243
| Observability | Azure Monitor and Application Insights | Planned configuration placeholders |
@@ -105,9 +106,15 @@ Feature groups cover account context, activity level, engagement depth, collabor
105106

106107
Runtime segmentation outputs are written under `outputs/models/segmentation/<segmentation_run_id>/`, which is ignored by Git. Concise reproducible evidence for the committed sample is stored in `docs/evidence/milestone-7/`.
107108

109+
## Governed Recommendation Baseline
110+
111+
Milestone 8 adds deterministic recommendation baselines over trusted Milestone 3 accepted outputs. The workflow creates a governed product-action catalogue, maps clickstream events into implicit-feedback strengths, builds point-in-time user-item interactions, applies plan/persona/company-size eligibility, generates candidates, compares popularity, recent-popularity, segment-aware popularity, and item-item collaborative-filtering baselines, and reports offline ranking, coverage, novelty, diversity, segment, and cold-start metrics.
112+
113+
Runtime recommendation outputs are written under `outputs/models/recommendations/<recommendation_run_id>/`, which is ignored by Git. Concise reproducible evidence for the committed sample is stored in `docs/evidence/milestone-8/`. The workflow is an offline synthetic-data baseline only; it is not an online recommender, causal treatment policy, or experiment readout.
114+
108115
## Analytics, ML, and GenAI Use Cases
109116

110-
Analytics use cases include active user tracking, journey funnels, feature adoption, retention, churn, resurrection, customer lifetime value, and governed user segmentation. ML use cases now include local churn prediction and segmentation demonstrations; recommendation baselines and experiment uplift interpretation remain planned. GenAI use cases will focus on grounded summarisation, feedback theme extraction, insight narratives, and human-reviewed product action recommendations.
117+
Analytics use cases include active user tracking, journey funnels, feature adoption, retention, churn, resurrection, customer lifetime value, and governed user segmentation. ML use cases now include local churn prediction, segmentation, and recommendation baseline demonstrations; experiment uplift interpretation remains planned. GenAI use cases will focus on grounded summarisation, feedback theme extraction, insight narratives, and human-reviewed product action recommendations.
111118

112119
## Repository Structure
113120

@@ -151,7 +158,7 @@ Analytics use cases include active user tracking, journey funnels, feature adopt
151158
| 5. Retention and cohort analysis | Measure product stickiness | Cohort tables and retention views | Windowing tests | Completed |
152159
| 6. Churn prediction | Identify at-risk users | Leakage-aware features and model training | Reproducibility and evaluation tests | Completed |
153160
| 7. User segmentation | Explain behavioural groups | Rule-based and KMeans segmentation | Determinism and profile tests | Completed |
154-
| 8. Recommendation baseline | Suggest items or features | Baseline recommender | Ranking tests | Recommendation outputs |
161+
| 8. Recommendation baseline | Suggest items or features | Baseline recommender | Ranking tests | Completed |
155162
| 9. A/B testing analysis | Evaluate product changes | Experiment analysis module | Statistical tests | Experiment readout |
156163
| 10. GenAI product insight assistant | Summarise grounded insights | Prompting and grounding layer | Mocked GenAI tests | Insight briefs |
157164
| 11. Power BI-ready outputs | Serve decision-ready datasets | Export tables and semantic docs | Schema tests | Dashboard-ready files |
@@ -187,6 +194,8 @@ make train-churn-sample
187194
make verify-churn-evidence
188195
make segment-users-sample
189196
make verify-segmentation-evidence
197+
make build-recommendations-sample
198+
make verify-recommendation-evidence
190199
```
191200

192201
Generate a synthetic run directly:
@@ -259,6 +268,18 @@ python3 -m product_growth_intelligence segment-users \
259268
--fixed-run-time 2026-01-02T00:00:00Z
260269
```
261270

271+
Run governed recommendations against trusted ingestion output:
272+
273+
```bash
274+
python3 -m product_growth_intelligence build-recommendations \
275+
--input-dir data/interim/<ingestion_run_id> \
276+
--output-root outputs/models/recommendations \
277+
--snapshot-time 2025-03-31T23:59:59Z \
278+
--lookback-days 56 \
279+
--holdout-days 28 \
280+
--fixed-run-time 2026-01-02T00:00:00Z
281+
```
282+
262283
## Quality and Security Principles
263284

264285
The implementation favours typed Python, deterministic behaviour, small interfaces, no embedded secrets, no generated data in Git, clear metric ownership, local validation by default, and Azure-specific adapters only where they are useful. Future Azure deployments should use managed identity, RBAC, Key Vault, private networking where appropriate, and monitoring that avoids leaking customer data.
@@ -278,7 +299,8 @@ The implementation favours typed Python, deterministic behaviour, small interfac
278299
| Retention and cohort analytics | Completed | Versioned retention definitions, cohort periods, censoring, lifecycle, evidence |
279300
| Churn prediction | Completed | Local deterministic model training, evaluation, model card, evidence |
280301
| User segmentation | Completed | Rule-based segments, KMeans, stability, PCA, profiles, evidence |
281-
| Recommendations, GenAI | Planned | Milestones 8-12 are not implemented |
302+
| Recommendation baseline | Completed | Local deterministic candidate generation, ranking, metrics, reasons, evidence |
303+
| Experimentation, GenAI | Planned | Milestones 9-12 are not implemented |
282304
| Azure deployment | Optional Azure deployment | No live resources required |
283305

284306
## Synthetic-Data Disclaimer

‎docs/architecture/azure-service-mapping.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ The platform is local-first, but each major component is designed to map cleanly
1313
| Funnel transformations | Local governed funnel pipeline | Azure Synapse Analytics |
1414
| Cohort transformations | Local governed retention pipeline | Azure Synapse Analytics |
1515
| Churn feature preparation | Local point-in-time churn feature builder | Azure Synapse Analytics or Azure ML data preparation |
16+
| Recommendation interaction preparation | Local point-in-time interaction and candidate builder | Azure Synapse Analytics or Azure ML data preparation |
1617
| Scheduled analytics | Makefile/CI commands | Azure Data Factory or Synapse pipelines |
1718
| Model training | Local deterministic churn training scripts | Azure Machine Learning |
1819
| Model tracking | Local reports, manifests, lineage, and metadata | Azure ML jobs, MLflow, and Azure ML registry |
1920
| User segmentation | Local rule-based and KMeans segmentation | Azure Machine Learning |
21+
| Recommendation baselines | Local popularity, segment-aware, and item-item CF baselines | Azure Machine Learning |
2022
| Batch scoring | Local prediction CSV outputs | Azure ML batch endpoints |
2123
| Batch segment assignment | Local assignment CSV outputs | Azure ML batch endpoints |
24+
| Batch recommendation generation | Local recommendation CSV and reason JSONL outputs | Azure ML batch endpoints or Synapse scheduled jobs |
2225
| Online scoring | Future scope only | Azure ML managed online endpoints |
2326
| GenAI insights | Mocked or disabled by default | Azure AI Foundry and Azure OpenAI |
2427
| Dashboards | Local documented outputs | Power BI |
@@ -36,4 +39,4 @@ The platform is local-first, but each major component is designed to map cleanly
3639
- Infrastructure templates are planned, not active, in Milestone 6.
3740
- No Azure service is deployed by the current repository.
3841

39-
The churn and segmentation workflows map trusted accepted data to ADLS Gen2 trusted zones, feature preparation to Synapse or Azure ML data preparation, experiment tracking to Azure ML jobs and MLflow, model registry to Azure ML registry, monitoring to Azure Monitor and Azure ML monitoring, secrets to Key Vault, identity to managed identity and Azure RBAC, governance and lineage to Microsoft Purview, and dashboard consumption to Power BI. The local implementation does not install Azure SDKs, create clients, deploy resources, or claim an Azure ML endpoint exists.
42+
The churn, segmentation, and recommendation workflows map trusted accepted data to ADLS Gen2 trusted zones, feature and interaction preparation to Synapse or Azure ML data preparation, experiment tracking to Azure ML jobs and MLflow, model registry to Azure ML registry, monitoring to Azure Monitor and Azure ML monitoring, secrets to Key Vault, identity to managed identity and Azure RBAC, governance and lineage to Microsoft Purview, and dashboard consumption to Power BI. The local implementation does not install Azure SDKs, create clients, deploy resources, or claim an Azure ML endpoint exists.

‎docs/architecture/data-flow.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Data Flow
22

3-
This document describes the logical data flow. Milestone 3 implements the local raw-to-interim ingestion and validation portion. Milestone 4 implements governed funnel analytics over trusted interim data. Milestone 5 implements governed retention and cohort analytics. Milestone 6 implements local leakage-aware churn prediction. Milestone 7 implements governed user segmentation. GenAI, dashboarding, and Azure deployment remain planned.
3+
This document describes the logical data flow. Milestone 3 implements the local raw-to-interim ingestion and validation portion. Milestone 4 implements governed funnel analytics over trusted interim data. Milestone 5 implements governed retention and cohort analytics. Milestone 6 implements local leakage-aware churn prediction. Milestone 7 implements governed user segmentation. Milestone 8 implements governed recommendation baselines. Experiment analysis, GenAI, dashboarding, and Azure deployment remain planned.
44

55
```mermaid
66
sequenceDiagram
@@ -49,6 +49,8 @@ Milestone 6 writes churn-model outputs under `outputs/models/churn/<model_run_id
4949

5050
Milestone 7 writes segmentation outputs under `outputs/models/segmentation/<segmentation_run_id>/`, including segmentation definition, feature catalogue, snapshots, feature matrix, rule-based assignments, cluster candidate metrics, stability, assignments, profiles, centroids, PCA outputs, segment names, metadata, diagnostics, manifest, lineage, and segment card.
5151

52+
Milestone 8 writes recommendation outputs under `outputs/models/recommendations/<recommendation_run_id>/`, including recommendation definition, item catalogue, interaction mapping, point-in-time user-item interactions, candidate items, model comparison, offline metrics, metrics by K, segment metrics, cold-start metrics, item similarity, recommendations, deterministic reasons, catalogue coverage, metadata, diagnostics, manifest, lineage, and recommendation card.
53+
5254
```mermaid
5355
flowchart LR
5456
A[Trusted accepted data] --> B[Point-in-time snapshots]
@@ -77,3 +79,18 @@ flowchart LR
7779
H --> J[Segment card manifest lineage]
7880
I --> J
7981
```
82+
83+
```mermaid
84+
flowchart LR
85+
A[Trusted accepted data] --> B[Recommendation snapshot]
86+
B --> C[Historical interactions]
87+
B --> D[Catalogue eligibility]
88+
C --> E[Popularity and similarity baselines]
89+
D --> F[Candidate generation]
90+
F --> G[Ranked recommendations]
91+
E --> G
92+
B --> H[Future holdout window]
93+
G --> I[Offline ranking metrics]
94+
H --> I
95+
I --> J[Manifest card lineage]
96+
```

‎docs/architecture/metric-framework.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Metric Framework
22

3-
This document defines governed metric concepts. Milestone 4 implements operational funnel formulas and denominator rules for descriptive product journeys. Milestone 6 adds governed churn-model evaluation definitions.
3+
This document defines governed metric concepts. Milestone 4 implements operational funnel formulas and denominator rules for descriptive product journeys. Milestone 6 adds governed churn-model evaluation definitions. Milestone 8 adds offline recommendation-ranking metric definitions.
44

55
| Metric | Conceptual definition |
66
| --- | --- |
@@ -96,3 +96,21 @@ Churn model selection uses validation metrics only. The default rule ranks by va
9696
| `SEGMENT_PROFILE_SHARE` | Segment population share | Segment users divided by eligible users | Null when no eligible users exist |
9797

9898
Segmentation candidates are selected by rejecting clusters below the minimum-size rule, prioritising silhouette score, using stability as a tie-breaker, and preferring fewer clusters where quality is materially similar. Segment profiles are descriptive and suppression-aware.
99+
100+
## Recommendation Ranking Metrics
101+
102+
| Metric ID | Business meaning | Definition | Null handling |
103+
| --- | --- | --- | --- |
104+
| `REC_PRECISION_AT_K` | Share of top-K recommendations that appear in future holdout interactions | Relevant recommended items in top K divided by recommended items in top K | Zero when no evaluated recommendations exist |
105+
| `REC_RECALL_AT_K` | Share of future relevant items captured in top K | Relevant recommended items in top K divided by relevant holdout items | Zero when no relevant holdout items exist |
106+
| `REC_HIT_RATE_AT_K` | Share of evaluated users with at least one relevant top-K recommendation | Users with a hit in top K divided by evaluated users | Zero when no evaluated users exist |
107+
| `REC_MRR` | Ranking position of first relevant recommendation | Mean reciprocal rank of first hit per evaluated user | Zero when no first hit exists |
108+
| `REC_MAP_AT_K` | Average precision across the ranked top-K list | Mean average precision at K over evaluated users | Zero when no evaluated users exist |
109+
| `REC_NDCG_AT_K` | Position-aware ranking quality | Normalised discounted cumulative gain at K against binary holdout relevance | Zero when ideal DCG is zero |
110+
| `REC_CATALOGUE_COVERAGE_AT_K` | Breadth of catalogue exposure | Distinct items recommended in top K divided by active catalogue items | Zero when catalogue is empty |
111+
| `REC_USER_COVERAGE` | Share of eligible users receiving recommendations | Users with recommendation rows divided by eligible users with model output | Zero when no eligible users exist |
112+
| `REC_NOVELTY_AT_K` | Preference for less historically common items | Mean negative log historical item share with smoothing | Zero when no recommendation rows exist |
113+
| `REC_DIVERSITY_AT_K` | Variety of item categories within recommendation lists | Mean distinct item categories divided by recommended items | Zero when no recommendation rows exist |
114+
| `REC_FALLBACK_RATE` | Share of recommendations produced by fallback logic | Fallback recommendation rows divided by recommendation rows | Zero when no recommendation rows exist |
115+
116+
Recommendation metrics are descriptive offline metrics over synthetic data. The future holdout window is used only for evaluation and never for candidate generation or scoring. Model selection rejects models below coverage guardrails, prioritises NDCG@5, uses recall@5 as a tie-breaker, and prefers simpler baselines where quality is materially similar.

0 commit comments

Comments
 (0)