Skip to content

feat(yield): replace hardcoded multipliers with XGBoost regression model#722

Open
parinaB wants to merge 2 commits into
neeru24:mainfrom
parinaB:main
Open

feat(yield): replace hardcoded multipliers with XGBoost regression model#722
parinaB wants to merge 2 commits into
neeru24:mainfrom
parinaB:main

Conversation

@parinaB

@parinaB parinaB commented Jun 8, 2026

Copy link
Copy Markdown

What does this PR do?

Replaces hardcoded yield multipliers in services/yield_service.py with a trained XGBoost regression model that learns yield relationships from growth stage, disease severity, weather conditions, and field size making predictions dynamic and realistic instead of static.

Related Issue

Closes #708

Changes made

  • Added training/train_yield_model.py -->generates 3000 synthetic samples per crop using ICAR domain ranges, trains crop-specific XGBoost regressors with 5-fold cross-validation, saves models to ai_models/
  • Added training/yield_model_config.json --> centralised domain config (base yields, disease severities, weather thresholds) sourced from ICAR-CICR data
  • Updated services/yield_service.py --> loads trained model at inference time, builds feature vector with 3 interaction features (disease_impact, temp_humidity_stress, stage_health_interact), gracefully falls back to rule-based estimation if model file is missing
  • Updated app.py --> passes crop_type from request into analyze_image() and estimate_yield() for all routes (/analyze, /api/analyze, /demo)
  • Added test_yield.py --> validates XGBoost path, tomato/potato inference, and legacy fallback behaviour

Model Performance

Crop | CV MAE | CV R² | Samples -- | -- | -- | -- Cotton | 34.64 kg/acre | 0.89 | 3000 Tomato | 669.81 kg/acre | 0.78 | 3000 Potato | 462.21 kg/acre | 0.88 | 3000

SCREEENSHOT

Screenshot 2026-06-09 at 2 58 57 AM

Checklist

  • I have tested my changes
  • My code follows project guidelines
  • No new errors introduced

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for creating a PR for your Issue! ☺️

We'll review it as soon as possible.
In the meantime, please double-check the file changes and ensure that all commits are accurate.

If there are any unresolved review comments, feel free to resolve them. 🙌🏼

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.

[Feature/ML]: Replace Rule-based Yield Multipliers with a Trained ML Regression Model

1 participant