This project contains two ML pipelines built on data/inventory.db:
Freight Cost Prediction(regression): predicts freight amount from invoice dollars.Invoice Flagging(classification): predicts whether an invoice should be flagged for review.
It also includes a Streamlit web app to run both models from a UI.
.
├── app.py
├── data/
│ └── inventory.db
├── freight_cost_prediction/
│ ├── data_preprocessing.py
│ ├── model_evaluation.py
│ └── train.py
├── invoice_flagging/
│ ├── data_preprocessing.py
│ ├── modelig_evolution.py
│ └── train.py
├── inference/
│ ├── predict_freight.py
│ └── predict_invoice_flag.py
├── models/
│ ├── predict_freight_model.pkl
│ ├── predict_flag_invoice.pkl
│ └── scaler.pkl
└── notebooks/
├── predicting_freight_cost.ipynb
└── invoice_flagging.ipynb
- Python 3.x
- pandas
- numpy
- scikit-learn
- joblib
- sqlite3 (stdlib)
- streamlit
- Create and activate a virtual environment.
- Install dependencies.
python -m venv .venv
source .venv/bin/activate
pip install pandas numpy scikit-learn joblib streamlitOr install from file:
pip install -r requirements.txt- SQLite DB:
data/inventory.db - Main tables used:
vendor_invoice(freight regression + part of flagging features)purchases(aggregated for flagging features)
Path: freight_cost_prediction/
- Feature:
Dollars - Target:
Freight
- Linear Regression
- Decision Tree Regressor
- Random Forest Regressor
- Evaluate MAE / RMSE / R2
- Best model chosen by lowest MAE in
freight_cost_prediction/train.py
Run from repo root:
python freight_cost_prediction/train.pymodels/predict_freight_model.pkl
Path: invoice_flagging/
flag_invoice = 1 when either condition is true:
abs(invoice_dollars - total_item_dollars) > 5avg_receiving_delay > 10
Else flag_invoice = 0.
invoice_quantityinvoice_dollarsFreighttotal_item_quantitydays_po_to_invoicetotal_item_dollars
StandardScalerfit on train split and saved as:models/scaler.pkl
- RandomForestClassifier with
GridSearchCV
Run from repo root:
python invoice_flagging/train.pymodels/predict_flag_invoice.pklmodels/scaler.pkl
python inference/predict_freight.pyThis script loads models/predict_freight_model.pkl and predicts Predicted_Freight.
python inference/predict_invoice_flag.pyNote: the current script is a basic template and may require alignment with the classifier feature set and scaler pipeline for production usage.
Path: app.py
The app includes two tabs:
Freight Model: input invoice dollars -> predicted freightInvoice Flag Model: input six engineered features -> predicted flag + confidence (if available)
streamlit run app.pyThen open the URL printed in terminal (usually http://localhost:8501).
- Ensure
requirements.txtis present at repo root (already added). - Ensure
runtime.txtis present at repo root (already added,python-3.11). - In Streamlit Cloud app settings:
- Repository: this repo
- Branch:
master - Main file path:
app.py
- Train freight model:
python freight_cost_prediction/train.py
- Train invoice flag model:
python invoice_flagging/train.py
- Launch UI:
streamlit run app.py
- Test predictions via web forms.
FileNotFoundErrorfor model/scaler:- Train model pipelines first so files are generated in
models/.
- Train model pipelines first so files are generated in
- Import errors when running scripts:
- Run commands from repository root.
- Streamlit command not found:
- Install streamlit in active environment:
pip install streamlit.
- Install streamlit in active environment:
- Add
requirements.txtand pinned versions. - Unify module naming (
modelig_evolution.pytypo can be renamed safely). - Add unit tests for preprocessing and inference contracts.
- Add one consistent inference API for both models (CLI + batch input).
- Add model/version metadata and experiment tracking.