Skip to main content
CASE STUDY // Research seedbed — CUN2026

Import price prediction with machine learning

Machine learning pipeline on customs records of frozen chicken imports into Mexico: it predicts unit price in USD/kg and segments importers.

Start a Project
Import price prediction with machine learning

METRICS // PERFORMANCE

Impact & Performance Metrics

0.9034

Test R²

Winsorized test (p1–p99), mean of 3 seeds

0.1971

MAE

Mean absolute error in USD/kg

389,303

Transactions

Mexico 2019-2026, 1,059 importers

0.728

Silhouette

K-Means on RFM with 6 clusters

The Challenge

Agricultural price studies usually rely on aggregate series that hide the variation between transactions. The goal was to predict the unit price of each shipment from Veritrade customs records: 389,303 frozen chicken imports into Mexico between 2019 and 2026, from 1,059 importers, with noisy data and outliers. There is also a structural ceiling: the final price depends on bilateral negotiations that the customs record does not show.

The Solution & Technical Approach

Module 1: LightGBM with a hyperparameter grid and extended feature engineering (v4), compared against XGBoost, Random Forest, KNN and ARIMA. A data-leakage audit found and fixed two leaks: the target used as a feature (a fake R² of 0.9996) and training lags and target encoding that included the price of the row itself. Leak-free, the production model (mean of 3 seeds, frozen protocol) reaches R² 0.9034 and MAE 0.1971 USD/kg on 21,803 future records with the price winsorized at p1–p99; on the raw price R² is 0.5737 because of tail errors, and bilateral negotiation sets a ceiling the customs record does not capture. Exogenous variables (exchange rate, grains, diesel, climate) bring no meaningful gain. Module 2: RFM and K-Means (6 clusters, silhouette 0.728), fpgrowth association rules and DBSCAN outlier detection. Individual research supervised by Camilo Barajas; the manuscript is in preparation for the journal Ciencia e Ingeniería (Universidad de La Guajira).

Key Features

  • Data-leakage audit: two leaks found and fixed (target used as a feature and training lags that included the price of the row itself)
  • Strict temporal validation: 353,377 training rows and a test on 21,803 future records never seen
  • RFM segmentation: 0.6% of importers account for 27.2% of traded value
  • Association rules with lift up to 22.90 and DBSCAN outlier detection

Technical Architecture

Reproducible Python pipeline in three stages: cleaning and standardizing the Veritrade file (repeated headers, metadata columns, winsorization with thresholds computed on training data only); feature engineering (calendar, price lags by tariff line and customs office, Bayesian target encoding, computed from earlier dates only); and modeling with LightGBM for price and K-Means on RFM features for segmentation. Strict temporal validation: training through September 2025 (353,377 rows), validation on the last quarter of 2025 and testing on 21,803 records from 2026.

NEXT STEP // COLLABORATION

Have a similar project in mind?

Let’s design a scalable, high-performance, and secure architecture tailored for your business.

Start a Project