Supervised vs. Unsupervised Learning
You will first need to decide whether to approach this as a
unsupervised learning problem.
supervised learning, you would need to take some portion of the data and hand score it as harsh/aggressive and normal. I suggest you not go this route to start. But if you do, I suggest using a
support vector classifier for your initial testing.
I suggest approaching this as an
unsupervised learning problem. Assuming you tend to be a normal/safe driver you can view this behavior as normal and harsh/aggressive driving as an
anomaly or an
outlier. This is known as outlier detection.
Feature engineering will play a significant roll in this problem. Despite your attention to the longitudinal and lateral axes of the car, the phone will have arbitrary orientation within the car i.e. it will just be in your pocket. Thus its probably best to factor out the direction somewhat.
First, I would find the length of the acceleration vector (magnitude of acceleration without regard to its directional orientation). Since you have three orthogonal axes, you can just use:
Additionally, you can also integrate the acceleration vector over time and find its magnitude to find the vehicle speed:
The speed is very useful in determining the difference between different modes of acceleration e.g. driving around in a circle will yield constant acceleration, but also constant speed vs. holding down the gas pedal and driving straight, which could yield constant acceleration with changing speed.
An important aspect of this method lies in the fact that integrals of your data will tend to damp noise, where as derivatives (differences) will tend to amplify noise. Don't take derivatives of your data.
At this point you can normalize the speed and acceleration-magnitude and find the mean and standard deviation of both values. When your normalized speed and acceleration-magnitude lies outside of some z-value, say two standard deviations, then you can classify your driving as dangerous.
Don't forget to think of speed and acceleration as orthogonal values and form a circular function out of the respective z-values for proper outlier detection. You can read about 2D or nD outlier detection and also here
Remember that the equation for a circle is:
We can therefore solve for $r$ and set it equal to $2$ standard deviations.
As an aside, note that since variance is just the square of the standard deviation, you could alternatively think of this in terms of variance.
Now for two standard deviations, the driving is aggressive if:
The online learning component simply requires that you continuously update the means and standard deviations. Though, I suggest that this be done in some sort of batch mode rather than continuously.
Hope this helps!