feat(linear-regression): add fast stub model, improved state handling, tests, and docs#20
Open
aviralgarg05 wants to merge 2 commits intoGDGoC-GLAU:mainfrom
Open
Conversation
…ocs\n\nAdds USE_STUB_LINEAR env-guarded lightweight LinearRegression stub to avoid 38s sklearn cold import during tests.\n\nKey changes:\n- api.py: stub model + env guard, improved HTTPException re-raise, deterministic coef logic, state reset helper retained.\n- tests/test_api.py: added error tests (predict-before-training, mismatched lengths) with explicit state resets; supports fast runs via USE_STUB_LINEAR=1.\n- README.md: startup latency note, error response docs, testing instructions.\n- requirements.txt: (unchanged runtime deps, kept for completeness).\n- Added Codacy config directory and adjusted .gitignore.\n\nBehavioral notes:\n- Production behavior unchanged when USE_STUB_LINEAR not set.\n- Error cases now reliably return 400 (dimension mismatch & predict-before-training).\n- All tests pass with and without stub (stub drastically reduces CI runtime).\n\nCloses: improves developer experience & test speed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📥 Pull Request for Hacktoberfest 2025
Description
Please include a summary of the change and which issue is fixed.
Introduces a fast test/stub pathway for the linear regression workflow, improves application state management, expands test coverage (including negative/error cases), and updates documentation for clarity on startup latency and usage.
Key Changes
Refactor: Replace module-level global model with app.state storage
Performance: Add USE_STUB_LINEAR env flag and lightweight in-memory regression stub (no sklearn import in fast mode)
Lazy Import: Only import scikit-learn when real model needed
Error Handling: Preserve 400 responses (re-raise HTTPException) and add length validation before training
Tests: Added 5 total tests (health, train+predict, train-and-predict, predict-before-training, mismatched-length) with explicit state reset helper
Docs: README updated (endpoints, error responses, startup note, testing instructions)
Quality: Added Codacy config; all tests green locally in both stub and real modes
DX: Faster CI/local cycles using stub path
Fixes #13
Type of Change
Checklist