The response time is one of the most important factors for emergency services because their ability to save lives and rescue people depends on it. A non-optimal choice of an emergency vehicle for a rescue request may lengthen the arrival time of the rescuers and impact the future of the victim. This choice is therefore highly critical for emergency services and directly rely on their ability to predict precisely the arrival time of the different units available.
This project aims to predict the response time of the appliances of an emergency service and is ONLY made possible through the code sharing from Wenqi Shu-Quartier-dit-Maire (wshuquar - rank 2 on the leaderboard), Antoine Moulin (amoulin), Julien Jerphanion & Edwige Cyffers (edwige & jjerphan), Wassim Bouaziz & Elliot Vincent (elliot.vincent & wesbz), Quentin Gallouedec (Quenting44), Laurent Deborde (Ljmdeb), François Paupier (popszer), Léo Andéol (leoandeol).
Thanks to all of them very much for the work carried out and shared.
With the current stage of the model and the Paris Fire Brigade data, we reach the following performances:
Metric | Score |
---|---|
Delta selection-presentation R² score | 0.3519 |
RMSLE (Root mean squared logarithmic error) | 0.2409 |
Median error | 46.8585 seconds |
Mean error | 79.8842 seconds |
For instance we have only used the fantastic work of Wenqi Shu-Quartier-dit-Maire but we are eager to also exploit the work of the other participants quoted just above resealing wonderful ideas.
Download the repo
git clone https://github.com/ds4es/unit-response-oracle
cd ./unit-response-oracle
Load your Python environment (eg. conda activate my_env
).
Install dependencies
pip install -r requirements.txt
Add the root project path to your PYTHONPATH
variable:
export PYTHONPATH=$PYTHONPATH:$(pwd)
python src/data/paris_fire_brigade_raw_data_to_processed.py
: to turn Paris Fire Brigade data challenge raw data into preprocessed datapython src/models/train_linear.py
: to train an intermediate linear modelpython src/models/train_lgbm.py
: to train the global modelpython src/models/predict.py
: to make a predictionpython src/utils/prediction_evaluation.py
: to evaluate a prediction (the default execution will need araw/paris_fire_brigade_2018/y_test.zip
file)python src/train_predict_evaluate.py
: to train a model, predict and evaluate the result of the prediction (the default execution will need araw/paris_fire_brigade_2018/y_test.zip
file)
To remove assert and debug-dependent statements add the -O
flag when running one of those scripts, e.g.:
python -O src/train_predict_evaluate.py
NB: Take a look at the src/config.py constant variables
To start the jupyter notebook in the dedicated folder
jupyter notebook --notebook-dir=notebooks
And start your notebook with:
import os
os.chdir('..')
print(os.getcwd(), "set as current working directory")
In a first terminal, start the API:
python api/api_for_paris_fire_brigade_data.py
In a second terminal, launch a random query:
python api/make_me_a_query_for_paris_fire_brigade_2018_data.py
Input data description (for the Paris Fire Brigade dataset under the data/processed/paris_fire_brigade_2018
folder)
- [ID]
emergency vehicle selection
: identifier of the selection instance of an emergency vehicle for an intervention - Intervention
intervention
: identifier of the interventionalert reason category
(category): alert reason categoryalert reason
(category): alert reason
- Address
intervention on public roads
(boolean): 1 when it concerns an intervention on public roads, 0 otherwisefloor
(int): floor of the interventionlocation of the event
(category): qualifies the location of the emergency request, for example: entrance hall, boiler room, motorway, etc.longitude intervention
: (float): approximate longitude of the intervention addresslatitude intervention
(float): approximate latitude of the intervention address
- Emergency vehicle
emergency vehicle
: identifier of the emergency vehicleemergency vehicle type
(category): type of the emergency vehiclerescue center
(category): identifier of the rescue center to which belong the vehicle (parking spot of the emergency vehicle)
selection time
(int): selection time of the emergency vehicle (seconds since the 1 January 1970)delta status preceding selection-selection
(int): number of seconds before the vehicle was selected when its previous status was entereddeparted from its rescue center
(boolean) : 1 when the vehicle departed from its rescue center (emergency vehicle parking spot), 0 otherwiselongitude before departure
(float): longitude of the position of the vehicle preceding his departurelatitude before departure
(float): latitude of the position of the vehicle preceding his departuredelta position gps previous departure-departure
(int): number of seconds before the selection of the vehicle where its GPS position was recorded (when not parked at its emergency center)routing engine estimated distance
(float): distance (in meters) calculated by the routing engine route servicerouting engine estimated duration
(float): transit delay (in seconds) calculated by the routing engine route servicerouting engine estimated distance from last observed GPS position
(float): distance (in meters) calculated by the routing engine route service from last observed GPS positionrouting engine estimated duration from last observed GPS position
(float): transit delay (in seconds) calculated by the routing engine route service from last observed GPS positiontime elapsed between selection and last observed GPS position
(float): in secondsupdated routing engine estimated duration
(float): time elapsed (in seconds) between selection and last observed GPS position + routing engine estimated duration from last observed GPS positiontime day
(float):time week
(float):time year
(float):departure center
(int): Departure parking placeGPS tracks count
(int): Number of GPS traces observedestimated speed
(float): Estimated speed (in meters/second) due to last observed positionestimated duration from speed
(float): Estimateddelta selection-presentation
(in seconds) based onestimated speed
estimated time factor
(float):estimated duration from time
(float): Estimateddelta selection-presentation
(in seconds) based onestimated time factor
intervention count
(int): Number of units sent for this interventionrescaled longitude before departure
rescaled longitude intervention
rescaled latitude before departure
rescaled latitude intervention
Backup your work in the parent folder in a ZIP file without data, models...
zip -r ../unit-response-oracle_$(date +%Y%m%d_%H%M%S).zip . -x "*.csv" "*.pkl" "*__pycache__*" "*.git*" "*.ipynb*" "*mlruns*" ".tar"
neptune-mflow
integrates mlflow
with Neptune
to let you get the best of both worlds: tracking and reproducibility of mlflow
with organization and collaboration of Neptune
.
Reference: neptune-mlflow GitHub repo
mlflow
is a dependency of neptune-mlflow
so do not worry if you need or not mlflow
.
pip install neptune-mlflow
Login to Neptune retrieve your API token and declare it through ~/.bashrc
vi ~/.bashrc
Add this line with your Neptune API token
export NEPTUNE_API_TOKEN="your_long_api_token"
Reload ~/.bashrc
source ~/.bashrc
mkdir project_repo
cd project_repo
vi example.py
Add MLFlow functions in your code to log metrics, parameters and artifacts
# example.py
import os
from mlflow import log_metric, log_param, log_artifact
if __name__ == "__main__":
# Log a parameter (key-value pair)
log_param("param1", 5)
# Log a metric; metrics can be updated throughout the run
log_metric("foo", 1)
log_metric("foo", 2)
log_metric("foo", 3)
# Log an artifact (output file)
with open("output.txt", "w") as f:
f.write("Hello world!")
log_artifact("output.txt")
Run your code
cd project_repo
python example.py
By now the tracking API should have write data into files into your local ./mlruns directory.
To launch the MLFlow web interface execute
cd project_repo
mlflow ui
and view it at http://localhost:5000.
Retrieve the related PROJECT_NAME
on Neptune you want to collaborate or create a new one: https://ui.neptune.ai
Publish and share your experiments on Neptune
cd project_repo
neptune mlflow --project USER_NAME/PROJECT_NAME