CoolFace
Apppublic

EnYa32/AccidentRiskPredictor

sourceHugging Facemitupdated 9mo agoView on Hugging Face
0likes
App README

๐Ÿš— Road Accident Risk Predictor (LightGBM)

This Streamlit app predicts accident_risk (0โ€“1) using a trained LightGBM regression model.

What this app does

  • โ€”Takes road & environment features (road type, lanes, curvature, speed limit, weather, lighting, etc.)
  • โ€”Applies the same feature engineering used in training:
  • โ€”curvature_speed
  • โ€”lanes_speed
  • โ€”accidents_lane
  • โ€”holiday_school
  • โ€”signs_public
  • โ€”Encodes categorical variables with one-hot encoding (pd.get_dummies(drop_first=True))
  • โ€”Aligns final features using the saved list in feature_names.pkl
  • โ€”Outputs a risk score between 0 and 1

Files you must have in the repo root

  • โ€”app.py
  • โ€”lgbm_model.pkl (trained model)
  • โ€”feature_names.pkl (list of training feature columns)
  • โ€”requirements.txt

Run locally

bash
pip install -r requirements.txt
streamlit run app.py
How to use
Manual input
Fill the form and click Predict.

CSV upload
Upload a CSV with the raw columns like Kaggle test.csv (without accident_risk).
The app returns a file with an additional column: accident_risk_pred.

Expected input columns (raw)
road_type (highway/urban/rural)

num_lanes

curvature

speed_limit

lighting (daylight/dim/night)

weather (clear/foggy/rainy)

road_signs_present (True/False or 0/1)

public_road (True/False or 0/1)

time_of_day (morning/afternoon/evening)

holiday (True/False or 0/1)

school_season (True/False or 0/1)

num_reported_accidents

Notes
Predictions are clipped to [0, 1] to match the target range.

For deployment, aligning columns via feature_names.pkl is critical to avoid feature mismatch.