A Machine Learning-Based Prediction Model for Agricultural Commodity Prices in Nigeria
Abstract
Agricultural commodity prices in Nigeria are highly volatile due to inflation, seasonality, weather variability, macroeconomic disruptions, and supply-chain challenges, making price forecasting difficult for farmers, traders, consumers, and policymakers [1]. This study develops a machine learning-based prediction model for forecasting the prices of selected agricultural commodities across Nigerian markets. Data from the World Food Programme (WFP) Nigeria food price dataset and a macroeconomic panel dataset were integrated to construct a forecasting dataset covering seven commodities including Yam, Cassava Meal/Gari (Yellow), Gari (White), Rice (Local), Maize (White), Maize (Yellow), and Rice (Imported) across 58 markets in 14 states from 2009 to 2024. Commodity prices were standardized to Nigerian Naira per kilogram, and a five-step imputation pipeline was developed to address temporal and structural missingness in the WFP data, increasing price coverage from 43–49% to 81–97% while preserving the underlying price distributions. Feature engineering produced a 22-feature supervised learning dataset incorporating temporal, macroeconomic, geographical, lagged-price, rolling-statistic, and CPI-deflated features. Five forecasting approaches were trained and evaluated: ARIMA, XGBoost, Random Forest, ARIMA–XGBoost, and ARIMA–Random Forest hybrid models. Chronological train-test splitting was employed, with model evaluation restricted to observed price values to prevent imputed data from artificially inflating performance. The models were evaluated using MAPE-based accuracy, R², and Mean Absolute Error (MAE) and Random Forest achieved the best overall performance across all seven commodities, with accuracy ranging from 76.01% for Local Rice to 90.69% for White Maize. The results demonstrate the effectiveness of tree-based machine learning for agricultural price forecasting under changing economic conditions. The best-performing models were deployed through AgriPrice Nigeria, a Streamlit-based application that enables users without technical expertise to obtain commodity price predictions. This work demonstrates how machine learning and robust data preprocessing can support agricultural price forecasting and data-driven decision-making in Nigeria.