2.5 KiB
2.5 KiB
Story 4.2: Exécution du Modèle (Backend)
Status: review
Story
As a system, I want to execute the statistical model computation, so that I can provide accurate regression results.
Acceptance Criteria
- Algorithm Support: Backend supports Ordinary Least Squares (OLS) for Linear and Logit for Logistic regression.
- Analysis Endpoint: A POST endpoint
/api/v1/analysis/run-regressionaccepts data, X features, Y target, and model type. - Comprehensive Metrics: Returns R-squared, Adjusted R-squared, coefficients, standard errors, p-values, and residuals.
- Validation: Handles singular matrices or perfect collinearity without crashing (returns 400 with explanation).
- Clean Data Source: Respects user row exclusions during calculation.
Tasks / Subtasks
- Dependency Update (AC: 1)
- Add
statsmodelsto the backend usinguv.
- Add
- Regression Engine (AC: 1, 3, 4)
- Implement
run_linear_regression(df, x_cols, y_col)inbackend/app/core/engine/stats.py. - Implement
run_logistic_regression(df, x_cols, y_col)inbackend/app/core/engine/stats.py.
- Implement
- API Endpoint (AC: 2, 5)
- Implement
POST /api/v1/analysis/run-regressioninanalysis.py.
- Implement
Dev Notes
- Statistics: Using
statsmodels.apifor high-quality, research-grade regression summaries. - Robustness: Added intercept (constant) automatically to models. Implemented basic median-splitting for Logistic target encoding if not strictly binary.
- Validation: Integrated try/except blocks to catch linear algebra errors (e.g. non-invertible matrices) and return meaningful error messages.
Project Structure Notes
- Modified
backend/app/core/engine/stats.py. - Updated
backend/app/api/v1/analysis.pywith the execution endpoint. - Added regression test case in
backend/tests/test_analysis.py.
References
- [Source: epics.md#Story 4.2]
- [Source: architecture.md#Computational Workers]
Dev Agent Record
Agent Model Used
{{agent_model_name_version}}
Completion Notes List
- Integrated
statsmodelsfor advanced statistical modeling. - Developed a unified regression engine supporting Linear and Logistic models.
- Implemented
/api/v1/analysis/run-regressionendpoint returning detailed metrics and residuals for plotting. - Verified with automated tests for both model types.
File List
- /backend/app/core/engine/stats.py
- /backend/app/api/v1/analysis.py
- /backend/tests/test_analysis.py
- /backend/pyproject.toml
- /backend/uv.lock