# identifying events (patterns) that occur before an event of interest using sequence of events data

I'm interested in identifying events (patterns) that occur before an event of interest.

For example, a customer calls in to complain or a customer checks their balance online then the customer closes the account (event of interest). Data is in a form of a sequence of events with a time stamp.

I would like to know what methodologies (and software) people are using for such a task.

I'm open to exact patterns (sequence of events), frequency of events (calls in multiple times to complain), and timing of events (80% of event A leads directly to event of interest within X days). Basically, open to any approach people are using to identify patterns leading up to an event.

Thus far I found the CSPADE algorithm as available in the arulesSequences package in R. It seems to be able to identify sequence of patterns and which items co-occur. However, I don't think one can set a target event for it to find a pattern.

I'm open to algorithms available in R, Python, or SAS.

Thanks so much!

• All of the models you list are possible, but please specify whether the "timing of events" is important or not. If timing doesn't matter, your problem is one of supervised learning (classification); if timing does matter, you need to use survival analysis. Both are perfectly do-able, but they will lead to entirely different answers (survival will be messier in this case). Unless timing information is critically important to your application, I would recommend using classification models. Please update with this information and you will receive better answers suitably tailored to your problem. – ahfoss Jan 27 '14 at 16:41
• As you discovered, Spade and other data mining algorithms won't help you, they aren't made for what you're after. – iliasfl Jan 29 '14 at 10:08
• @ahfoss Time component can be incorporated in a classification scheme. In the question's setup you can measure time between events (any event or specific ones); number of events per some unit of time; time from first occurrence of event X from start of customer history; time until first complain in customer life-time, etc. – iliasfl Jan 29 '14 at 10:12
• @iliasfl I should have been more specific. My question refers to the outcome variable, not features. Predicting which or whether an event of interest happens requires a classification scheme, whereas predicting time to an event of interest is survival analysis; two substantially different tasks. – ahfoss Jan 30 '14 at 13:52

I start with approaches you can use to interpret what's going on: You will need to make a script to extract from the full dataset the sequences of length $n$ that lead to the event you are interested in. If $n$ is low and you have enough data you can measure frequencies of all combinations of events that lead to the event of interest. If situation is a bit more complex and there are no clear winners, you could try visualise these series of events using a tree as a form of a Markov chain. Using some ad-hoc cleaning, like removing edges with $p<0.1$, you could end-up with something actionable.