Add comprehensive tests for classifier pipeline accuracy - #33
Add comprehensive tests for classifier pipeline accuracy#33abuzarmahmood wants to merge 2 commits into
Conversation
- Add generate_raster_with_envelope() function to visualize.py - Creates comprehensive visualization showing both raster plot of movement classifications and raw EMG envelope signals for each taste - Each taste subplot shows trials with predictions overlaid on EMG envelope - Left panel displays EMG envelopes with colored prediction overlays - Right panel shows raster plot of predictions over time - Supports optional taste names and session naming - Integrated into run_flow.py for automatic generation Resolves #27 Co-authored-by: Ona <no-reply@ona.com>
- Add pytest test suite with 20 tests covering: * Artifact loading (XGBoost model, PCA, scaler, event dict) * Prediction consistency across multiple loads * Transform consistency for PCA and scaler * Complete end-to-end pipeline functionality * Error handling for missing artifacts - Update devcontainer to include Python 3.11 - Add pytest to requirements.txt - Update setup.sh to auto-install dependencies Tests verify that saved classifier pipeline produces accurate and consistent predictions, addressing issue #26. Co-authored-by: Ona <no-reply@ona.com>
Test Coverage DetailsThe test suite provides comprehensive coverage of the classifier pipeline with the following breakdown: Artifact Loading TestsThese tests ensure all saved artifacts can be loaded and have the expected structure:
Consistency TestsThese tests verify that the pipeline produces deterministic results:
This is critical for ensuring that predictions are reliable and reproducible across different runs. End-to-End Pipeline TestsThese tests validate the complete workflow from raw EMG data to final predictions:
Error Handling TestsThese tests ensure the pipeline fails gracefully with informative errors:
This helps developers quickly identify configuration issues. |
Technical Implementation NotesTest Design Decisions
Pipeline Architecture InsightsThrough developing these tests, I gained deep understanding of the pipeline:
Future EnhancementsPotential improvements for the test suite:
|
Running the TestsQuick Start# Run all tests with verbose output
python -m pytest tests/test_classifier_pipeline.py -v
# Run specific test class
python -m pytest tests/test_classifier_pipeline.py::TestArtifactLoading -v
# Run specific test
python -m pytest tests/test_classifier_pipeline.py::TestArtifactLoading::test_load_xgb_model -v
# Run with detailed output on failures
python -m pytest tests/test_classifier_pipeline.py -v --tb=long
# Run with coverage (if pytest-cov is installed)
python -m pytest tests/test_classifier_pipeline.py --cov=src --cov-report=htmlExpected OutputCI/CD IntegrationThese tests can be easily integrated into a CI/CD pipeline: # Example GitHub Actions workflow
name: Test Classifier Pipeline
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.11'
- run: pip install -r requirements.txt
- run: pytest tests/test_classifier_pipeline.py -v |
Summary
This PR addresses issue #26 by adding comprehensive tests to verify the accuracy and consistency of the saved classifier pipeline.
Changes
Test Suite ()
Added 20 comprehensive tests organized into 4 test classes:
1. TestArtifactLoading (8 tests)
2. TestPredictionConsistency (3 tests)
3. TestEndToEndPipeline (6 tests)
4. TestErrorHandling (3 tests)
Infrastructure Updates
Test Results
All 20 tests pass successfully:
How to Run Tests
Key Findings
The tests confirm that the saved classifier pipeline:
Closes #26