The scikit-learn phase-classifier model (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Xander44-4/traffic_reducer/llms.txt
Use this file to discover all available pages before exploring further.
modelo_semaforo_ia.pkl) was trained on a fully synthetic dataset that maps four-direction vehicle counts to the expected winning signal phase. The model is loaded at server startup by app.py; its presence is required for the /predict endpoint to respond — the endpoint returns 500 if the model failed to load.
Dataset file
Schema
| Column | Type | Range | Description |
|---|---|---|---|
Norte | int | 0–59 | Vehicle count in the North lane |
Sur | int | 0–59 | Vehicle count in the South lane |
Este | int | 0–59 | Vehicle count in the East lane |
Oeste | int | 0–59 | Vehicle count in the West lane |
GANADOR_ESPERADO | int | 0–3 | Expected winning phase (0 = Norte, 1 = Sur, 2 = Este, 3 = Oeste) |
Sample rows
Label generation logic
GANADOR_ESPERADO is always the index of the maximum count across the four directions:
49,38,53,13 → argmax([49,38,53,13]) = index 2 (Este). The dataset encodes a strict majority-rule policy: whichever direction has the most vehicles gets the green phase. There are no tie-breaking rules in the synthetic data; ties are avoided by construction during generation.
Because the dataset is purely synthetic and labels are always
argmax, any reasonable classifier achieves near-100% accuracy. The real intelligence of Traffic Reducer lies in the YOLOv8 vehicle detection pipeline, not the phase classifier. The classifier’s job is simply to formalise the argmax rule as a trained artifact that can be swapped for a more sophisticated policy in the future.Loading and testing the model
pickle.load raises an error (e.g., the file was saved with joblib), use joblib.load instead — app.py tries both automatically:
Retraining with scikit-learn
To retrain the classifier from scratch — for example after extending the dataset or switching algorithms — run the following script from the project root:traffic_app/app.py so the new model is picked up at startup. The MODEL_PATH variable in app.py must point to the correct absolute path on your machine.