betaFeedback

WorksComputer Science

Crop Yield Prediction for Punjab, Pakistan: A Tree-Ensemble and Leaf-Health Prototype, and What Random Validation Hides

Abstract

Yield forecasts help planners and farmers decide on inputs, storage and imports, but small agricultural tables can make reported accuracy fail on a new season. We built a crop-yield prototype for Punjab, Pakistan that combines Random Forest, XGBoost, support vector regression and a Ridge-stacked ensemble with a MobileNetV2 leaf-health classifier, and deployed it as a web application with SHAP explanations. A random 80/20 split of a merged Kaggle-derived table (414 rows) gives the ensemble an R2 of 0.991. An audit showed that the table contains only 46 independent observations: a join with nine temperature records per year copied every crop-year nine times. Holding out whole years takes XGBoost on the same rows from R2 = 0.994 to -0.20. On deduplicated data, and on a longer FAOSTAT table (1990-2024, 70 observations), a per-crop linear trend (leave-one-year-out RMSE 0.29 Ton/Ha) beats every model not given the year (0.84-1.06). Neither pesticide use nor national temperature change explains the trend residuals. An apparent pesticide gain in the Kaggle table disappears on FAOSTAT, where the pesticide series is mostly imputed and the two releases disagree. An independent district-level wheat panel (36 districts, 13 seasons) shows that most variation in Punjab is spatial and that a district mean with a common trend matches the learned models. The leaf classifier reaches 99.87% accuracy on held-out PlantVillage images and recalls 96.4% of 336 unseen diseased leaves after near-duplicates were removed. However, no leaf image is paired with a yield record, so the health score used in the yield models had to be constructed and adds nothing. We report these negative findings together with the prototype.

Introduction

Agriculture contributed about 24% of Pakistan’s GDP and 37.4% of its employment in 2023–24 [12], and Punjab is one of its main wheat- and maize-growing regions. A farmer deciding how much fertiliser to buy, or a planner deciding how much grain to import, would like an estimate of the coming yield. Machine learning is a natural tool for this, and the literature on it is large. [citep?] [37], with random forests [20] and deep networks [23] among the methods applied. Much of it, though, is evaluated on tables small enough that a careless split can make a weak model look excellent, a failure that is well documented in data mining generally [22].

This paper started as a coursework project with a conventional goal: predict wheat and maize yield in Punjab from climate, pesticide and soil variables, compare several regressors, and wrap the best one in a web application. We later added a computer vision module that reads a leaf photograph and returns a health score, with the idea that visible disease should say something about yield. The first version of our results looked very good. A stacking ensemble scored R2=0.991R^2 = 0.991 on a held-out test set. We were pleased, and then we looked at the data more carefully.

What we found changes how those numbers should be read, and it is the main reason we are writing this up. The 414-row table that all our models were trained on contains 46 distinct yield values, each repeated nine times. The repetition is an artefact of how a temperature file was joined, not of anything that happens in a field. A random split puts copies of the same crop-year on both sides of the train/test boundary, and the model is rewarded for remembering them. Once we evaluated by whole years, the picture was very different, and a one-line linear trend turned out to be the strongest model we had.

We think this is worth reporting for two reasons. First, the same mistake is easy to make with other public agricultural tables, and the cost of making it is a headline number that means little. Second, the prototype itself, including the leaf classifier and the explanation interface, is a reasonable starting point for people working on similar problems in Pakistan, provided its limits are stated plainly. Our contributions are:

  • A data audit of a public Kaggle-derived crop table, showing that 414 rows correspond to 46 independent observations and that the national pesticide series is an exact straight line in time from 2001 to 2013, with a reproducible deduplication step.

  • A comparison of Random Forest, XGBoost, SVR, a stacking ensemble and simple baselines under three validation protocols (random, leave-one-year-out and forward chaining), with bootstrap confidence intervals over years, and a test of whether weather and input variables explain what a linear trend misses.

  • An independent check on a district-level wheat panel for Punjab (36 districts, 13 seasons), which shows how much of the variation is spatial and how much a season-wide shock could add.

  • A replication on a longer national table that we rebuilt from FAOSTAT (1990–2024, 70 observations), in which the pesticide series, the one feature that seemed to help, turns out to be largely imputed.

  • A MobileNetV2 leaf-health classifier (99.87% accuracy on 772 held-out PlantVillage images, 96.4% recall on 336 unseen diseased leaves after removing near-duplicates of its training images) and a deployed Gradio prototype with SHAP explanations.

  • A frank account of an integration that did not work: the image-derived feature has to be constructed when no paired data exist, and it adds nothing. We list what data would be needed to test the idea properly.

Related Work

Yield prediction with machine learning. A systematic review of the area [37] found that temperature, rainfall and soil type are the most common inputs and that deep learning models are widely used alongside classical learners. Statistical yield models are usually built on weather variables, and temperature effects in particular are strongly nonlinear [24, 33]. We use three widely used learners: Random Forest [6], gradient-boosted trees as implemented in XGBoost [8], and support vector regression [10]. We combine them by stacked generalisation [39] with a Ridge meta-learner [16].

Plant disease from images. Image-based disease recognition has been studied extensively on the PlantVillage collection [17, 27], where deep networks reach very high accuracy on leaves photographed against plain backgrounds. Such accuracy is known to be fragile: models can exploit background cues instead of symptoms [14], and the variety of the training images matters as much as their number [4]. We use MobileNetV2 [32], chosen because it is small enough to run on a free hosting tier.

Validation with dependent data. It has long been known that standard cross-validation assumes exchangeable samples and can give misleading estimates when data have temporal, spatial or hierarchical dependence [31], and that evaluating forecasting models needs its own care [5, 36]. A comprehensive survey of cross-validation procedures is given by Arlot and Celisse [3]. In the forecasting literature, simple benchmark methods are repeatedly found hard to beat by more complex ones [26], which motivates the baselines we use. Leakage of this kind is a recognised source of over-optimistic results across many fields [21, 22]. What we add here is a concrete and small example, from a public table, of how a join can create the leak without anyone intending it.

Data

We used four public datasets. Table 1 summarises them; Figure 3 shows how they are processed.

DatasetSizeContent used
Crop Yield Prediction [29]28,242 rows (1,449 for Pakistan)FAO yields (hg/ha), pesticide use (tonnes), national mean temperature, 1990–2013
District-level crop data, Punjab (Kaggle)2,200 rows, 13 cropsSoil N, P, K, soil temperature, humidity, pH, rainfall
Wheat statistics, Punjab (Kaggle)12 yearsArea, production, yield (trend plots only)
District wheat yields, Punjab [28]36 districts × 13 seasonsWheat yield (kg/ha), 2007–08 to 2019–20 (independent check)
FAOSTAT, re-downloaded [13]35 years × 2 cropsOfficial yields, pesticide use, temperature change, 1990–2024 (replication)
PlantVillage [1, 17]3,852 maize imagesHealthy, common rust, northern leaf blight, gray leaf spot
Corn or Maize Leaf Disease [35]4,188 imagesCandidate images for the unseen-image test

Table 1. Datasets used. The first two feed the national yield models; the FAOSTAT table and the district panel are used for the replications in § 5.5 and § 5.6; the corn dataset is used only to test the classifier on unseen images; the wheat statistics were used for exploratory plots.

Data pipeline

Figure 3. Data pipeline. Blue: raw sources; green: cleaning, join and audit steps; orange: modelling inputs and evaluation; purple: stage headers. The 414-row table produced by the join trains the deployed models; the 46-row table produced by the audit is used for the honest-protocol evaluation of the Kaggle-derived data. The FAOSTAT table and the district wheat panel (middle rows) are used for replication, and the lower lane trains the leaf classifier whose score feeds feature set B. The 12-year Punjab wheat statistics were used for exploratory plots only.

Tabular data and the merged table

We kept the Pakistan rows of the yield table (whose yield and pesticide columns, according to the dataset description, come from FAO statistics [13]), converted yield from hg/ha to Ton/Ha (division by 10410^{4}), and averaged the district-level soil and climate values by crop. The two tables share only wheat and maize, so an inner join on crop type left 414 rows covering 1990–2013. There are 23 distinct years, because 2003 is absent. We also derived NPKtotal=N+P+K\mathrm{NPK}_{\mathrm{total}} = N + P + K. The merged table has no missing values.

Two properties of this table matter later. First, the soil variables (N, P, K, soil temperature, humidity, pH) and rainfall (a constant 494 mm) do not vary within a crop, because they come from crop-level averages. They therefore act as a crop indicator and nothing more. Second, pesticide use and temperature are national values that change from year to year but are shared by the two crops.

The pesticide series. Pesticide use is a single national figure per year, shared by both crops. Looking at it over time (Figure 1d), we noticed that from 2001 to 2013 the values fall by the same 989.2 tonnes every year, from 11,871 tonnes to under one tonne, and then stay constant at 0.92 tonnes in the later years of the source file. The same straight line appears in the original pesticide file before any merging. Real application figures do not usually behave like this; the values look interpolated or imputed, although we could not trace this in the source documentation. The consequence is that for 13 of the 23 years the pesticide column is simply a linear function of the year, and, as § 5.3 and § 5.4 show, models use it as one. § 3.4 shows that the current FAOSTAT release gives a different series, which is mostly imputed.

Figure 1. Data audit. (a) Every crop-year appears nine times with a single yield. (b) The nine temperature readings per year (light dots) vary much more within a year than the yearly mean (line) varies across years; shown for wheat. (c) Yield by crop and year. Both series rise steadily and correlate with year at r=0.95r = 0.95 (maize) and r=0.96r = 0.96 (wheat). (d) The national pesticide series: from 2001 it is an exact straight line, falling by 989.2 tonnes per year to under one tonne.

The nine-fold replication

Each Pakistan crop-year appears exactly nine times in the merged table, always with the same yield and the same pesticide figure, but with different temperatures (Figure 1a,Figure 1b). The cause is the temperature source file, which holds nine readings for each Pakistan year. Their provenance is not documented in the files we used (they could be station-level or regional values), and their spread within a year (mean standard deviation 2.5 ∘C2.5\,^\circ\mathrm{C}) is five times larger than the spread of the yearly means (0.5 ∘C0.5\,^\circ\mathrm{C}). A join on country and year therefore multiplied every crop-year row by nine. The 414 rows are 2×23×92 \times23 \times9; the independent information is in 46 rows, each with one yield.

We kept the 414-row table for the deployed models, so that the prototype matches our original submission. For every honest evaluation in this paper we collapse the replicates into one row per crop-year, taking the mean temperature. We call this the crop-year table. It is released with the code.

District-level wheat panel

To test our conclusions on data with real spatial variation, we added a second, independent source: wheat yields per hectare by district for Punjab, from 2007–08 to 2019–20, published by the Pakistan Bureau of Statistics and redistributed through the Open Data Pakistan portal [28]. We removed the province and division summary rows and the row for Islamabad, which lies outside Punjab. Chiniot has no values for the first two seasons (the district was created later) and was kept for the remaining eleven. Two cells were removed as implausible: Kasur in 2009–10 (8.9 Ton/Ha) and Lahore in the same season (0.78 Ton/Ha), whose values differ from the reported figure for their division (2.61 Ton/Ha) by a factor of three or more; both look like transcription errors, and no other cell deviates from its division by more than 60%. The resulting panel has 464 observations from 36 districts and 13 seasons. Seasons are labelled by harvest year. As a consistency check of the earlier national table, the province-level row of this file correlates at r=0.99r = 0.99 with the national FAO wheat yields in our table for the six overlapping harvest years (2008–2013). The portal lists no licence for the file, so we ship the cleaning code and not the raw data (see Data and Code Availability). This panel contains yields only; it has no weather variables.

FAOSTAT table, 1990–2024

To check our conclusions on data that we could trace to its source, we re-downloaded Pakistan’s wheat and maize yields, national pesticide use and national temperature change from FAOSTAT [13] and built a table for 1990–2024: 35 years and two crops, 70 crop-year observations, with no gap in 2003. The 46 crop-years that overlap with the Kaggle-derived table have identical yields (the largest difference is below 10−1510^{-15} Ton/Ha), so the yield column of that table is a faithful copy of FAO figures. All yields are official figures except maize in 2024, which FAOSTAT flags as a figure from an international organisation. Temperature enters as the annual national temperature change in ∘C\mathord{^\circ}\mathrm{C} (meteorological year); the yearly mean temperature in the Kaggle table correlates with it at r=0.92r = 0.92 over the 23 overlapping years, so the two describe the same signal at national scale.

Pesticide use is a different matter (Figure 2). The current FAOSTAT series takes only four distinct values: 16,479 t in 1990–1997, 17,619 t in 1998, 19,470 t in 1999 and 26,702 t from 2000 to 2024. FAOSTAT’s own flags mark 27 of the 35 values as imputed, three (2022–2024) as estimated and only five (1997–2000 and 2013) as official. This series does not resemble the one in the Kaggle table (correlation −0.25 over the overlapping years): there the values start at 5,299 t in 1990, peak in 2000 and then fall in a straight line to 0.92 t in 2013. We did not establish whether the two come from different FAO releases. Either way, neither looks like measured annual pesticide use.

FAOSTAT table showing yields, pesticide use, and temperature change

Figure 2. The FAOSTAT table. Left: yields of maize and wheat, 1990–2024. Middle: national pesticide use with FAOSTAT’s flag for each year (A official, E estimated, I imputed); the series is flat except for 1997–2000. Right: annual national temperature change (the panel shows the full series from 1961).

Leaf images

From PlantVillage we used the four maize folders. The three disease classes (common rust, northern leaf blight, gray leaf spot) were merged into one diseased label, giving a binary problem with 2,690 diseased and 1,162 healthy images. Wheat leaf classes are not part of PlantVillage, so the image module covers maize only.

Methodology

Preprocessing pipeline

Figure 3 summarises the full pipeline. The tabular lane (blue) goes from the raw yield file through the Pakistan filter, the district-level aggregation, the join and the audit to the three feature sets described below. The image lane (orange) trains the leaf classifier and produces the score that feeds feature set B. The two teal lanes show the FAOSTAT table and the district wheat panel that we use for replication. The only scaling step is a standardisation inside the SVR and Ridge pipelines; tree models receive raw values. All random seeds are fixed at 42.

Feature sets

We use three feature sets throughout.

A Nine tabular features: pesticide use, mean temperature, N, P, K, soil temperature, humidity, pH and NPK_total. This is the set used by the deployed models.

B Set A plus health_score, the output of the leaf classifier (§ 4.5).

C Set A plus calendar year. Year is known in advance, so it is a legitimate input for forecasting; we add it as a separate set to see what the models do when given the one variable that tracks the trend.

An earlier 13-feature version also contained year, rainfall, a temperature–rainfall product and a crop code. We dropped rainfall (constant), the product and the crop code for being redundant, and year because we wanted the models to rely on weather, input and soil information. As § 5 shows, that choice turned out to matter a great deal.

Regression models

Let xi\mathbf{x}_i be the features of crop-year ii and yiy_i its yield in Ton/Ha. We fit five regressors.

Baselines. The crop mean predicts the training mean yield of the crop. The crop linear trend fits y=ac+bcty = a_c + b_c t separately for each crop cc by ordinary least squares on year tt. Both use no weather or soil information.

Ridge regression. A linear model with penalty λ∥β∥2\lambda\lVert\boldsymbol{\beta}\rVert^2, λ=1\lambda= 1, on standardised inputs. All learners are implemented in scikit-learn [30] or XGBoost [8].

Random Forest with 200 trees and maximum depth 8, XGBoost with 200 trees, learning rate 0.05 and maximum depth 5, and SVR with an RBF kernel (C=100C = 100, γ=0.1\gamma= 0.1, ϵ=0.1\epsilon= 0.1) on standardised inputs. These settings were chosen once, early in the project, and were not tuned; we use the same settings under every protocol. (The earlier 13-feature experiments used depth 10 and 6 for the two tree models.)

Stacking ensemble. The three learners above are first-level models. A Ridge regression (λ=1\lambda= 1) is the second-level model and is fitted on out-of-fold predictions from five-fold cross-validation:

y^(x)=β0+∑k∈{RF,XGB,SVR}βkf~k(x),β=arg min⁡β∑i(yi−β0−∑kβkf~k(xi))2+λ∥β∥2(1)\hat{y}(\mathbf{x}) = \beta_0 + \sum_{k \in\{\mathrm{RF},\mathrm{XGB},\mathrm{SVR}\}} \beta_k \tilde{f}_k(\mathbf{x}), \qquad\boldsymbol{\beta} = \operatorname*{arg\,min}_{\boldsymbol{\beta}} \sum_i \left(y_i - \beta_0 - \sum_k \beta_k \tilde{f}_k(\mathbf{x}_i)\right)^2 + \lambda\lVert\boldsymbol{\beta}\rVert^2 \tag*{(1)}

where f~k\tilde{f}_k denotes the out-of-fold prediction. In the deployed model trained on 414 rows, the learned weights were βXGB=0.967\beta_{\mathrm{XGB}} = 0.967, βRF=0.070\beta_{\mathrm{RF}} = 0.070 and βSVR=−0.027\beta_{\mathrm{SVR}} = -0.027, with an intercept of −0.021-0.021. The ensemble is therefore close to XGBoost alone.

Leaf-health classifier

The classifier (Figure 4) is a MobileNetV2 [32] pretrained on ImageNet, with its convolutional backbone frozen. On top we train a small head: global average pooling, a dense layer of 128 ReLU units, dropout with rate 0.3, and one sigmoid unit that outputs P(healthy)P(\mathrm{healthy}). Of 2,422,081 parameters, 164,097 are trainable. Images are resized to 224×224224 \times224 and scaled to [0,1][0, 1]. Each class folder was split 80/20 with a fixed seed, giving 3,080 training and 772 validation images (539 diseased, 233 healthy). Training images were augmented with rotations up to 20∘20^\circ, zoom up to 20%, horizontal flips and brightness changes between 0.8 and 1.2. We minimised binary cross-entropy with Adam, monitored validation accuracy, stopped after three epochs without improvement, and kept the best weights. Training ended after five epochs. A cut-off of 0.5 turns the probability into a label.

Architecture of the leaf-health classifier

Figure 4. Architecture of the leaf-health classifier. Only the dense head is trained; the pretrained backbone is kept frozen.

Integrating the leaf score into the yield models

At inference time the integration is straightforward: the uploaded photograph is scored by the classifier and the probability becomes health_score; if no photograph is uploaded, a neutral value of 0.5 is used. At training time there is a difficulty. Our yield records are national, annual figures and carry no leaf images. To give the yield models something to learn from, we built a score for each training row. Let sh=0.9921s_h = 0.9921 and sd=0.0007s_d = 0.0007 be the classifier’s mean predicted probabilities on validation leaves of the healthy and diseased classes. For row ii we set

health_scorei=sd+NPK_totali−min⁡jNPK_totaljmax⁡jNPK_totalj−min⁡jNPK_totalj(sh−sd).(2)\mathrm{health\_score}_i = s_d + \frac{\mathrm{NPK\_total}_i - \min_j \mathrm{NPK\_total}_j}{\max_j \mathrm{NPK\_total}_j - \min_j \mathrm{NPK\_total}_j}(s_h - s_d). \tag*{(2)}

This is a rescaled copy of an existing feature. Because NPK_total is constant within a crop (159.63 for wheat, 160.25 for maize), the score takes only two values, 0.0007 for wheat rows and 0.9921 for maize rows. Wheat is scored near zero only because its nutrient total happens to be slightly lower; no wheat image was involved, and the value does not mean that wheat is unhealthy. We disclose this construction in full because it limits what the integration can show. We test its effect in § 5.7.

Evaluation of the classifier on unseen images

The PlantVillage validation set comes from the same collection as the training set, so it says little about other image sources. To test on other images we used the Kaggle Corn or Maize Leaf Disease Dataset [35], which according to its description was curated from PlantVillage and PlantDoc [34] and holds 4,188 images in four folders (healthy, blight, common rust, gray leaf spot). Most of those images are PlantVillage images that the classifier was trained on, so we removed every image that is a near-duplicate of a PlantVillage maize image. For each image we computed a 64-bit perceptual hash (the 8×88 \times8 DCT hash of the image resized to 128×128128 \times128) and treated two images as the same picture when their hashes differed in at most six bits. All 3,852 PlantVillage maize images were hashed. Of the 4,188 candidates, 3,852 matched a PlantVillage image exactly (distance 0), and the other 336 were at distance 12 or more, so the split is clean. The matched images have the same class counts as the PlantVillage maize folders (1,162 healthy, 1,192 common rust, 985 blight, 513 gray leaf spot); the 336 others (161 blight, 114 common rust, 61 gray leaf spot) are the images that PlantVillage does not account for. We take them as unseen images. Their source is presumably PlantDoc, but we did not check provenance image by image. All of them are diseased, because the healthy folder consists entirely of PlantVillage images. We therefore report the recall of the diseased class with a Wilson interval, and could not measure the false-alarm rate on healthy leaves. As a contamination control we also evaluated a random sample of 800 of the matched images.

Evaluation protocols

We compare three ways of splitting the data (Figure 5).

Figure 5. The three validation protocols. Each small block is one row (three rows per year are drawn for illustration; 2003 is absent from the data). In a random split, rows of the same crop-year land on both sides; in the other two, a year is either fully held out or lies in the future of the training data.

  • Random 5-fold. Rows are shuffled and split into five folds, repeated five times. This is the conventional protocol and matches how our original results were produced.

  • Leave-one-year-out (LOYO), a blocked form of cross-validation [3, 31]. All rows of one year, both crops, are held out together; 23 folds.

  • Forward chaining. For each test year from 1998 to 2013 the models are trained on all earlier years only (15 test years). This mimics forecasting and is also known as rolling-origin evaluation [18, 36].

Both crops of a year share the same pesticide and temperature values, so holding out only one of them would leave its twin in the training set. For this reason we group by year and not by crop-year.

We report RMSE [19], MAE and R2R^2 computed on the pooled held-out predictions. For LOYO and forward chaining we also give a 95% bootstrap interval for the RMSE, obtained by resampling the held-out years with replacement 2,000 times [11]. With 15–23 years these intervals are wide, and we ask the reader to take them seriously. For the leaf classifier we report accuracy with a Wilson score interval [38].

District-panel evaluation

On the district panel (§ 3.3) we compare six predictors of the yield of district dd in season tt. The district mean is the average yield of that district in the training seasons. The common trend adds a single linear trend in season index, fitted to the training residuals of all districts. Ridge regression, Random Forest and XGBoost use one-hot district indicators and the season index as inputs, with the same settings as before. The oracle season shock adds to the district mean the average deviation of all districts in the held-out season, computed from that season’s own labels. It cannot be used in practice; its purpose is to measure how much a perfect season-wide predictor, for example one built from weather, could add. We evaluate by random 5-fold (three repeats), leave-one-season-out, and forward chaining with test seasons from 2012–13 onward (training on at least five earlier seasons), with bootstrap intervals over test seasons.

Replication on the FAOSTAT table

On the FAOSTAT table (§ 3.4) we repeat the comparison of trend and models with two feature sets: A′A' (pesticide use, temperature change and a crop indicator) and C′C' (A′A' plus year). The soil variables are left out because they are crop-level constants that duplicate the crop indicator. The models, settings, protocols and bootstrap are those of § 4.7 and § 5.4, with 35 leave-one-year-out folds and forward chaining over the 27 test years 1998–2024. The residual models use the same small settings as before (§ 8).

Explainability and deployment

Predictions of the XGBoost model are explained with SHAP [25] (TreeExplainer), displayed as a waterfall plot. The application (Figure 6) is written with Gradio [2], uses scikit-learn [30], XGBoost and Keras [9], and is hosted on Hugging Face Spaces. Users set sliders for pesticide use (0–30,000 t), mean temperature (15–35 °C), N (0–140), P (0–100), K (0–120), soil temperature, humidity (50–100%) and pH (4–9), optionally upload a maize leaf image, and receive the four model predictions, a comparison chart, the leaf label and the SHAP plot.

Overview of the deployed prototype

Figure 6. Overview of the deployed prototype. A user sets climate and soil sliders and may upload a maize leaf photograph. The classifier output enters the yield models as an extra feature (0.5 if no photograph is uploaded). The SHAP plot explains the XGBoost model; the yield estimates come from all four models.

Results

Results as originally obtained

On a random 80/20 split of the 414-row table (seed 42), the deployed models reached the scores in Table 2. The stacking ensemble led with R2=0.9906R^2 = 0.9906 and a mean absolute error of 0.046 Ton/Ha, XGBoost followed closely, and SVR was poor. With the earlier 13-feature set, which included year, Random Forest, XGBoost and the ensemble were essentially perfect (R2≥0.9999R^2 \ge0.9999). Taken at face value, this is an extremely accurate system.

ModelMAERMSETest R2R^25-fold CV R2R^2
Random Forest0.07150.13090.97350.9582
XGBoost0.05090.08270.98940.9922
SVR0.46390.70860.22400.3767
Stacking ensemble0.04620.07800.99060.9923

Table 2. Original evaluation: random 80/20 split of the 414-row table, nine features plus health_score (feature set B). These figures are inflated by the replication discussed in § 3.2.

The same rows under a different split

We re-evaluated the same 414 rows and the same feature set A (no leaf score), changing only how rows are assigned to folds. Table 3 and Figure 7a show that the result depends almost entirely on the protocol. Under random 5-fold, XGBoost reaches R2=0.994R^2 = 0.994. When the nine copies of a year are kept together (LOYO), the same model falls to R2=−0.204R^2 = -0.204, which is worse than predicting the overall mean. Random Forest drops from 0.965 to −0.063-0.063. SVR is the exception: it was poor to begin with and changes less, because its smooth kernel cannot memorise individual crop-years as easily.

ModelRandom 5-fold RMSERandom 5-fold R2R^2Leave-one-year-out RMSELeave-one-year-out R2R^2
Random Forest0.1390.9650.768-0.063
XGBoost0.0600.9940.818-0.204
SVR0.5970.3590.6430.255

Table 3. Same 414 rows, same features (set A), two protocols. Random 5-fold is a single shuffled run.

Figure 7. (a) R2R^2 of three models on the 414-row table under random 5-fold and leave-one-year-out validation. (b) Pooled RMSE on the 46-row crop-year table under leave-one-year-out and forward chaining, with 95% bootstrap intervals over years. “+year” means feature set C.

Honest evaluation on the crop-year table

Table 4 gives results on the 46-row crop-year table for the three protocols; Figure 7b plots the two year-aware ones. Five observations stand out.

A one-line trend beats every model without year. The per-crop linear trend gives an RMSE of 0.243 Ton/Ha under LOYO (interval 0.18–0.30) and 0.317 under forward chaining. Every learned model that uses feature set A lies between 0.59 and 0.74 under LOYO and between 0.70 and 0.96 under forward chaining, and the intervals do not overlap with the trend baseline’s. The crop mean, which uses nothing beyond the crop, scores 0.78 and 0.94. The models built on weather, pesticide and soil features do better than that, but only modestly under LOYO, and under forward chaining every one of them has a negative R2R^2: they forecast worse than a constant equal to the mean of the test years, and the ensemble (0.956) is even slightly worse than the crop mean (0.943). The signal in our table is overwhelmingly a time trend: yield correlates with year at r≈0.95r \approx0.95 in both crops (Figure 1c), which reflects improving varieties, area and practices that none of our features describe.

Giving the models the year changes the picture. With year added (set C), Random Forest reaches an LOYO RMSE of 0.141 (R2=0.964R^2 = 0.964, interval 0.11–0.17), clearly better than the linear trend, and XGBoost reaches 0.207. This is interpolation: a held-out year sits between years the model has seen, and a tree can learn a step-wise trend. Forward chaining is harder because it requires extrapolation, which tree models cannot do, since they predict piecewise-constant values [15]. There the advantage disappears: RF and XGBoost with year give 0.333 and 0.323, against 0.317 for the plain trend, a tie within the intervals (Figure 8). Models without year fail more visibly: the nine-feature XGBoost forecast falls while observed yields rise.

Figure 8. Forward-chaining predictions for each test year (trained on all earlier years). The linear trend and the year-aware random forest follow the rising yields; the nine-feature XGBoost model does not.

Replication, not noise, produced the headline numbers. Under random 5-fold on the crop-year table, XGBoost with set A reaches R2=0.54R^2 = 0.54 rather than 0.994 (Table 4, compared with Table 3). The protocol is the same; the difference is that the nine copies are gone. This isolates the replication as the main source of inflation, ahead of the choice of model.

ModelRandom 5-fold RMSERandom 5-fold R2R^2Leave-one-year-out RMSE [95% CI]Leave-one-year-out R2R^2Forward chaining RMSE [95% CI]Forward chaining R2R^2
Baselines
Crop mean0.779-0.090.777 [0.66, 0.89]-0.090.943 [0.75, 1.11]-0.87
Crop linear trend0.2400.900.243 [0.18, 0.30]0.890.317 [0.22, 0.41]0.79
Feature set A (nine features, no year)
Ridge0.6510.240.654 [0.56, 0.74]0.230.779 [0.62, 0.91]-0.28
Random Forest0.5160.520.593 [0.40, 0.76]0.370.713 [0.50, 0.91]-0.07
XGBoost0.5030.540.651 [0.39, 0.87]0.240.817 [0.49, 1.08]-0.40
SVR0.5860.380.592 [0.41, 0.76]0.370.695 [0.50, 0.86]-0.01
Stacking ensemble0.748-0.010.737 [0.57, 0.88]0.020.956 [0.74, 1.14]-0.92
Feature set C (A + year)
Ridge + year0.4360.660.407 [0.35, 0.46]0.700.507 [0.40, 0.59]0.46
Random Forest + year0.1680.950.141 [0.11, 0.17]0.960.333 [0.20, 0.46]0.77
XGBoost + year0.2110.920.207 [0.12, 0.30]0.920.323 [0.17, 0.46]0.78
SVR + year0.2710.860.303 [0.18, 0.43]0.830.354 [0.24, 0.45]0.74
Stacking ensemble + year0.2720.860.275 [0.19, 0.36]0.860.388 [0.28, 0.50]0.68

Table 4. Performance on the 46-row crop-year table. RMSE in Ton/Ha; for the two year-aware protocols the 95% bootstrap interval over held-out years is shown in brackets. Random 5-fold is the mean of five repeats. Feature set A has no year; set C adds year.

The ensemble is not better than its parts here. The stacking ensemble is the best model in the original evaluation but is worse than RF, XGBoost and SVR individually under the honest protocols (LOYO RMSE 0.737, set A). We have not investigated this fully. Our guess is that with 45 or fewer training rows the inner five-fold cross-validation that produces the second-level training data is itself unstable, but we did not test this.

A caution on interpreting small intervals. The bootstrap intervals are wide, and the number of years is small. We would not rank RF, XGBoost and SVR against one another on these data, and we do not claim that the year-aware forest is better than a trend model for forecasting, only that it is better at interpolation.

Modelling deviations from the trend

Since a straight line per crop is so hard to beat, a natural question is whether weather, soil and input variables explain what the line misses. We tested this with a two-stage model. In every fold, the per-crop trend is fitted on the training years only; a regressor is then trained to predict the training residuals from the non-time features (crop indicator, mean temperature, pesticide use); and the prediction for a held-out year is the trend plus the predicted residual. The regressors were kept small (§ 8) and were chosen once, without tuning. All four residual models match or improve on the trend alone (Table 5). The forest does best: its leave-one-year-out RMSE is 0.159 against 0.243 for the trend, and its forward-chaining RMSE is 0.260 against 0.317.

ModelLeave-one-year-out RMSELeave-one-year-out 95% CILeave-one-year-out R2R^2Forward chaining RMSEForward chaining 95% CIForward chaining R2R^2
Crop linear trend (no residual model)0.243[0.18, 0.30]0.890.317[0.22, 0.41]0.79
Trend + Ridge residual0.224[0.16, 0.28]0.910.306[0.21, 0.41]0.80
Trend + Random Forest residual0.159[0.12, 0.19]0.950.260[0.14, 0.36]0.86
Trend + XGBoost residual0.175[0.12, 0.23]0.940.275[0.18, 0.37]0.84
Trend + SVR residual0.211[0.16, 0.26]0.920.296[0.17, 0.41]0.82

Table 5. Trend plus residual model on the 46-row crop-year table. Residual features: crop indicator, mean temperature and pesticide use.

To see which input produces the improvement, we refitted the forest on subsets of the features and bootstrapped the paired RMSE difference to the trend over years (Table 6). A crop indicator alone reproduces the trend exactly, as it should. Mean temperature adds nothing (gain +0.001 under LOYO, interval −0.034 to 0.027). Pesticide use produces the entire gain, 0.085 Ton/Ha under LOYO (interval 0.048–0.117) and 0.069 under forward chaining (0.038–0.101). Using calendar year instead gives a gain of a similar kind (0.070 and 0.045).

Residual features (RF)Leave-one-year-out RMSELeave-one-year-out gain over trend [95% CI]Forward chaining RMSEForward chaining gain over trend [95% CI]
Crop indicator only0.243+0.000 [-0.001, +0.001]0.316+0.001 [-0.000, +0.002]
+ year (for comparison)0.173+0.070 [+0.044, +0.093]0.274+0.045 [+0.019, +0.074]
+ mean temperature0.243+0.001 [-0.034, +0.027]0.329-0.012 [-0.047, +0.018]
+ pesticide use0.158+0.085 [+0.048, +0.117]0.251+0.069 [+0.038, +0.101]
+ temperature + pesticides0.159+0.084 [+0.050, +0.115]0.260+0.060 [+0.026, +0.096]

Table 6. Which residual features matter (Random Forest residual model). Gain is the reduction in RMSE relative to the trend alone, with a paired bootstrap 95% interval over held-out years.

We do not read this as an effect of pesticides. As described in § 3, in the Kaggle table the pesticide column is an exact straight line in time for 13 of the 23 years, preceded by a peak around 2000. To a forest, such a column is a switch with a few kinks. The comparison with the calendar year supports this reading: a time variable alone recovers a gain of the same order. What the result does tell us is that the deviations from a linear trend are not random in time (maize yields in particular rise in a step between 2002 and 2005, Figure 1c), and that a variable that carries timing information can pick some of it up. Mean temperature, the one genuine weather variable in the table, carries no information about those deviations. The longer FAOSTAT table supports this reading: the gain disappears there (§ 5.5).

Replication on the current FAOSTAT release

The FAOSTAT table has 35 years and 70 observations, so the intervals are narrower than before, and it has no replicated rows. Table 7 gives the results, and the picture of § 5.3 repeats. The per-crop linear trend has a leave-one-year-out RMSE of 0.292 Ton/Ha (interval 0.23–0.35) and a forward-chaining RMSE of 0.339 (0.25–0.43). Every model on feature set A′A' lies between 0.84 and 1.06 under leave-one-year-out and between 0.93 and 1.15 under forward chaining, about three times worse. The crop mean scores 1.24 and 1.39. With the year added, the forest reaches 0.202 under leave-one-year-out (interval 0.15–0.25), XGBoost 0.24 and SVR 0.23, better than the trend when interpolating; Ridge, which cannot follow a non-linear trend, stays at 0.69. Under forward chaining the models with year (0.336, 0.318 and 0.366 for forest, XGBoost and SVR) tie with the trend (0.339).

ModelLeave-one-year-out RMSE [95% CI]R2R^2Forward chaining RMSE [95% CI]R2R^2
Baselines
Crop mean1.235 [1.05, 1.41]0.061.391 [1.15, 1.62]-0.27
Crop linear trend0.292 [0.23, 0.35]0.950.339 [0.25, 0.43]0.92
Feature set A′A' (pesticide use, temperature change, crop)
Ridge0.979 [0.80, 1.15]0.411.117 [0.92, 1.32]0.18
Random Forest0.909 [0.62, 1.19]0.490.992 [0.74, 1.25]0.35
XGBoost1.061 [0.76, 1.34]0.301.152 [0.87, 1.43]0.13
SVR0.843 [0.64, 1.03]0.560.931 [0.73, 1.13]0.43
Feature set C′C' (A′A' + year)
Ridge + year0.692 [0.58, 0.80]0.700.790 [0.64, 0.93]0.59
Random Forest + year0.202 [0.15, 0.25]0.970.336 [0.25, 0.42]0.93
XGBoost + year0.237 [0.17, 0.29]0.970.318 [0.22, 0.40]0.93
SVR + year0.228 [0.17, 0.29]0.970.366 [0.28, 0.44]0.91
Trend plus residual model (features A′A')
Trend + Ridge0.290 [0.22, 0.35]0.950.354 [0.27, 0.44]0.92
Trend + Random Forest0.290 [0.22, 0.36]0.950.372 [0.28, 0.46]0.91
Trend + XGBoost0.296 [0.23, 0.36]0.950.379 [0.28, 0.47]0.91
Trend + SVR0.282 [0.22, 0.35]0.950.382 [0.28, 0.48]0.90

Table 7. Replication on the FAOSTAT table, 70 crop-year observations, 1990–2024. RMSE in Ton/Ha with bootstrap intervals over test years (35 for leave-one-year-out, 27 for forward chaining).

The two-stage models, which learn what the trend misses, end differently here than on the Kaggle table (Table 8). Residual models built on pesticide use and temperature change give no improvement: their leave-one-year-out RMSE is 0.282–0.296 against 0.292 for the trend alone, and under forward chaining they are worse (0.354–0.382 against 0.339). In the ablation, temperature change has a gain of −0.006 (interval −0.033 to 0.022) under leave-one-year-out and −0.033 (−0.059 to −0.010) under forward chaining; pesticide use gives +0.021 (−0.014 to 0.058) and −0.024 (−0.033 to −0.016). The only residual feature that helps is the year itself (+0.071 and +0.049, both intervals above zero): the trend is not a straight line, as the step-like rise of maize in Figure 2 shows, and a time variable can describe that.

Residual features (Random Forest)Leave-one-year-out gain [95% CI]Forward chaining gain [95% CI]
Crop indicator only-0.000 [-0.001, -0.000]+0.000 [-0.000, +0.001]
+ year+0.071 [+0.044, +0.097]+0.049 [+0.031, +0.068]
+ temperature change-0.006 [-0.033, +0.022]-0.033 [-0.059, -0.010]
+ pesticide use+0.021 [-0.014, +0.058]-0.024 [-0.033, -0.016]
+ temperature change + pesticide use+0.002 [-0.029, +0.033]-0.033 [-0.058, -0.013]

Table 8. Which residual features help on the FAOSTAT table (Random Forest residual model). Gain is the reduction in RMSE relative to the linear trend, with a paired bootstrap 95% interval over test years.

This is the result the Kaggle table could not give us. There, pesticide use appeared to explain 0.085 Ton/Ha of the trend’s error (§ 5.4). On the longer table, where the pesticide series is nearly constant, the gain is gone. We take this as evidence that the earlier gain came from the shape of an interpolated series and not from pesticide use. National temperature change, a documented weather variable, adds nothing either. That is not proof that weather is irrelevant, since an annual national anomaly is a crude summary of growing-season conditions in one province (see Limitations).

Independent check on district-level wheat

The district panel behaves very differently from the national table. Variation is mostly between places: district identity alone explains 85.4% of the variance of yield, season alone 6.7%, and the two together 91.5%. Season-wide shocks are therefore small compared with the gap between, say, Okara and Chakwal (Figure 9a).

Figure 9. District-level wheat panel, Punjab. (a) Yield of each district (thin lines) and the mean over districts (thick line). (b) RMSE of six predictors under three validation protocols; the oracle season shock uses test labels and is an upper bound.

Table 9 gives the results. Two things stand out. First, the inflation seen in the national table does not appear here: random 5-fold and leave-one-season-out give almost the same RMSE for every model (for example 0.263 and 0.261 for the district mean, and 0.334 and 0.340 for the forest). This is what one would expect when the rows are genuinely distinct observations and the season shock is small, and it supports our reading that the national table’s inflation came from the nine-fold replication and not from temporal structure alone. Second, simple structure is hard to beat. The district mean with a common trend (RMSE 0.231 under leave-one-season-out) is as good as Ridge (0.234), and better than XGBoost (0.258) and the forest (0.340); under forward chaining the ordering is the same. The forest, which cannot extrapolate along the season index, is the worst.

Table 9: District-level wheat panel (464 observations). RMSE in Ton/Ha. The oracle uses the held-out season’s own labels and is not a usable model. Bootstrap intervals are over test seasons.

ModelRandom 5-fold RMSELeave-one-season-out RMSE [95% CI]Leave-one-season-out R2R^2Forward chaining RMSE [95% CI]
District mean0.2630.261 [0.21, 0.31]0.830.279 [0.23, 0.33]
District mean + common linear trend0.2280.231 [0.21, 0.25]0.870.246 [0.20, 0.29]
Ridge (district dummies + season index)0.2320.234 [0.21, 0.26]0.860.255 [0.21, 0.29]
Random Forest (district + season index)0.3340.340 [0.31, 0.37]0.710.334 [0.29, 0.38]
XGBoost (district + season index)0.2400.258 [0.22, 0.29]0.830.264 [0.21, 0.32]
Oracle season shock (uses test labels)–0.199 [0.18, 0.22]0.900.216 [0.18, 0.25]

Table 9.

The oracle row shows the room that remains. If the season-wide shock were known exactly, the RMSE of the district mean would fall from 0.261 to 0.199 Ton/Ha under leave-one-season-out (and from 0.279 to 0.216 under forward chaining). A model that could predict that shock from weather therefore has a ceiling of roughly a quarter of the error of the district mean, and the practical gain would be smaller. We could not test weather directly, because the file has no weather variables; this is the main reason we think district-level weather is the most useful data to add.

Effect of the leaf score

Table 10 compares feature sets A and B under the year-aware protocols. The leaf score changes RMSE by at most 0.001 Ton/Ha. XGBoost and the ensemble give the same predictions with and without it, to three decimals. This is expected from the construction in § 4.5: the score is a function of the crop, and the nutrient features already encode the crop. A permutation test on the deployed XGBoost model agrees (Figure 10): shuffling health_score costs nothing, while shuffling pesticide use or nitrogen costs a great deal. Both of those are constant within a crop-year or within a crop, so they act as identifiers of the series rather than as agronomic drivers, and the pesticide column is, for 2001–2013, an exact line in time (§ 3.2). We would not read the importance of pesticides as a causal effect.

Table 10: Adding the leaf score (set B) to the nine tabular features (set A), crop-year table.

ProtocolModelRMSE (A)RMSE (B)R2R^2 (A)R2R^2 (B)
Leave-one-year-outRandom Forest0.5930.5940.3670.364
Leave-one-year-outXGBoost0.6510.6510.2360.236
Leave-one-year-outStacking ensemble0.7370.7370.0230.021
Forward chainingRandom Forest0.7130.713-0.070-0.069
Forward chainingXGBoost0.8170.817-0.405-0.405
Forward chainingStacking ensemble0.9560.958-0.923-0.928

Table 10.

Figure 10. Permutation importance of the ten features for the deployed XGBoost model on its 20% test split. Only pesticide use, nitrogen and (slightly) temperature matter. Both leading features are constant within a crop-year or crop, so they behave as identifiers.

Sensitivity of the deployed application. We also queried the saved models directly. With default slider values (pesticides 6,000 t, temperature 24 °C, N 56, P 42, K 61, soil temperature 24 °C, humidity 86%, pH 6.4), we changed only the leaf score (Table 11). Moving it across its entire range shifts the ensemble prediction by 0.004 Ton/Ha, XGBoost by nothing, and Random Forest by 0.043 Ton/Ha. In its present form, the leaf photograph is displayed and passed to the models, but it has almost no effect on the predicted yield.

Leaf input (health_score)RFXGBoostSVREnsemble
Healthy leaf (0.9921)1.6601.8542.3521.824
No image (0.5)1.6601.8542.3431.825
Diseased leaf (0.0007)1.7031.8542.3261.828

Table 11. Predicted yield (Ton/Ha) of the deployed models for different leaf scores, other inputs fixed.

Leaf-health classifier

On the 772 validation images the classifier made a single error: one healthy leaf was labelled diseased (Figure 11). All 539 diseased leaves and 232 of 233 healthy leaves were classified correctly, an accuracy of 771/772 = 99.87% with a Wilson 95% interval of 99.27–99.98%. Table 12 gives per-class precision, recall and F1, computed from the confusion matrix. Training converged quickly (Figure 11b): validation accuracy was about 99.7% after the first epoch and reached 99.87% in the second. Training accuracy starts lower than validation accuracy, which is what one expects when training images are augmented and dropout is active.

Figure 11. Leaf-health classifier: evaluation on 772 held-out images (539 diseased, 233 healthy) and training history.

ClassPrecisionRecallF1Support
Diseased0.99811.00000.9991539
Healthy1.00000.99570.9979233
Macro average0.99910.99790.9985772

Table 12. Per-class results of the leaf classifier on the validation set.

Confusion matrix (validation set)

Figure 11a. Confusion matrix (validation set)

Accuracy and loss over five epochs

Figure 11b. Accuracy and loss over five epochs

Three caveats limit what this number means. First, PlantVillage images are photographed against plain backgrounds in controlled light, and the collection contains several pictures of the same leaves, so a random image-level split can put near-duplicates on both sides. Second, the same validation set was used to choose the stopping epoch and to report accuracy, which is known to bias estimates upward [7]; we held out no separate test set. Third, the validation images are laboratory photographs, and accuracy has been reported to drop markedly when models trained on such images meet other sources [27]; we address this below with images from other sources, but not with photographs taken in Bahawalpur. We therefore read 99.87% as an optimistic estimate for clean maize images. As a quick sanity check on a non-leaf input, the deployed classifier labelled an image of random noise “healthy” with a probability of 0.535, so its output should not be trusted outside the domain it was trained on.

Unseen images. Table 13 shows the results on the 336 images that remained after removing near-duplicates of PlantVillage (§ 4.6). The classifier recognised 324 of the 336 diseased leaves, a recall of 96.4% (Wilson 95% interval 93.9–97.9%). Recall was highest for northern leaf blight (98.1%) and lowest for common rust (93.9%). The 12 missed leaves received healthy probabilities between 0.59 and 0.92. On the contamination control, the 800 near-duplicates of training images were classified perfectly; that is the number one would have reported by testing on the whole Kaggle dataset without removing duplicates. Two limits remain: the unseen set contains no healthy leaves, so we know the sensitivity of the classifier on another image source but not its false-alarm rate, and no image comes from Bahawalpur.

Image setCorrect / totalRecall of diseased [95% CI]
Unseen: northern leaf blight158 / 1610.981
Unseen: common rust107 / 1140.939
Unseen: gray leaf spot59 / 610.967
Unseen: all diseased324 / 3360.964 [0.939, 0.979]
Near-duplicates of training images (contaminated; sample of 800)800 / 8001.000 [0.995, 1.000]

Table 13. Recall of the diseased class on images that are not in PlantVillage, and on near-duplicates of PlantVillage training images (Corn or Maize Leaf Disease Dataset).

Findings

Table 14 collects what we found, in the order in which the evidence appears. Each row gives the finding, the numbers behind it and where to look.

FindingKey evidenceSee
1The 414-row national table holds only 46 independent observations.3.2
2Random splits inflate the scores.XGBoost R2R^2 0.994 (random 5-fold) →−0.204\to-0.204 (LOYO) on the same rows; 0.54 on the deduplicated table.
3A per-crop linear trend beats every model that is not given the year.LOYO RMSE 0.243 against 0.59–0.74 (46 rows); 0.292 against 0.84–1.06 on the FAOSTAT table (70 rows).
4Giving the models the year helps interpolation but not forecasting.Random Forest + year: LOYO 0.141 and 0.202 (FAOSTAT), but forward chaining 0.333 and 0.336 against 0.317 and 0.339 for the trend (ties).
5The pesticide series is imputed in both data releases, and the gain it seemed to give on the Kaggle table does not survive on the longer FAOSTAT table; temperature change adds nothing.Kaggle: exact line, −989.2 t per year, gain 0.085. FAOSTAT: 4 distinct values, 27 of 35 imputed; gain +0.021 [−0.014, 0.058] (LOYO), −0.024 (forward).
6In an independent district-level wheat panel, most variation is spatial and simple structure is hard to beat.District identity explains 85.4% of variance, season 6.7%; district mean with common trend 0.231; known season shock would give 0.199.
7The leaf classifier is accurate on its benchmark and transfers reasonably to unseen diseased leaves, but the yield models do not use it in any meaningful way.99.87% on PlantVillage validation; 324/336 (96.4%) recall on unseen images; score changes RMSE by ≤0.001\le0.001; ensemble moves 0.004 Ton/Ha.
8The stacking ensemble is effectively XGBoost and is not better than its parts under honest validation.Meta-learner weight 0.967 on XGBoost; LOYO RMSE 0.737 against 0.59–0.65 for the single models.

Table 14. Summary of findings. RMSE in Ton/Ha; LOYO is leave-one-year-out; “ensemble” is the Ridge-stacked model.

What we do not claim. We do not claim that weather has no effect on yield: in our tables rainfall is constant, soil values are crop-level averages and temperature is a national mean of unclear origin, so a null result is what one would expect whatever the truth. We do not claim that learned models cannot beat a trend in general, only that they did not do so here without the year. We do not claim that leaf images cannot help to predict yield, only that our data cannot test it. We do not know how often the classifier raises false alarms on healthy field leaves, because our unseen images are all diseased. And we do not read the importance of pesticide use as an agronomic effect.

Discussion

Three lessons come out of this work, and we think they apply beyond our table.

Check what a row is. The most valuable step in this project was also the simplest: counting how many distinct targets the table contains. Our nine-fold replication came from a many-to-one join that is easy to overlook, because the result still looks like a clean rectangular table with no missing values. A group-aware split, or even a simple check that no two rows share a target and a year, would have caught it at the start. When the unit of prediction is a crop-year, the split should be done by crop-year or, as here, by year.

Always include a trend baseline. Yield series rise over time, so a model that is not told the year is competing against a baseline it cannot see. That simple methods are hard to beat is a recurring finding in forecasting [26], and it held again on the independent district panel, where a district mean with a common trend matched or beat every learned model. In our data, a straight line per crop beats nine-feature machine-learning models by a wide margin. Reporting a model without such a baseline gives no sense of whether the weather and soil variables add anything. In our case, on this table, they do not add much, and the one that seemed to add something (pesticide use) turned out to be an imputed series whose apparent gain vanished on a longer table; in fairness the variables available are weak: rainfall is constant, soil values are crop averages, temperature is a national mean with an undocumented spread, and pesticide use is one number per year.

Be careful what an image feature can claim. The leaf classifier is accurate on its own task, and a health label is useful information for a farmer in its own right, and on diseased leaves it never saw in training it still recovered 96% (§ 5.8); we cannot yet say how often it would raise a false alarm on healthy field leaves. But linking it to yield requires data we did not have: leaf images and yields from the same fields and seasons. Without them, any feature we feed to the yield model is a stand-in, and our stand-in carries no new information. The correct conclusion is not that images cannot help yield prediction. It is that our data cannot tell, and that the interface in its present form should be presented as a leaf-health tool with a yield estimator beside it, not as a combined model.

Hyperparameters and Reproducibility

Table 15 lists every setting used in this paper. All random seeds are fixed at 42, hyperparameters were chosen once and not tuned, and the same settings are used under every validation protocol. The scripts that produce each table and figure are in the code/ folder of the repository (Data and Code Availability).

ModelSettings
Random Forest200 trees, max depth 8 (10 in the 13-feature baseline), seed 42
XGBoost200 trees, learning rate 0.05, max depth 5 (6 in the baseline), seed 42
SVRRBF kernel, C=100C = 100, γ=0.1\gamma= 0.1, ϵ=0.1\epsilon= 0.1, standardised inputs
Ridgeλ=1\lambda= 1, standardised inputs
StackingRF, XGBoost, SVR →\to Ridge (λ=1\lambda= 1), 5-fold out-of-fold predictions
Residual models (Section 5.4)Ridge (λ=1\lambda= 1); Random Forest (200 trees, depth 3, min. leaf 3); XGBoost (100 trees, depth 2, learning rate 0.05); SVR (RBF, C=1C = 1, $\epsilon = 0.05). Chosen once, not tuned.
Leaf classifierMobileNetV2 (frozen), GAP, Dense 128 ReLU, Dropout 0.3, Dense 1 sigmoid; Adam, binary cross-entropy; early stopping (patience 3) on validation accuracy
EvaluationRandom 5-fold (5 repeats); leave-one-year-out (23 folds); forward chaining (test years 1998–2013); bootstrap over years, 2,000 resamples; on the FAOSTAT table, 35 leave-one-year-out folds and forward-chaining test years 1998–2024

Table 15. Settings used for the models in this paper.

Limitations

  • Sample size. The Kaggle-derived table has 46 independent observations from 23 years and the FAOSTAT table 70 from 35 years, in both cases for two crops. Confidence intervals are wide and model rankings among the learned models are not reliable.

  • Aggregation level. Yields, pesticides and temperature are national or crop-level figures. Soil and humidity are crop-level means and carry no spatial information about Punjab’s districts, so the models cannot represent regional variation.

  • National weather. The only weather variable we could test, annual national temperature change, cannot describe growing-season conditions in one province, so its null result is weak evidence about weather in general.

  • Period. The Kaggle-derived table ends in 2013. The FAOSTAT table reaches 2024 but is national and has only 70 observations. The district panel reaches 2019–20 but covers wheat only, has no weather variables, and we did not test generalisation to unseen districts.

  • Pesticide series. The Kaggle table’s pesticide series is an exact straight line from 2001, and the current FAOSTAT series is mostly imputed (27 of 35 values) and takes only four distinct values. Neither is usable as a measure of annual pesticide use, and any apparent link to yield should be regarded as an artefact.

  • Temperature source. The meaning of the nine yearly readings is not documented in the files we used. We averaged them, which may or may not be the right summary.

  • Constructed score. health_score in the training data is a rescaled NPK_total. The integration therefore adds nothing, and the deployed application’s response to a leaf image is nearly flat.

  • Classifier evaluation. Maize only. The PlantVillage validation set was also used to select the stopping epoch. The unseen-image test contains diseased leaves only, its provenance (presumably PlantDoc) is inferred from the dataset description and the image counts, and no photographs from Bahawalpur were tested, so the false-alarm rate on healthy field leaves is unknown.

  • Tuning. Hyperparameters were fixed once and not tuned; a tuned SVR might close part of its gap, although tuning on 46 rows would itself require nested validation.

  • Single seed. We report one seed for the classifier and the deployed models; the random 5-fold results average five repeats.

  • Not for decisions. The system is an academic prototype and has not been validated for farming, financial or policy decisions.

Conclusion and Future Work

We built a yield-prediction prototype for Punjab that combines tree ensembles, SVR and a MobileNetV2 leaf-health classifier, and we were able to reproduce very high scores with it, up to R2=0.991R^2 = 0.991. We then found that these scores came from nine-fold replication in the merged table and did not reflect real predictive skill. Evaluated by year, a linear trend per crop is the strongest option available without extra inputs (RMSE 0.24 Ton/Ha leave-one-year-out on the Kaggle-derived table and 0.29 on a longer table rebuilt from FAOSTAT); models given the year match or beat it, and models without the year do not. Neither pesticide use, whose series is imputed in both releases, nor national temperature change improves on the trend. An independent district-level wheat panel confirmed that most variation in Punjab is spatial and that simple structure is hard to beat, and it bounded what a perfect season-wide predictor could add. The leaf classifier works well on its own benchmark (99.87%) and recovered 96.4% of 336 diseased leaves it had never seen, but our attempt to feed it into the yield models failed for lack of paired data.

The path forward is fairly clear. We would (i) extend the district-by-season yield panel to more crops and add district-level seasonal weather and vegetation indices, which would test the weather question that national data cannot answer; (ii) collect or find leaf images with matched yield records so that health_score can be measured and its value tested; (iii) report leave-one-year-out and forward-chaining results as the headline metrics, with a trend baseline alongside; and (iv) test the classifier on healthy and diseased photographs from the Bahawalpur region, and on wheat. The code, the crop-year tables, the Colab notebook that rebuilds the FAOSTAT table and runs the unseen-image test, and the deployed application are available so that others can reproduce what we did and, where we were wrong, correct it.

Data and Code Availability

The code, notebook, trained models and result tables are available at https://github.com/AminahAsif/Crop_Yield_Prediction-_Punjab and the demo at https://huggingface.co/spaces/AminahAsif/Crop-yield-punjab. The deduplicated crop-year table, the extended FAOSTAT table, the cleaning code for the district panel and a Colab notebook that rebuilds the FAOSTAT table and runs the unseen-image test are included in the repository. The source datasets are public on Kaggle (Table 1); please check their licences before redistributing the raw files. The district yield file is available from the Open Data Pakistan portal [28], which lists no licence, so we do not redistribute it.

Acknowledgements

During the preparation of this work, the authors used Claude (Anthropic) to assist with code development and debugging. The authors reviewed and edited all content as needed and take full responsibility for the content of this paper.

References

  1. [1]abdallahalidev. Plant Village dataset. Kaggle, https://www.kaggle.com/datasets/abdallahalidev/plantvillage-dataset. Accessed 2026.
  2. [2]Abubakar Abid, Ali Abdalla, Ali Abid, Dawood Khan, Abdulrahman Alfozan, and James Zou. Gradio: Hassle-free sharing and testing of ML models in the wild, 2019.arxiv.org/abs/1906.02569
  3. [3]Sylvain Arlot and Alain Celisse. A survey of cross-validation procedures for model selection. Statistics Surveys, 4:40–79, 2010.
  4. [4]Jayme Garcia Arnal Barbedo. Impact of dataset size and variety on the effectiveness of deep learning and transfer learning for plant disease classification. Computers and Electronics in Agriculture, 153:46–53, 2018.DOI
  5. [5]Christoph Bergmeir and José M. Benítez. On the use of cross-validation for time series predictor evaluation. Information Sciences, 191:192–213, 2012.DOI
  6. [6]Leo Breiman. Random forests. Machine Learning, 45(1):5–32, 2001.
  7. [7]Gavin C. Cawley and Nicola L. C. Talbot. On over-fitting in model selection and subsequent selection bias in performance evaluation. Journal of Machine Learning Research, 11:2079–2107, 2010.DOI
  8. [8]Tianqi Chen and Carlos Guestrin. XGBoost: A scalable tree boosting system. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, pages 785–794, 2016.DOI
  9. [9]François Chollet et al. Keras. https://keras.io/, 2015.
  10. [10]Harris Drucker, Christopher J. C. Burges, Linda Kaufman, Alex Smola, and Vladimir Vapnik. Support vector regression machines. In Advances in Neural Information Processing Systems 9, pages 155–161, 1997.
  11. [11]Bradley Efron and Robert J. Tibshirani. An Introduction to the Bootstrap. Chapman & Hall, 1993.
  12. [12]Finance Division, Government of Pakistan. Pakistan economic survey 2023–24, chapter 2: Agriculture. https://www.finance.gov.pk/survey/chapter_24/2_agriculture.pdf, 2024.
  13. [13]Food and Agriculture Organization of the United Nations. FAOSTAT statistical database. https://www.fao.org/faostat.
  14. [14]Robert Geirhos, Jörn-Henrik Jacobsen, Claudio Michaelis, et al. Shortcut learning in deep neural networks. Nature Machine Intelligence, 2(11):665–673, 2020.DOI
  15. [15]Trevor Hastie, Robert Tibshirani, and Jerome Friedman. The Elements of Statistical Learning: Data Mining, Inference, and Prediction. Springer, 2 edition, 2009.
  16. [16]Arthur E. Hoerl and Robert W. Kennard. Ridge regression: Biased estimation for nonorthogonal problems. Technometrics, 12(1):55–67, 1970.
  17. [17]David P. Hughes and Marcel Salathé. An open access repository of images on plant health to enable the development of mobile disease diagnostics, 2015.
  18. [18]Rob J. Hyndman and George Athanasopoulos. Forecasting: Principles and Practice. OTexts, 3 edition, 2021.
  19. [19]Rob J. Hyndman and Anne B. Koehler. Another look at measures of forecast accuracy. International Journal of Forecasting, 22(4):679–688, 2006.
  20. [20]Jig Han Jeong, Jonathan P. Resop, Nathaniel D. Mueller, et al. Random forests for global and regional crop yield predictions. PLOS ONE, 11(6):e0156571, 2016.DOI
  21. [21]Sayash Kapoor and Arvind Narayanan. Leakage and the reproducibility crisis in machine-learning-based science. Patterns, 4(9):100804, 2023.
  22. [22]Shachar Kaufman, Saharon Rosset, Claudia Perlich, and Ori Stitelman. Leakage in data mining: Formulation, detection, and avoidance. ACM Transactions on Knowledge Discovery from Data, 6(4):15:1–15:21, 2012.
  23. [23]Saeed Khaki and Lizhi Wang. Crop yield prediction using deep neural networks. Frontiers in Plant Science, 10:621, 2019.
  24. [24]David B. Lobell and Marshall B. Burke. On the use of statistical models to predict crop yield responses to climate change. Agricultural and Forest Meteorology, 150(11):1443–1452, 2010.
  25. [25]Scott M. Lundberg and Su-In Lee. A unified approach to interpreting model predictions. In Advances in Neural Information Processing Systems 30, pages 4765–4774, 2017.
  26. [26]Spyros Makridakis, Evangelos Spiliotis, and Vassilios Assimakopoulos. Statistical and machine learning forecasting methods: Concerns and ways forward. PLOS ONE, 13(3):e0194889, 2018.
  27. [27]Sharada P. Mohanty, David P. Hughes, and Marcel Salathé. Using deep learning for image-based plant disease detection. Frontiers in Plant Science, 7:1419, 2016.
  28. [28]Pakistan Bureau of Statistics. Area sown, production and yield per hectare of wheat by districts, Punjab. Open Data Pakistan, https://opendata.com.pk/dataset/area-sown-production-and-yield-per-hectare-of-wheat-by-districts-punjab. Accessed 2026.
  29. [29]patelris. Crop yield prediction dataset. Kaggle, https://www.kaggle.com/datasets/patelris/crop-yield-prediction-dataset. Accessed 2026.
  30. [30]Fabian Pedregosa, Gaël Varoquaux, Alexandre Gramfort, et al. Scikit-learn: Machine learning in Python. Journal of Machine Learning Research, 12:2825–2830, 2011.arxiv.org/abs/1201.0490
  31. [31]David R. Roberts, Volker Bahn, Simone Ciuti, et al. Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure. Ecography, 40(8):913–929, 2017.
  32. [32]Mark Sandler, Andrew Howard, Menglong Zhu, Andrey Zhmoginov, and Liang-Chieh Chen. MobileNetV2: Inverted residuals and linear bottlenecks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 4510–4520, 2018.arxiv.org/abs/1801.04381
  33. [33]Wolfram Schlenker and Michael J. Roberts. Nonlinear temperature effects indicate severe damages to U.S. crop yields under climate change. Proceedings of the National Academy of Sciences, 106(37):15594–15598, 2009.
  34. [34]Davinder Singh, Naman Jain, Pranjali Jain, Pratik Kayal, Sudhakar Kumawat, and Nipun Batra. PlantDoc: A dataset for visual plant disease detection. In Proceedings of the 7th ACM IKDD CoDS and 25th COMAD, pages 249–253, 2020.DOI
  35. [35]smaranjitghose. Corn or maize leaf disease dataset. Kaggle, https://www.kaggle.com/datasets/smaranjitghose/corn-or-maize-leaf-disease-dataset. Accessed 2026.
  36. [36]Leonard J. Tashman. Out-of-sample tests of forecasting accuracy: an analysis and review. International Journal of Forecasting, 16(4):437–450, 2000.DOI
  37. [37]Thomas van Klompenburg, Ayalew Kassahun, and Cagatay Catal. Crop yield prediction using machine learning: A systematic literature review. Computers and Electronics in Agriculture, 177:105709, 2020.DOI
  38. [38]Edwin B. Wilson. Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, 22(158):209–212, 1927.DOI
  39. [39]David H. Wolpert. Stacked generalization. Neural Networks, 5(2):241–259, 1992.DOI

Paper details

vlnc:W_h429yftk
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Claude (Anthropic)

View statement
Looking for related papers…
Contents