CoolFace
Apppublic

bakytius/freight-profitability-app

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

๐Ÿš› 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 environment

Requirements

  • โ€”Python 3.9+
  • โ€”Dependencies listed in requirements.txt:
  • โ€”streamlit
  • โ€”pandas
  • โ€”scikit-learn==1.6.1
  • โ€”xgboost
  • โ€”joblib
  • โ€”geopy

Setup & Installation

  1. 1.Clone or download the repository.
  1. 1.Create and activate a virtual environment:
bash
   python -m venv .venv
   source .venv/bin/activate   # On Windows: .venv\Scripts\activate
  1. 1.Install dependencies:
bash
   pip install -r requirements.txt
  1. 1.Ensure the model file is present: Make sure xgboost_model.pkl is in the root directory.

Running the App

bash
streamlit run app.py

Then open http://localhost:8501 in your browser.

How to Use

  1. 1.Enter Pickup Location โ€” Type a city/state (e.g., Dallas, TX). Mileage is auto-calculated when both locations are filled.
  2. 2.Enter Delivery Location โ€” Type a city/state (e.g., Chicago, IL).
  3. 3.Select Load Type โ€” Choose from Dry Van, Reefer, or Flatbed.
  4. 4.Select Pickup Date โ€” Used to extract month and day-of-week features.
  5. 5.Enter Rate ($) โ€” The total freight rate offered.
  6. 6.Verify / Adjust Miles โ€” Auto-filled from geocoding; can be manually overridden.
  7. 7.Enter Weight (lbs) โ€” Cargo weight.
  8. 8.Click "๐Ÿš€ Predict Profitability" โ€” View the prediction and probability score.

Model Input Features

FeatureDescription
rate_per_mileRate รท Miles
actual_distance_milesRoad distance (auto-calculated or manual)
weight_lbsCargo weight in pounds
pickup_monthMonth of pickup date (1โ€“12)
pickup_day_of_weekDay of week (0=Monday โ€ฆ 6=Sunday)
load_typeDry Van / Reefer / Flatbed
origin_state2-letter state code from pickup location
destination_state2-letter state code from delivery location

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, State format (e.g., Houston, TX โ†’ TX).