Predicting Distracted Driving

Using Machine Learning and Sensor Data to Detect Distracted Driving for a Mobile Safety App

Problem Statement

Copernicus, a startup focused on mobile safety innovations, approached us with a unique challenge: could we detect whether a person texting on their iPhone was the driver or a passenger? Their goal was to develop an iOS keyboard that would notify users—or their parents—if someone was texting while driving. The core technical hurdle was distinguishing driver activity from passenger behavior using only sensor data captured during texting.

Situation

Copernicus had developed a custom iOS keyboard capable of recording each keypress along with real-time phone sensor data, including speed, yaw, pitch, and roll. While this rich stream of data offered potential, it was unstructured and not yet organized for analysis. Our task was to convert raw keystroke and sensor data into usable insights, and to train a model that could accurately classify whether a user was texting as a driver or passenger.

Summary

Marketing Science partnered with Copernicus to build a machine learning model that could detect whether someone texting on their phone was a driver or a passenger using keystroke and motion sensor data. The resulting decision tree model achieved 98% accuracy, enabling real-time distracted driving detection and laying the foundation for a safety-focused mobile keyboard app.

Key results

  • Achieved 98% accuracy in detecting driver vs. passenger texting behavior using a custom decision tree model.
  • Enabled real-time, sensor-driven distracted driving detection, supporting the launch of a safety-focused mobile keyboard app.

Solution

Our first step was to structure the incoming data. We collected individual keystrokes into a keystrokes table and grouped them into a higher-level sentences table, based on timing and device movement patterns between characters. This allowed us to analyze behavior on a per-message level rather than per-tap.

With structured data in place, we explored feature engineering by calculating averages and variances in yaw, pitch, roll, and typing speed for each sentence. These features were then used to build two machine learning models: a decision tree and a logistic regression classifier. This dual-model approach allowed us to compare accuracy and interpretability, and to evaluate whether an ensemble method might further improve performance.

The decision tree model used features such as char_count, time_delta, yaw_ave, roll_ave, pitch_ave, yaw_var, pitch_var, roll_var, speed_ave, and a binary label (driver vs. passenger). This approach enabled transparent, rule-based classification tailored to user behavior.

Results

The decision tree model achieved 98% accuracy, outperforming the logistic regression model at 95% accuracy. Based on this performance, we recommended that Copernicus move forward with the decision tree model while continuing to retrain and refine it as more user data becomes available.

Decision Tree model generated from trained data

This model gave Copernicus a clear path forward for enabling real-time detection of driver texting behavior—a key differentiator for their safety-focused keyboard app and a promising step toward improving road safety through data-driven design.

Machine Learning Capability

Marketing Science applies machine learning to help clients uncover patterns, predict outcomes, and automate decision-making using their existing data. From customer behavior modeling to operational risk detection, we design tailored ML solutions that turn complex data into measurable business value.

Solving Complex Problems

Marketing Science specializes in translating complex technical challenges into practical, scalable solutions that drive business outcomes. Whether it’s structuring messy data, integrating advanced analytics, or building custom models, we turn technical complexity into actionable insights that fuel growth, efficiency, and innovation.