Classification of keystrokes A year or two ago I wrote a keylogger that has been quietly running in the background of my computer. Each line consists of a timestamp, a keycode, and a value representing modifier keys (e.g. ctrl, shift, etc.).

Separately, I have a web app that I use to manually make notes about how I spend my time: TaskRanger.com



As you can see in this screenshot, Task Ranger is basically a daily log of work done. Each day consists of a list of intervals. Each interval consists of a start time, a duration, and a string briefly describing the work I did during that period. The description also contains a twitter style hashtag that manually classifies the type of work I was doing.

I'm interested in combining both of these data sources to create a classifier that can take a raw log of keystrokes as input and output a sequence of tags indicating the type of work I did over time. For example, I might have been doing research from 11am to 1pm, then planning a project from 1pm to 2:30, then alternating between coding and debugging for the next few hours, etc.

The intent is to basically build a personal profiler. I want to become more productive. And I think I ought to be able to treat my workflow as a software program: figure out what the bottlenecks are, drill down into them, and focus my improvement efforts on those areas.

I tried to build some kind of naive classifier myself without much luck. One problem is I couldn't find an easy way to figure out when one kind of work ends and the next kind begins (segmentation I think it's called?). I think this whole classification task might be a lot harder than it initially seems. I have this vague idea that a Hidden Markov Model should work. Basically the type of work that I'm doing is a hidden state, and the keylogs provide clues as to that state. But I know next to nothing about signal processing or machine learning, so I'm not sure if I'm on the right track here.

Any advice or suggestions on how to build this would be appreciated. Some sample code demonstrating something similar would be especially useful.
Looks like you have a classification problem. A simple way to solve this is with a linear regression model. Here is how I would do that with the data you've provided:

1) Determine a "unit" of time, for example 1 minute of keystrokes. Once this process is complete you can tweak the unit of time to see if different intervals give you better results (5 minutes, 10 minutes, etc...)

2) Split all keystrokes into 1 minute chunks, and categorize those chunks as work, study, play, etc... Now you basically have a bunch of character strings that are categorized into activity types.

3) Create variables to describe your chunks. Word count, character count, wpm, # of times "lol" was typed, etc...Get creative.

4) Create a test set and training set of chunks.

5) Create a linear regression model to predict type of activity based upon the variables you created.

This is a pretty simple solution but if you can come up with good variables to distinguish your activity types it can work.