Skip to content

Add return_models option to getPercentScore (#181)#196

Open
OmerJauhar wants to merge 2 commits into
TeaspoonTDA:masterfrom
OmerJauhar:fix-181
Open

Add return_models option to getPercentScore (#181)#196
OmerJauhar wants to merge 2 commits into
TeaspoonTDA:masterfrom
OmerJauhar:fix-181

Conversation

@OmerJauhar
Copy link
Copy Markdown

Description

Adds an optional return_models=False keyword to getPercentScore. When set to True, the function returns a third value: a list of {model, scaler} dicts, one per cross-validation fold. Each entry holds the fitted classifier and the StandardScaler that was applied to its training features, so users can run the model on new raw data with scaler.transform(...) followed by model.predict(...). The kernel-method branch sets scaler to None since that path doesn't use one. Default behavior is unchanged, old callers continue to receive the 2-tuple (c_report_train, c_report_test).

Motivation and Context

Closes #181. As @Ignaci09 pointed out, getPercentScore only returned the train and test reports, so there was no way to use the trained models for prediction after cross-validation. With return_models=True, the fitted estimator and its corresponding scaler are now accessible.

How has this been tested?

  • Confirmed the default 2-tuple return is unchanged for existing callers.
  • Confirmed return_models=True returns a 3-tuple, with len(models) == params.k_fold_cv.
  • Used a returned (model, scaler) pair to run predict() on unseen samples — output matches expectations.
  • Verified the kernel-method branch returns scaler=None (since it doesn't apply a StandardScaler) while still returning the fitted SVC(kernel='precomputed').
  • Existing test suite (tests/test_classification.py, tests/test_featureFunctions.py) — 4 passed.
  • Confirmed both APIs work on Python 3.13.13 as well as 3.10.
  • Rebuilt the docs locally with make html to confirm the new "Extracting the trained models" section renders cleanly with no new Sphinx warnings

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the code style of this project. (make clean)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (make html)
  • I have incremented the version number in the pyproject.toml file.
  • I have added tests to cover my changes.
  • All new and existing tests passed. (make tests)

…eturn_models=True, the function returns a third value: a list of {model, scaler} dicts, one per CV fold. Default stays False so existing callers are unaffected. The kernel method branch sets scaler to None since it doesn't use one.
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.

Suggestion: allow extraction of the trained models from getPercentScore

1 participant