Fleet Telematics: Driving Behaviour, Fuel, Maintenance and an In-Cab Camera
Fixed-effects panel · LightGBM · SHAP · Cost-sensitive alerts · Eye-state CNN · PERCLOS · ONNX int8 · MediaPipe · DuckDB · dbt · Spark · MLflow · Cluster-randomised design · 35 tests
The business question
A company that runs a connected fleet pays for diesel, for breakdowns on the road and for accidents. The telematics box and the camera in the cab already collect the data. Four questions turn it into money. Which driving habits raise fuel use once the vehicle, the road and the weather are taken out, and how much is a coaching programme worth in reais a month? Which trucks should go to the workshop this week, given that a missed failure costs far more than an early inspection? Can a small model on the camera tell when a driver’s eyes are closing, without sending any image out of the cab, and how far can its alarm be trusted? And how many trucks, branches and weeks does it take to prove that coaching saved 3% to 5% of fuel?
The data
Driving and fuel. The Vehicle Energy Dataset (VED) logged 383 private cars in Ann Arbor, Michigan, from November 2017 to November 2018 with OBD-II loggers: 22.4 million samples of GPS, speed, engine speed, load, air flow and fuel trims, about one every 0.6 seconds. The analysis keeps the 264 petrol cars, builds one row per trip, and keeps trips of at least 2 km and 3 minutes with fuel logged on 90% of the samples: 10,577 trips of 194 cars, 10.2 L/100 km on average. Fuel comes from the mass air flow corrected by the fuel trims, as the dataset’s authors do.
Maintenance. The SCANIA Component X data, released for the IDA 2024 Industrial Challenge: operational readouts (counters and histograms of 14 anonymised variables) of 23,550 trucks in training, 2,272 of which had Component X repaired during the study, plus validation and test files in which each truck’s history stops at a readout drawn at random, as it would when a model is used in practice.
Camera. The MRL Eye Dataset (Fusek, 2018): 84,898 infrared images of eyes of 37 people, captured by three different sensors, each labelled open or closed and with the person, glasses, reflections and lighting. A second camera checks the model out of its domain: the Annotated Drowsiness Detection Dataset captured with a Raspberry Pi 5 (Isworo and Liawatimena, 2025, CC BY 4.0), full-face frames in visible light with every eye boxed and labelled, split by the authors into training frames (158 closed and 968 open eyes) and testing frames (49 closed, 225 open) of the same three people.
Diesel price. ANP’s weekly survey of retail prices, diesel S10, state by state, week ending 28 November 2026: R$ 7.24 per litre on average across the country.
Try it
Set a driving profile and a fleet and see the predicted consumption and the diesel bill; follow a trip second by second with its harsh events; choose the alert threshold for the workshop and see what it catches and what it costs; see how the eye model’s errors turn into false drowsiness alarms, and run it live on your own webcam; and size the coaching trial. Nothing you enter or film leaves the page.
Method
From samples to trips (DuckDB and dbt). The weekly CSV files go to Parquet with DuckDB. Four dbt models then do the rest in SQL: fuel rate from air flow, increments between samples at most 5 seconds apart, acceleration over a window of 1.5 to 3 seconds (samples arrive every 0.1 to 2 seconds, and a one-sample difference turns speed noise into false events), and one row per trip. A harsh brake is a deceleration beyond 3 m/s², a harsh launch an acceleration beyond 2.5 m/s², each counted once at its start. Idling is time stopped with the engine running; speeding is time above 113 km/h (70 mph). Road type comes from GPS alone: each cell of about 220 m is a highway, an arterial or a local street by the median speed of every car that drove through it. Temperature is the fleet’s median for the day, since fewer than half the cars log it. A PySpark job computes the same trip totals and a test checks that both give identical numbers.
Behaviour or condition? A rough driver in a big car on short winter trips burns more fuel for reasons that are not the driving. The panel regression of L/100 km on the four habits and speed variability, with fixed effects for each car and each month and controls for temperature (and its square around 18 °C), road mix, trip length, average speed and stops per km, compares each car with itself. Standard errors are clustered by car.
Prediction out of time. LightGBM, trained on November 2017 to July 2018 and scored on August to November 2018, is set against two baselines: the car’s own average and the fixed-effects panel. SHAP values show what drives each prediction.
Maintenance. Each readout gets the counters, the counters per unit of time in use and their change since the previous readout. Training uses every readout in the 48 time units before a repair and four earlier ones per truck; a binary LightGBM gives the probability of failure within 48 units. Folds are grouped by truck. Because the training rows over-represent failures, the alert threshold is chosen on a copy of the training trucks cut at a random readout, like the validation file, by minimising the challenge’s own cost matrix (an alert costs 7 to 10, a missed or late failure 200 to 500). The validation file is touched only at the end.
Camera: eye state, then PERCLOS. A drowsiness alarm needs to know, many times a second, whether the eyes are open or closed; PERCLOS, the share of time with the eyes closed over the last minute, is the measure most used in fatigue research (Sommer and Golz, 2010). The eye model is a small convolutional network (four 3×3 blocks, about 60 thousand weights) on 48 × 48 grey crops, trained in PyTorch with flips, contrast and shift augmentation. Every evaluation keeps each person entirely on one side: five folds grouped by person, each image scored by a model that never saw that face. A logistic regression on the raw pixels goes through the same folds as the baseline, and once more on folds drawn at random, to measure how much a split that mixes people flatters a model. The model shipped to the page is trained on all 37 people, exported to ONNX and quantized to int8.
A classifier with hit rate TPR on closed eyes and false-alarm rate FPR on open eyes measures p·TPR + (1 − p)·FPR instead of the true closure share p. So what matters for the alarm is the error rate of each person, not the overall accuracy: the rates are computed person by person, for the 25 people with at least 100 images of each state.
Another camera. The model, without any retraining, is applied to the eye boxes of the Raspberry Pi frames. The crop size and the decision threshold are chosen on the dataset’s training frames and the results are read on its testing frames. They are the same three people in other frames, which is what a per-camera, per-driver calibration does in the first minutes of use.
On the device. In the app, MediaPipe’s Face Landmarker (Kartynnik et al., 2019) finds the eye corners in the webcam image, both eyes are cropped as tightly as the boxes that worked best, and the int8 model runs in the browser with onnxruntime-web.
Coaching trial. Coaching is assigned by branch, so that drivers who share a yard do not contaminate the control group. The variance of a branch’s mean consumption combines the spread between trucks of the same model, the share of it that is between branches (ICC) and the week-to-week noise of one truck; a two-sided test at 5% gives the power. The week-to-week and between-truck variation come from VED. Schall and Mohnen (2017) ran this kind of field experiment with company drivers.
Results
Idling and speeding cost the most per unit; harsh events add up. Within the same car and month, ten more harsh brakes per 100 km add 0.05 L/100 km (+0.5%), ten more harsh launches 0.03 L/100 km (+0.3%), ten more percentage points of time idling +0.26 L/100 km (+2.6%) and ten more points of moving time above 113 km/h +0.41 L/100 km (+4.0%); all are at least four standard errors from zero. Moving a driver from the 90th percentile of the fleet (59 harsh brakes and 104 harsh launches per 100 km, 35% of the time idling, 5% speeding) to the median would cut consumption by about 9.8%: on 50 trucks running 10,000 km a month at 35 L/100 km, about R$ 138 thousand a month at today’s ANP price. That is the upper end; a fleet whose drivers are near the median has much less to gain.
Out of time, the model beats the car’s own average by 44%. On 2,029 trips of August to November 2018, the mean absolute error is 0.80 L/100 km for LightGBM, 0.96 for the fixed-effects panel and 1.43 for the car’s average from earlier months (mean consumption 9.75). Average speed, engine size, engine speed and weight lead the SHAP ranking; among the habits, speed variability, harsh launches and idling come first.
Maintenance: a 20% cut against “inspect everything”, and the honest gap. On the 5,046 validation trucks (136 with a failure ahead), the threshold chosen on training data alone, 0.180, alerts 3,577 trucks, catches 124 of the 136 failures and costs 39,629 under the challenge’s matrix, against 49,566 for alerting every truck and 57,400 for never alerting. The best threshold in hindsight would cost 39,249, so the choice made before seeing the validation file loses little. Discrimination is modest: AUC 0.79 on held-out training trucks cut at random readouts, 0.64 on validation. With failures this rare and misses this expensive, the right policy alerts widely and lets the workshop sort: the value is in not missing failures, not in precision.
Camera: 95.1% on people it never saw, but the alarm depends on the person. Across the five person-grouped folds the eye model gets 95.1% of images right (AUC 0.989): it catches 95.0% of closed eyes and calls 4.7% of open eyes closed. The pixel baseline gets 87.0% (AUC 0.929); on folds drawn at random the same baseline reports 91.8%, so mixing people between training and test would have flattered it by almost five points. Glasses raise the false alarms on open eyes from 2.5% to 12.2%, strong reflections from 3.3% to 10.9%. The spread between people is the finding that matters for a product: the median person has 1.8% of open eyes called closed, the worst tenth 24%. For a driver whose eyes are truly closed 10% of the time, the measured PERCLOS ranges from 8.3% to 30.7% across people (10th to 90th percentile): without calibration, an alarm set at 15% fires all day for some drivers and never for others. The int8 file is 73 KB (244 KB in float), agrees with the float model on 99.85% of images and takes 0.17 ms per eye on one CPU thread.
On a camera it never saw, the ranking holds and the threshold moves. On the Raspberry Pi testing frames, ordinary visible light against the infrared of training, the AUC is 0.987. But at the default threshold the model catches only 63% of closed eyes (0.4% false alarms), so PERCLOS comes out low: a true 10% reads as 6.7%. With the threshold chosen on the training frames of the same camera, detection goes back to 90% with 3.6% false alarms, and the 10% reads as 12.2%. The tight eye box works best; a crop 2.4 times as wide drops the AUC to 0.90. Calibrating per camera and per driver is not a refinement, it is the step that makes the alarm usable.
A first version of this module tried to classify distraction (phone, texting) on a public photo set of 464 images. On capture sessions it never saw, it did worse than always guessing the most common class, because each class had been photographed in its own sessions and the scene gave the class away (51% with random folds, 15% with folds grouped by session). That failure is why every split here keeps a person, or a camera, on one side.
How big a trial. With 15 trucks per branch for 8 weeks, week-to-week variation of 10% and 12.8% between trucks of the same model, and an ICC of 0.1, detecting a 5% saving needs 17 branches per arm, 4% needs 27 and 3% needs 48, for 80% power. Most of the noise is between branches and trucks, not between weeks, so adding weeks helps less than adding branches.
Limits
The fuel effects come from private petrol cars, not loaded diesel trucks: the simulator applies them as a percentage change, which is a reasonable order of magnitude for idling and speeding and a weaker one for harsh events, whose cost grows with mass. The panel separates behaviour from the car, the month, the weather and the road type, but a driver who brakes hard may also choose busier roads in ways the GPS cells do not capture. Fuel is computed from air flow, not measured at the pump. Scania’s variables are anonymised and the challenge notes that repair and readout frequencies may have been altered, so the costs are in the challenge’s units. The eye model was trained on 37 people, mostly men, in infrared; the second camera has three people, and a webcam in daylight is a third domain, which is why the app uses the threshold recalibrated on visible light. PERCLOS from eye state alone does not see head nods or yawns, and the simulator’s blinks and microsleeps are synthetic. The trial planner assumes the coaching effect is the same in every branch.
Applied to your business
This is the Custom Forecasting package applied to fleet telematics. On your own trips, workshop records and cameras, the same pieces give a driver score that separates habit from route and vehicle, the reais at stake per habit, a workshop alert tuned to what a breakdown costs you, a drowsiness alarm that runs on the camera and is calibrated per camera and per driver, and a coaching trial sized before it starts.
Code
github.com/rhozon/fleet-telematics-analytics
pip install -e ".[dev,ml]"
pytest -v
python -m fleet.cli ved # VED to Parquet (DuckDB), then dbt build
python -m fleet.cli drive # panel, LightGBM out of time, SHAP (MLflow)
python -m fleet.cli scania # failure risk and alert threshold
python -m fleet.cli eyes # eye state by person-grouped folds, ONNX int8, latency
python -m fleet.cli eyes-cross # the same model on the Raspberry Pi camera, crop and threshold
python -m fleet.cli camera # first version: distraction photos, kept for the record
python -m fleet.cli anp # diesel S10 prices
python -m fleet.cli export # data for the pageReferences
Data: Oh, LeBlanc and Peng, Vehicle Energy Dataset (Apache-2.0); Scania CV AB, SCANIA Component X dataset, Swedish National Data Service (CC BY 4.0); Fusek, MRL Eye Dataset; Isworo and Liawatimena, Annotated Drowsiness Detection Dataset captured using Raspberry Pi 5, Mendeley Data (CC BY 4.0); Sahin Afridi et al., Driver Behavior Image Dataset, Mendeley Data (CC BY 4.0, first version); ANP, Levantamento de Preços de Combustíveis, weekly series by state.
- Ayuso, M., Guillen, M. and Nielsen, J. P. (2019). Improving automobile insurance ratemaking using telematics: incorporating mileage and driver behaviour data. Transportation, 46(3), 735-752. doi:10.1007/s11116-018-9890-7
- Barkenbus, J. N. (2010). Eco-driving: An overlooked climate change initiative. Energy Policy, 38(2), 762-769. doi:10.1016/j.enpol.2009.10.021
- Fusek, R. (2018). Pupil Localization Using Geodesic Distance. Lecture Notes in Computer Science, 433-444. doi:10.1007/978-3-030-03801-4_38
- Guo, F. and Fang, Y. (2013). Individual driver risk assessment using naturalistic driving data. Accident Analysis & Prevention, 61, 3-9. doi:10.1016/j.aap.2012.06.014
- Huang, Y., Ng, E. C. Y., Zhou, J. L., Surawski, N. C., Chan, E. F. C. and Hong, G. (2018). Eco-driving technology for sustainable road transport: A review. Renewable and Sustainable Energy Reviews, 93, 596-609. doi:10.1016/j.rser.2018.05.030
- Isworo, N. and Liawatimena, S. (2025). Annotated Drowsiness Detection Dataset Captured Using Raspberry Pi 5. Mendeley Data. doi:10.17632/chvz7vh2dc.1
- Kartynnik, Y., Ablavatski, A., Grishchenko, I. and Grundmann, M. (2019). Real-time Facial Surface Geometry from Monocular Video on Mobile GPUs. arXiv. doi:10.48550/arXiv.1907.06724
- Kharazian, Z., Lindgren, T., Magnússon, S., Steinert, O. and Andersson Reyna, O. (2025). SCANIA Component X dataset: a real-world multivariate time series dataset for predictive maintenance. Scientific Data, 12(1). doi:10.1038/s41597-025-04802-6
- Lindgren, T., Steinert, O., Andersson Reyna, O., Kharazian, Z. and Magnússon, S. (2024). SCANIA Component X Dataset: A Real-World Multivariate Time Series Dataset for Predictive Maintenance. Scania CV AB. doi:10.5878/jvb5-d390
- Oh, G., Leblanc, D. J. and Peng, H. (2022). Vehicle Energy Dataset (VED), A Large-Scale Dataset for Vehicle Energy Consumption Research. IEEE Transactions on Intelligent Transportation Systems, 23(4), 3302-3312. doi:10.1109/TITS.2020.3035596
- Ortega, J. D., Kose, N., Cañas, P., Chao, M. A., Unnervik, A., Nieto, M. et al. (2020). DMD: A Large-Scale Multi-modal Driver Monitoring Dataset for Attention and Alertness Analysis. Lecture Notes in Computer Science, 387-405. doi:10.1007/978-3-030-66823-5_23
- Prytz, R., Nowaczyk, S., Rögnvaldsson, T. and Byttner, S. (2015). Predicting the need for vehicle compressor repairs using maintenance records and logged vehicle data. Engineering Applications of Artificial Intelligence, 41, 139-150. doi:10.1016/j.engappai.2015.02.009
- Romera, E., Bergasa, L. M. and Arroyo, R. (2016). Need data for driver behaviour analysis? Presenting the public UAH-DriveSet. 2016 IEEE 19th International Conference on Intelligent Transportation Systems (ITSC), 387-392. doi:10.1109/ITSC.2016.7795584
- Sahin Afridi, A., Kafy, A., Nessa Moon, M. N. and Shakil, M. S. (2024). Driver Behavior Image Dataset. Mendeley Data. doi:10.17632/6y3g6vs2k4.2
- Sandler, M., Howard, A., Zhu, M., Zhmoginov, A. and Chen, L. C. (2018). MobileNetV2: Inverted Residuals and Linear Bottlenecks. 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition, 4510-4520. doi:10.1109/CVPR.2018.00474
- Schall, D. L. and Mohnen, A. (2017). Incentivizing energy-efficient behavior at work: An empirical investigation using a natural field experiment on eco-driving. Applied Energy, 185, 1757-1768. doi:10.1016/j.apenergy.2015.10.163
- Sommer, D. and Golz, M. (2010). Evaluation of PERCLOS based current fatigue monitoring technologies. 2010 Annual International Conference of the IEEE Engineering in Medicine and Biology, 4456-4459. doi:10.1109/iembs.2010.5625960