Skip to main content

Import

On instantiation, 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.
Raises 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


Location resolution

Locations are resolved through air_travel_model.resolvers.location.resolve():
  • IATA code ("CHS") — direct lookup in airports.csv
  • City name ("Charleston, SC") — matched against city, state entries in airports.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
Raises 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.