feat(ml): album shape proposal training module with sklearn #467

Open
chris wants to merge 1 commit from feature/003-album-ml-training into main
Owner

Summary

New Python module implementing the album shape proposal ML training logic for spec 003 (Automatic Album Suggestions).

What changed

  1. album_proposal_train.py - New standalone training module:

    • Uses sklearn LogisticRegression when available with feature+label pairs
    • Falls back to label-weighted heuristic coefficient estimation
    • Produces coefficients + intercept compatible with the scoring handler
    • Handles edge cases: insufficient data, single class, missing features
  2. jobs.py - Handler delegation (minimal change):

    • album_shape_proposal_train handler now calls train_album_shape_model()
    • Returns structured TrainingResult instead of inline heuristic
    • Adds scoringMode to validation metrics
  3. pyproject.toml - New optional dependency:

    • ml-train = ["scikit-learn>=1.6,<2"] optional group
  4. test_album_proposal_train.py - 28 unit tests:

    • Label weight computation, suggestion ID extraction, feature extraction
    • Heuristic training with various label distributions
    • sklearn training with mixed labels/features
    • Fallback behavior and edge cases

Design decisions

  • Graceful degradation: sklearn first, heuristic fallback. No hard dependency.
  • Future-proof: accepts optional feature_batch for when Core API sends features.
  • No Core API Java changes. Worker receives data via job payload.
  • Coefficient format compatible with scoring handler.

Verification

All 57 ML worker tests pass (20 existing + 28 new + 9 fixture tests).

## Summary New Python module implementing the album shape proposal ML training logic for spec 003 (Automatic Album Suggestions). ### What changed 1. album_proposal_train.py - New standalone training module: - Uses sklearn LogisticRegression when available with feature+label pairs - Falls back to label-weighted heuristic coefficient estimation - Produces coefficients + intercept compatible with the scoring handler - Handles edge cases: insufficient data, single class, missing features 2. jobs.py - Handler delegation (minimal change): - album_shape_proposal_train handler now calls train_album_shape_model() - Returns structured TrainingResult instead of inline heuristic - Adds scoringMode to validation metrics 3. pyproject.toml - New optional dependency: - ml-train = ["scikit-learn>=1.6,<2"] optional group 4. test_album_proposal_train.py - 28 unit tests: - Label weight computation, suggestion ID extraction, feature extraction - Heuristic training with various label distributions - sklearn training with mixed labels/features - Fallback behavior and edge cases ### Design decisions - Graceful degradation: sklearn first, heuristic fallback. No hard dependency. - Future-proof: accepts optional feature_batch for when Core API sends features. - No Core API Java changes. Worker receives data via job payload. - Coefficient format compatible with scoring handler. ### Verification All 57 ML worker tests pass (20 existing + 28 new + 9 fixture tests).
feat(ml): album shape proposal training module with sklearn support
All checks were successful
Build and Deploy / Detect changed services and test scopes (push) Successful in 43s
Build and Deploy / Run scoped PR tests (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
75c8c06ca1
- Add album_proposal_train.py with AlbumShapeModelTrainer
- Use sklearn LogisticRegression when available with feature+label pairs
- Fallback to label-weighted heuristic coefficient estimation
- 28 unit tests covering training, edge cases, sklearn integration
- Optional ml-train dependency in pyproject.toml
- Update jobs.py handler to use new training module

Spec: 003 (Automatic Album Suggestions), Task S003T001
All checks were successful
Build and Deploy / Detect changed services and test scopes (push) Successful in 43s
Build and Deploy / Run scoped PR tests (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin "feature/003-album-ml-training:feature/003-album-ml-training"
git switch "feature/003-album-ml-training"
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!467
No description provided.