Import
TransportPredictor loads all available .pkl model files from src/air_travel_model/data/. Missing files are skipped — the predictor still works with whatever models are present.
Methods
predict(model, origin, destination, **kwargs) -> float | None
Runs the ML model for the given mode. Returns a float (time in minutes or cost in USD), or None if the model is not loaded.
For drive_time, routes not in the training dataset fall back to a live OSRM query before returning None. See Routing Fallback.
| Parameter | Type | Description |
|---|---|---|
model | str | Model name — see table below |
origin | str | tuple | IATA code, "City, ST", or (lat, lon) |
destination | str | tuple | Same as origin |
**kwargs | Model-specific options — see table below |
ValueError for unrecognised location strings.
estimate(model, origin, destination, **kwargs) -> float | None
Heuristic estimate — intended as a guaranteed fallback when predict() returns None or the model is not loaded.
For drive_time, estimate() also queries OSRM first and only falls back to the haversine formula if OSRM is unavailable.
predict_all(origin, destination, **kwargs) -> dict
Calls predict() for all loaded models and returns a {model_name: float} dict. Models that return None are omitted from the result.
estimate_all(origin, destination) -> dict
Calls estimate() for all models. Returns a {model_name: float} dict, skipping any model whose estimate() raises or returns None.
available -> list[str]
Returns model names that have a trained .pkl loaded.
Model names and kwargs
| Model name | Unit | Required kwargs | Optional kwargs |
|---|---|---|---|
air_fare | USD | quarter (1–4) | is_business (bool, default False) |
air_time | minutes | quarter (1–4) | — |
drive_time | minutes | — | — |
drive_fare | USD | — | gas_price ($/gal, default 3.50), mpg (default 28) |
bus_fare | USD | quarter (1–4) | is_premium (bool, default False) |
bus_time | minutes | quarter (1–4) | — |
train_time | minutes | quarter (1–4) | — |
Location resolution
Locations are resolved throughair_travel_model.resolvers.location.resolve():
- IATA code (
"CHS") — direct lookup inairports.csv - City name (
"Charleston, SC") — matched againstcity, stateentries inairports.csv (lat, lon)tuple — used directly for coordinate-based routing; no IATA code is assigned, so models that require a code for route-stats lookup (air_fare, air_time) will fall back to their heuristics
ValueError with a descriptive message for unrecognised strings.
For train_time, origins and destinations are additionally resolved against amtrak_stations.csv. Amtrak station codes ("NYP", "WAS", "CHI") give the best accuracy because the model was trained on station-to-station pairs.