Freight Cost Prediction & Invoice Risk Flagging
- Project Overview
- Business Objectives
- Data Sources
- Exploratory Data Analysis
- Models Used
- Evaluation Metrics
- Application
- Project Structure
- How to Run This Project
- Author & Contact
This project implements an end-to-end machine learning system designed to support finance teams by:
- Predicting expected freight cost for vendor invoices.
- Flagging high-risk invoices that require manual review due to abnormal cost, freight, or operational patterns.
Objective:
Predict the expected freight cost for a vendor invoice using quantity, invoice value, and historical behavior.
Why it matters:
- Freight is a non-trivial component of landed cost.
- Poor freight estimation impacts margin analysis and budgeting.
- Early prediction improves procurement planning and vendor negotiation.
Objective:
Predict whether a vendor invoice should be flagged for manual approval due to abnormal cost, freight, or delivery patterns.
Why it matters:
- Manual invoice review does not scale.
- Financial leakage often occurs in large or complex invoices.
- Early risk detection improves audit efficiency and operational control.
Data is stored in a relational SQLite database (inventory.db) with the following tables:
vendor_invoice– Invoice-level financial and timing datapurchases– Item-level purchase detailspurchase_prices– Reference purchase pricesbegin_inventory,end_inventory– Inventory snapshots
SQL aggregation is used to generate invoice-level features.
EDA focuses on business-driven questions, such as:
- Do flagged invoices have higher financial exposure?
- Does freight scale linearly with quantity?
- Does freight cost depend on quantity?
Statistical tests (t-tests) are used to confirm that flagged invoices differ meaningfully from normal invoices.
- Linear Regression (baseline)
- Decision Tree Regressor
- Random Forest Regressor (final model)
- Logistic Regression (baseline)
- Decision Tree Classifier
- Random Forest Classifier (final model with GridSearchCV)
Hyperparameter tuning is performed using GridSearchCV with F1-score to handle class imbalance.
- MAE
- RMSE
- R² Score
- Accuracy
- Precision, Recall, F1-score
- Classification report
- Feature importance analysis
A Streamlit application demonstrates the complete pipeline:
- Input invoice details
- Predict expected freight
- Flag invoices in real time
- Provide human-readable explanations
inventory-invoice-analytics/
│
├── data/
│ └── inventory.db
│
├── freight_cost_prediction/
│ ├── data_preprocessing.py
│ ├── model_evaluation.py
│ └── train.py
│
├── invoice_flagging/
│ ├── data_preprocessing.py
│ ├── model_evaluation.py
│ ├── model_evaluation.py
│ └── train.py
│
├── inference/
│ ├── predict_freight.py
│ └── predict_invoice_flag.py
│
├── models/
│ ├── predict_freight_model.pkl
│ ├── scaler.pkl
│ └── predict_flag_invoice.pkl
│
├── notebooks/
│ ├── Invoice Flagging.pkl
│ └── Predict Freight Cost.ipynb
│
├── app.py
├── README.md
└── .gitignore- Clone the repository:
git clone https://github.com/yourusername/inventory-invoice-analytics.git- Train and Save Best Fit Models:
python freight_cost_prediction/train.py
python invoice_flagging/train.py- Test Models:
python inference/predict_freight.py
python inference/predict_invoice_flag.py- Open Application:
streamlit run app.pyNimesh Patel
ML Engineer
📧 Email: pnimesh0806@gmail.com

