bakytius/freight-profitability-app
0
๐ Freight Profitability Predictor
A Streamlit web application that predicts whether a freight load will be profitable, powered by an XGBoost machine learning model.
Features
- Automatic Mileage Calculation โ Enter pickup and delivery cities/states and the app automatically geocodes them using OpenStreetMap (via
geopy) and estimates road miles. - Profitability Prediction โ Uses a trained XGBoost model to classify a load as profitable or not, along with a probability score.
- Load Details โ Supports Dry Van, Reefer, and Flatbed load types.
- Input Summary โ Expandable section shows the exact feature values passed to the model.
Project Structure
freight-profitability-app/
โโโ app.py # Main Streamlit application
โโโ xgboost_model.pkl # Trained XGBoost model (pipeline with preprocessing)
โโโ requirements.txt # Python dependencies
โโโ inspect_model.py # Utility to inspect model pipeline/features
โโโ check_imports.py # Utility to verify installed packages
โโโ .venv/ # Python virtual environmentRequirements
- Python 3.9+
- Dependencies listed in
requirements.txt: streamlitpandasscikit-learn==1.6.1xgboostjoblibgeopy
Setup & Installation
- Clone or download the repository.
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Ensure the model file is present: Make sure
xgboost_model.pklis in the root directory.
Running the App
streamlit run app.pyThen open http://localhost:8501 in your browser.
How to Use
- Enter Pickup Location โ Type a city/state (e.g.,
Dallas, TX). Mileage is auto-calculated when both locations are filled. - Enter Delivery Location โ Type a city/state (e.g.,
Chicago, IL). - Select Load Type โ Choose from Dry Van, Reefer, or Flatbed.
- Select Pickup Date โ Used to extract month and day-of-week features.
- Enter Rate ($) โ The total freight rate offered.
- Verify / Adjust Miles โ Auto-filled from geocoding; can be manually overridden.
- Enter Weight (lbs) โ Cargo weight.
- Click "๐ Predict Profitability" โ View the prediction and probability score.
Model Input Features
Notes
- Geocoding uses the Nominatim service (OpenStreetMap). Road distance is estimated as geodesic distance ร 1.17 to approximate road curvature.
- The model file (
xgboost_model.pkl) must be a scikit-learn Pipeline that handles categorical encoding internally. - State codes are extracted automatically from the
City, Stateformat (e.g.,Houston, TXโTX).
