Role: Solo Builder : end-to-end architecture, ML pipeline, XAI integration, full-stack deployment

Indian farmers lose billions every year growing the wrong crop in the wrong soil, not because they're careless, but because traditional knowledge can't account for real-time soil chemistry and live weather patterns. AgriVerse is a deployed, full-stack explainable AI system that takes a farmer's soil parameters (N, P, K, pH) and live location, fetches real-time weather data, and recommends the top 3 crops with probability scores, SHAP-based explanations, counterfactual alternatives, and a trust score. Built on XGBoost with 99.80% classification accuracy across 22 crop types.
India produces more mangoes than any other country on Earth, yet crop failures from poor planning cost the agricultural sector billions every year. The core problem isn't lack of technology. It's that existing ML crop recommendation systems are black boxes: they tell a farmer "grow rice" but offer no explanation, no alternative, and no guidance on what to do if rice isn't viable. Farmers without formal technical training have no reason to trust a system they can't understand. AgriVerse was built to fix exactly this, a system that doesn't just predict, but explains, justifies, and guides.
The Problem Worth Solving
Most crop recommendation systems are technically impressive and practically useless for the people they're meant to serve. A Random Forest model that says "grow chickpea" with 94% accuracy is worthless to a farmer who doesn't know why chickpea, what happens if the soil pH is slightly off, or what to grow instead if chickpea isn't viable this season. AgriVerse was built from the ground up around one principle: transparency is not optional in systems that affect people's livelihoods.
How It Works
A farmer opens AgriVerse, enters their soil's Nitrogen (N), Phosphorus (P), Potassium (K), and pH values, the four parameters available from any basic soil test. They share their location. The system does the rest.
Open-Meteo API fetches live temperature, humidity, and rainfall for that exact location. All seven variables are passed to an XGBoost classifier trained on 2,200 labelled instances covering 22 crop types. The model returns probability scores for all 22 crops simultaneously, and the top 3 are surfaced to the user.
That's where most systems stop. AgriVerse is just getting started.
The Explainability Layer
Every recommendation is accompanied by a SHAP (SHapley Additive exPlanations) waterfall chart showing exactly which soil and weather variables pushed the model toward or away from each crop. This isn't decorative, it's mathematically grounded in cooperative game theory, giving each feature its fair attribution of the prediction.
The system generates two tiers of explainability:
Local (Per-Crop): For each of the top 3 recommendations, a dedicated SHAP bar chart shows why that specific crop was chosen for this specific farm. A farmer can see, for example, that high rainfall strongly supports a rice recommendation while the soil's potassium level is slightly working against it.
Global (Model-Wide): A precomputed global feature importance chart shows which variables matter most across the entire model, useful for agricultural researchers and extension workers understanding systemic patterns.
The Trust Score
Not all recommendations are equally confident. AgriVerse introduces a Trust Score — derived from the probability margin between the top crop and its competitors, penalised dynamically if any input data is missing or if the weather API fails. The output is mapped to High, Medium, or Low confidence with a percentage, so farmers and advisors know exactly how much weight to give the recommendation.
The Counterfactual Engine
This is the feature that makes AgriVerse genuinely different. If the top recommended crop isn't viable, wrong market, wrong season, wrong logistics, the counterfactual engine finds the next-best crop that could become viable with minimal soil adjustments.
It does this by computing Euclidean distance between the user's current N, P, K, pH profile and the centroid profiles of all other crop categories in the training data. Weather variables (temperature, rainfall, humidity) are deliberately excluded, a farmer can't change the weather. Only soil-amendable variables count. The result: a concrete, actionable suggestion like "Rice can also be grown, decrease Phosphorus from 50 to 47.58 and decrease Potassium from 43 to 39.87."
That's not a prediction. That's a farming plan.
The AI-Generated Narrative Report
Every crop recommendation includes a plain-language AI report that translates the SHAP analysis into readable guidance. It identifies the top contributing factors supporting the crop, the hindering factors limiting it, and prescriptive recommendations comparing current soil values to optimal agronomic ranges. When data is incomplete, the system flags assumptions explicitly.
Architecture
The system is a modular full-stack application. A ReactJS frontend handles user input and dynamic visualisation via Chart.js. An Express.js backend acts as the API gateway, orchestrating calls to a Python ML pipeline via shell execution. The Python layer handles XGBoost inference, SHAP computation, trust scoring, and counterfactual analysis, returning a structured JSON payload with four tiers: predictive, interpretative, actionable, and narrative.
The decoupled architecture means the ML model can be updated independently without touching the API or frontend, important for a system intended to improve over time.
Results
XGBoost classifier trained on 2,200 instances, 22 crop classes, 7 features. 5-fold cross-validation with grid search hyperparameter tuning.
Overall accuracy: 99.80% 18 of 22 crop classes: Perfect precision, recall, and F1 score of 1.00 Remaining 4 classes: F1 scores of 0.98–0.99
A novel dropout simulation strategy was used during training, randomly masking input features to simulate incomplete real-world data (missing soil tests, sensor failures). This makes the model robust to partial inputs, a critical requirement for smallholder agriculture in India where complete soil data is often unavailable.
Deployed production system serving real crop recommendations for Indian farmers, 99.80% accuracy across 22 crops, with explainability that tells you not just what to grow but why and how to adjust your soil to grow something better.