Skip to content

Updated machine learning model - #461

Draft
jan-janssen wants to merge 10 commits into
mainfrom
ml
Draft

Updated machine learning model#461
jan-janssen wants to merge 10 commits into
mainfrom
ml

Conversation

@jan-janssen

Copy link
Copy Markdown
Owner

No description provided.

@jan-janssen
jan-janssen marked this pull request as draft August 10, 2026 10:56
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.39%. Comparing base (aa9e6d0) to head (820e9df).

Files with missing lines Patch % Lines
gmailsorter/ml/encoding.py 93.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #461      +/-   ##
==========================================
- Coverage   97.50%   97.39%   -0.12%     
==========================================
  Files          35       35              
  Lines        1484     1498      +14     
==========================================
+ Hits         1447     1459      +12     
- Misses         37       39       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jan-janssen

Copy link
Copy Markdown
Owner Author

@copilot Improve test coverage by adding additional unit tests for the changes in this pull request

Co-authored-by: jan-janssen <3854739+jan-janssen@users.noreply.github.com>

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@copilot Improve test coverage by adding additional unit tests for the changes in this pull request

Added 7 new unit tests in tests/test_ml.py (commit $(git -C /home/runner/work/gmailsorter/gmailsorter rev-parse --short HEAD)):

  • test_train_random_forest_respects_max_depth_and_min_samples_leaf – verifies the new max_depth / min_samples_leaf params are applied to the fitted model
  • test_train_random_forest_with_n_jobs – verifies n_jobs is passed through correctly
  • test_fit_machine_learning_models_max_depth_and_min_samples_leaf – same for fit_machine_learning_models
  • test_fit_machine_learning_models_max_workers – verifies max_workers maps to n_jobs on the fitted model
  • test_get_predictions_single_output_label – covers the single-output squeeze normalisation path
  • test_to_sparse_matrix_dense – covers the dense (numpy) code path in _to_sparse_matrix
  • test_to_sparse_matrix_sparse – covers the sparse (scipy CSR) code path in _to_sparse_matrix

@jan-janssen

Copy link
Copy Markdown
Owner Author

pre-commit.ci autofix

@jan-janssen

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

Copilot AI and others added 2 commits August 24, 2026 04:49
- model.py: keep single multi-output RandomForestClassifier approach
- encoding.py: keep sparse matrix approach in one_hot_encoding/_encoding_helper,
  incorporate label_prefix parameter from main
- google/mail.py: remove methods now in AbstractMailBox base class
- base/mail.py: update AbstractMailBox to use new load_model/store_model API
  and new fit_machine_learning_models signature (with max_depth/min_samples_leaf)
- tests/test_ml.py: fix test_spam_example_csv_pipeline_parallel to use new API

Co-authored-by: jan-janssen <3854739+jan-janssen@users.noreply.github.com>
Co-authored-by: jan-janssen <3854739+jan-janssen@users.noreply.github.com>

Copilot AI commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved in commit cf1835d. The three conflicted files were resolved as follows:

  • gmailsorter/ml/model.py: kept the single multi-output RandomForestClassifier approach from this PR
  • gmailsorter/ml/encoding.py: kept the sparse matrix approach in one_hot_encoding/_encoding_helper, and incorporated the label_prefix parameter that main added to encode_df_for_machine_learning
  • gmailsorter/google/mail.py: removed the methods that main moved into AbstractMailBox
  • gmailsorter/base/mail.py (auto-merged with old API): updated filter_messages_from_server and fit_machine_learning_model_to_database to use the new load_model/store_model API and the updated fit_machine_learning_models signature (max_depth, min_samples_leaf params)

All 59 tests pass.

@jan-janssen

Copy link
Copy Markdown
Owner Author

pre-commit.ci autofix

Co-authored-by: jan-janssen <3854739+jan-janssen@users.noreply.github.com>
@jan-janssen

Copy link
Copy Markdown
Owner Author

@copilot Improve unit test coverage for the newly added functionality to maintain the test coverage rate of over 97%

…erver

Co-authored-by: jan-janssen <3854739+jan-janssen@users.noreply.github.com>

Copilot AI commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

@copilot Improve unit test coverage for the newly added functionality to maintain the test coverage rate of over 97%

Added the following new tests across three test files (commit 2a0e8ef):

tests/test_mail_base.py (via _StubMailBox):

  • test_fit_machine_learning_model_forwards_max_depth_and_min_samples_leaf – verifies max_depth and min_samples_leaf are forwarded to fit_machine_learning_models
  • test_filter_messages_from_server_no_model_skips – covers the new early-return when load_model() returns None
  • test_filter_messages_from_server_empty_df_skips – covers the no-op when download_emails_for_label returns an empty DataFrame
  • test_filter_messages_from_server_with_model – covers the full encode → predict → move path

tests/test_google_integration_units.py:

  • Adds max_depth/min_samples_leaf assertions to the existing test_fit_machine_learning_model_to_database
  • test_filter_messages_from_server_no_model_skips – same early-return path via GoogleMailBase

tests/test_ml.py:

  • test_store_model_user_isolation – verifies models for different user_ids are stored and loaded independently
  • test_load_model_missing_returns_empty_features_when_features_exist – verifies load_model returns (None, [], feature_lst) when there is no model row but features exist

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.

2 participants