Skip to content

feat(AF-645): approval prediction — logistic regression trainer + evaluator - #656

Open
ashish-babu-03 wants to merge 2 commits into
bablsoft:mainfrom
ashish-babu-03:feature/AF-645-approval-prediction-trainer-evaluator
Open

feat(AF-645): approval prediction — logistic regression trainer + evaluator#656
ashish-babu-03 wants to merge 2 commits into
bablsoft:mainfrom
ashish-babu-03:feature/AF-645-approval-prediction-trainer-evaluator

Conversation

@ashish-babu-03

Copy link
Copy Markdown

Closes #648

Implements the mathematical core for the approval-outcome prediction
epic (#645): a pure-Java logistic regression trainer and model evaluator.
No Spring, no database, no external ML libraries — hand-rolled, matching
the precedent set by StatisticalAnomalyDetector.

What's included

  • TrainedApprovalModel.java — immutable record holding intercept,
    weights, feature means/stddevs, and a predict() method that
    standardizes + applies sigmoid. JSON round-trip via Jackson 3
    (tools.jackson.databind).
  • LogisticRegressionTrainer.java — stateless batch gradient descent
    trainer with L2 regularization, zero-initialized weights, and z-score
    feature standardization. Deterministic by design — no randomness
    anywhere.
  • ModelEvaluator.java — stateless evaluator computing AUC via the
    rank-sum method (with average-rank tie handling) and accuracy at a
    configurable threshold.

Testing

All three classes have dedicated test classes per the coverage-parity
rule:

  • LogisticRegressionTrainerTest — verifies >95% accuracy on a
    linearly separable synthetic dataset, exact bit-identical determinism
    across repeated training runs, L2 shrinkage effect, and standardization
    correctness (including constant-column edge case).
  • TrainedApprovalModelTest — JSON round-trip fidelity, sigmoid bounds.
  • ModelEvaluatorTest — known-answer AUC cases (perfect/inverted/tied
    rankings) and hand-computed accuracy.

mvn verify -Pcoverage: 10/10 new tests pass. ApplicationModulesTest
passes — all three classes live in ai/internal, no cross-module
dependency violations.

Note: ran without Docker, so Testcontainers-based integration tests
were skipped locally. Saw 9 pre-existing teardown errors unrelated to
this change (DefaultDriverCatalogServiceTest,
DefaultQueryEngineCatalogTest — JUnit extension context lifecycle
issue), flagging in case it's already a known issue.

@babltiga babltiga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few robustness/convention items to address before merge — details inline. The math itself checks out (verified the standardization, gradient, and rank-sum AUC against the spec in #648).

@ashish-babu-03

Copy link
Copy Markdown
Author

@babltiga Thanks for the detailed review! I've addressed all the robustness and edge-case items.

Here is what was updated:

TrainedApprovalModel Serialization: Replaced the generic catch (Exception e) with catch (JacksonException e) and wrapped it in a new, public ApprovalModelSerializationException so the retraining jobs can properly catch corrupt DB rows as a sentinel.
Fail-fast map lookups: Updated predict() to strictly use .get() rather than .getOrDefault(). Added validation to the compact constructor to reject duplicate feature names and ensure weights, means, and stddevs are fully populated.
Array shape guards: Added explicit IllegalArgumentException checks to both LogisticRegressionTrainer.train and ModelEvaluator (calculateAuc / calculateAccuracy) to fail fast on length mismatches and ragged rows before entering any loops.
Test Parity: Added 9 new unit tests covering all the new exception branches, including the existing empty-input edge cases.
Everything is pushed and CI should be fully green. Ready for another look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai: approval prediction — pure-Java logistic regression trainer + evaluator

2 participants