AI Initiative logoAI Initiative
Reading room / GraFOSa

GraFOSa Classical ML Proposal

Seven classical-ML directions over graph metrics, including defect prediction, anomalies, changepoints, survival models, service boundaries, co-change and scoring optimisation.

Proposal
This is the retained source text, not a new validation of its claims. Numerical results and comparative claims require the accompanying source review before public reuse.

Read the connected case study or article →

Author not established in the source · Date not established

Provenance, authorship and editorial notes

GraFOSa Classical ML Proposal

Id

grafosa-classical-ml

Source path

grafosa/docs/CLASSICAL-ML-PROPOSAL.md

Source sha256

3ab106f66a580a786c5cf21c067059652776902200cf6b8d4d0c17ca19bd0bc5

Bytes

13730

Repo root

grafosa

Repo head

388b50cfb34decee9d716f7f02d01ccf53305c03

Last git commit date

2026-03-05T13:23:48Z

Copy scope

Private full-text review candidate; not approved for public release.

Copy status

FULL_TEXT_BYTE_IDENTICAL

Metadata lines

No entries recorded.

Author
Not recorded
Date
Not recorded
Format

Markdown

Publication status

NOT_ESTABLISHED

Word count

1790

Disclosure concerns
  • Authorised private review copy. Preserve the original attribution and document status when selecting a public edition.
  • Document claims and numerical results are historical source assertions, not independently revalidated by this discovery.
  • CPU/cost/determinism/interpretability comparisons are broad proposal claims, not universal properties or measured implementation results.
Author provenance

Not stated; not inferred from repository ownership

Date provenance

Not stated; citation access and Git commit dates are not publication dates

Document status

Proposal

Summary

Seven classical-ML directions over graph metrics, including defect prediction, anomalies, changepoints, survival models, service boundaries, co-change and scoring optimisation.

Recommended library type

Proposed research direction

Attribution scope

GraFOSa professional-work source; retain explicit GraFOSa Research Team byline where present. Repository location alone does not identify individual authors.

Private review scan
Id

grafosa-classical-ml

Scanned file

AI-Initiative-Architecture-Review-2026-10-26/research/publications/grafosa-classical-ml.md

Sha256

3ab106f66a580a786c5cf21c067059652776902200cf6b8d4d0c17ca19bd0bc5

Credential pattern counts
Private key

0

Provider key

0

Github token

0

Aws access id

0

Jwt

0

Quoted credential assignment

0

Email count

0

Contact classification

No email patterns found

Customer record findings

No customer-record content identified in targeted text inspection.

Limits

Targeted pattern scan and publication-text review, not exhaustive data-loss-prevention certification.

GraFOSa Classical ML Proposal

Classical machine learning for graph-first structural analysis — no GPU, no LLM, fully interpretable.

Why Classical ML

PropertyClassical MLLLM/GenAI
Training timeSeconds to minutesHours to days
Inference timeMicrosecondsSeconds
HardwareAny CPUGPU / large RAM
InterpretabilityFull (feature importance, decision paths)Black box
Data neededHundreds of samplesMillions of tokens
ReproducibilityDeterministicStochastic
CostZeroAPI costs or GPU hours

Classical ML answers the question: given the graph metrics we already compute, what can we PREDICT?


Proposal: 7 ML Capabilities

1. Bug Prediction (Random Forest / XGBoost)

Problem: Which modules are most likely to have bugs in the next sprint?

Approach: Train a gradient-boosted classifier on graph-derived features per node.

Features from GraFOSa's existing graph:

Labels: Git ground truth — files that appeared in bug-fix commits (already available via GitGroundTruth.extract()).

Output: Per-file bug probability (0-1) with feature importance explaining WHY.

Expected performance: F1 0.80-0.90 based on published research (Microsoft, Google, Huawei studies on defect prediction from software metrics).

Dependencies: scikit-learn (or zero-dep implementation with decision stumps)

Fits in GraFOSa: Runs after health_report(), uses the same graph kernel. Results stored as node properties (_bug_probability, _bug_risk_factors).


2. Anomaly Detection (Isolation Forest)

Problem: Something changed in the codebase health and it's unusual — but what?

Approach: Isolation Forest on multivariate health metrics time series. Detects outlier health snapshots without manual thresholds.

Features (per health snapshot):

How it works: Isolation Forest isolates anomalies by randomly splitting features. Anomalies need fewer splits to isolate (they're "different" from the crowd). No need to define "what's normal" — the algorithm learns it.

Output:

Use case: "Your health score dropped 3 points — is that normal churn or an anomaly?" Isolation Forest answers this without hand-tuned thresholds.

Dependencies: scikit-learn or pure-Python implementation (~100 lines)


3. Changepoint Detection (PELT / CUSUM)

Problem: When EXACTLY did the architecture start degrading?

Approach: PELT (Pruned Exact Linear Time) algorithm on health score time series. Finds points where the statistical properties of the series change.

What it detects:

Output:

Why this matters: Trend lines smooth over abrupt changes. Changepoint detection finds the EXACT moment something broke — then git correlation identifies the likely cause.

Dependencies: ruptures library or pure-Python CUSUM (~50 lines)


4. Survival Analysis (Cox Proportional Hazards)

Problem: How long until this module needs a fix?

Approach: Cox model treats each module as a "patient" and bug-fix commits as "events." Graph metrics are covariates that influence the hazard rate.

Covariates:

Output:

Why this is powerful: Unlike bug prediction (binary yes/no), survival analysis gives a TIME estimate. Combined with GraFOSa's health trending, you get "this module will need attention in ~3 weeks."

Dependencies: lifelines library or manual Breslow estimator


5. Service Boundary Discovery (Spectral Clustering / DBSCAN)

Problem: Are the current microservice boundaries optimal, or should things be reorganized?

Approach: Cluster nodes in the dependency graph based on connectivity patterns. Nodes that are densely connected internally but sparsely connected externally form natural service boundaries.

Methods:

Input: The adjacency matrix from GraphKernel (already available via _outgoing/_incoming indices).

Output:

Why this matters: Manual service boundary decisions are often historical accidents. Clustering reveals what the code itself thinks the boundaries should be.


6. Co-change Mining (Association Rules / Apriori)

Problem: Which files are secretly coupled — always changed together but not connected in the dependency graph?

Approach: Mine git commit history for frequent co-change patterns using Apriori or FP-Growth algorithms.

Data source: Git commits — each commit is a "transaction," each changed file is an "item."

Output:

Metrics per rule:

Why this matters: The dependency graph shows STRUCTURAL coupling. Co-change mining shows LOGICAL coupling — the coupling humans create through behavior. The gap between these two is where architectural debt lives.

Dependencies: Pure Python implementation (~150 lines) or mlxtend


7. Scoring Config Optimization (Bayesian Optimization)

Problem: GraFOSa's health scoring has dozens of weights and thresholds. Are they optimal?

Approach: Use Bayesian optimization to find the scoring configuration that best predicts real-world outcomes (bugs, incidents, developer pain).

Search space:

Objective function: Maximize correlation between GraFOSa health score and actual bug frequency (from git ground truth). A good config should assign low scores to modules that later have bugs.

Method: Gaussian Process-based Bayesian optimization. Builds a surrogate model of the objective function, efficiently explores the parameter space. Typically converges in 50-100 evaluations.

Output:

Why this matters: Currently, GraFOSa's scoring weights are hand-tuned. This closes the loop — let the data tell you what matters.

Dependencies: scikit-optimize or pure-Python GP implementation


Integration Architecture

                     GraFOSa Graph Kernel
                            │
              ┌─────────────┼─────────────────┐
              │             │                 │
         Graph Metrics   Git History    Health Snapshots
              │             │                 │
              ▼             ▼                 ▼
    ┌─────────────┐  ┌────────────┐  ┌──────────────┐
    │ Bug Predict  │  │ Co-change  │  │ Anomaly Det  │
    │ (XGBoost)    │  │ (Apriori)  │  │ (IsoForest)  │
    ├─────────────┤  ├────────────┤  ├──────────────┤
    │ Survival     │  │ Boundary   │  │ Changepoint  │
    │ (Cox Model)  │  │ (Spectral) │  │ (PELT)       │
    └──────┬──────┘  └─────┬──────┘  └──────┬───────┘
           │               │                │
           └───────────────┼────────────────┘
                           │
                  Bayesian Optimization
                  (tunes GraFOSa config)
                           │
                           ▼
                 Predictions as Node Properties
                 (_bug_prob, _survival_days, etc.)

Proposed Implementation

File Structure

src/grafosa/ml/
├── __init__.py
├── bug_predictor.py        # Random Forest / XGBoost bug prediction
├── anomaly_detector.py     # Isolation Forest on health time series
├── changepoint.py          # PELT / CUSUM changepoint detection
├── survival.py             # Cox proportional hazards model
├── clustering.py           # Spectral clustering + DBSCAN for service boundaries
├── cochange.py             # Association rule mining from git history
├── config_optimizer.py     # Bayesian optimization for scoring config
└── features.py             # Shared feature extraction from graph kernel

MCP Tools

ToolPurpose
ml_bug_predictPredict bug probability per module
ml_anomaly_detectDetect anomalies in health history
ml_changepointFind when health characteristics changed
ml_survivalEstimate time-to-next-fix per module
ml_cluster_servicesDiscover optimal service boundaries
ml_cochangeMine hidden coupling from git history
ml_optimize_configAuto-tune scoring configuration
ml_feature_importanceShow which graph metrics drive predictions

Dependency Strategy

Zero-dep core (pure Python):

Optional scikit-learn (recommended):

Optional extras:

All modules degrade gracefully — if scikit-learn isn't installed, fall back to pure-Python implementations with reduced accuracy.

Priority Order

PriorityCapabilityValueEffort
1Bug PredictionHighest — directly actionableMedium
2Co-change MiningHigh — reveals hidden couplingLow
3Anomaly DetectionHigh — pairs with health trendingLow
4Service Boundary DiscoveryHigh — architectural insightsMedium
5Changepoint DetectionMedium — root cause analysisLow
6Scoring Config OptimizationMedium — self-improving systemMedium
7Survival AnalysisMedium — time-based predictionsMedium

Recommended start: Bug Prediction + Co-change Mining + Anomaly Detection — three capabilities, highest combined value, lowest combined effort. All three feed off data GraFOSa already computes (graph metrics, git history, health snapshots).

Expected Impact

All of this runs on a laptop, trains in seconds, needs zero GPU, and every prediction is fully explainable.

Continue exploring