Skip to content

feat(linear-regression): add fast stub model, improved state handling, tests, and docs#20

Open
aviralgarg05 wants to merge 2 commits intoGDGoC-GLAU:mainfrom
aviralgarg05:feature/fast-tests-linear-regression
Open

feat(linear-regression): add fast stub model, improved state handling, tests, and docs#20
aviralgarg05 wants to merge 2 commits intoGDGoC-GLAU:mainfrom
aviralgarg05:feature/fast-tests-linear-regression

Conversation

@aviralgarg05
Copy link
Copy Markdown

📥 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

  • Bug fix
  • New feature
  • Documentation update
  • Other (please describe):

Checklist

  • My code follows the project style guidelines
  • I have tested my changes
  • I have updated documentation if needed
  • This PR is ready for review 🚀

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add API Endpoint to Access Models

2 participants