A leading home improvement and construction material retailer approached us to develop an automated freight cost prediction system for their logistics operations. The project’s primary goal was to create a reliable, real-time system for estimating shipping costs across different courier services, with a particular focus on their primary logistics provider.
Project Scope and Technological Implementation
The goal was the development of a comprehensive freight cost prediction system that would handle approximately half a million requests per day. The system needed to process orders in real-time, providing accurate shipping cost estimates while accounting for other factors such as product dimensions, weight, shipping zones, and special handling requirements.
Key Challenges Addressed
- Data Quality and Availability: Significant data quality issues were discovered during detailed system evaluation, revealing inconsistencies in master data and pricing variations with suppliers.
- Digital Maturity: The existing IT infrastructure and digitalization level presented additional challenges, making both machine learning implementation and integration more complex than initially anticipated.
- Non-Deterministic Calculations: The final shipping price depends on multiple variable factors:
- Actual route and fuel used taken by the shipping company to deliver the goods
- Volume and pallet configuration of purchased items
- Product packaging and assembly requirements
- Special properties (the assembled pallet is oversized in any of its dimensions)
- High Performance Requirements:
- Handle approximately 500,000 requests daily
- Maintain low latency for seamless user experience on both website and mobile applications
- Handle unevenly distributed load patterns using my API, which performs machine learning predictions.
- Business Rule Integration:
- Accommodate sales campaign parameters (lower the freight cost predictions for some goods or to some specific delivery address)
- Support multiple shipping companies with different business logic
- Be easily extensible for future carriers or changes in their calculations
- Handle complex pricing rules and special conditions of the goods
Implementation Approach
Machine Learning Strategy
During the selection of the AI model I prioritized accuracy, scalability, and addressing key challenges such as:
- Superior performance compared to statistical methods
- Ability to handle variable-length input sets (variable number of items per basket)
- Robust handling of missing data
- Context-aware processing capabilities
During the pilot phase, I tested statistical approaches and cutting-edge models, including:
- Recurrent Neural Networks
- Attention Mechanisms
- Set Transformer architecture
- XGBoost, gradient boosting model
The team selected XGBoost as the primary machine learning framework due to its accuracy, reliable performance, and relatively low complexity. To address the criterion of handling variable-length input sets, I used a proprietary algorithm to encode the basket into a single vector, independent of the number of items.
System Architecture
The implementation utilized a modern technology stack:
- Backend: Python with FastAPI framework, hosted by gunicorn
- Machine Learning: XGBoost for prediction models
- Database: SQL Server for data management
- Deployment: Docker containers for scalability
- Monitoring: Real-time health checks and alerts, Tensorboard performance monitoring
Results and Performance Metrics
The machine learning model demonstrated significant improvements over baseline performance of their current approach:
24.6% reduction in mean squared error
29.5% reduction in mean absolute error
Consistent performance across different product categories
This improvement resulted in a more realistic cost burden for prospective customers (leading to a higher conversion rate) and reduced the risk for the company of underpricing deliveries and subsequently covering the delivery costs themselves.
Key Lessons Learned
Data Quality Impact:
- Detailed data analysis revealed numerous master data inconsistencies
- Data engineering and cleansing contributed more to results than model sophistication
Digital Infrastructure:
- Proper digitalization levels and IT infrastructure would have significantly simplified both ML implementation and integration
- Legacy systems created additional complexity in data processing and integration
Supplier Pricing Analysis:
- Detailed data analysis uncovered pricing discrepancies with shipping service suppliers
- Provided additional business insights beyond the primary project scope
Development Focus:
- Data engineering and cleaning efforts proved more valuable for accuracy than complex model development
- Simple, robust solutions often outperformed more sophisticated approaches
Conclusion
This project highlights how I successfully built an AI-powered system to predict freight costs by blending machine learning with clear business rules. Along the way, I not only hit our main goals but also uncovered valuable insights into data quality and supplier pricing, offering extra benefits beyond the original scope.


