Thursday, December 29, 2016

Are you getting paid enough for your good looks and charming personality?


All resources referenced in this post can be found here.

I have obtained salary information for a large number of people and it can be used to answer the important question in the title

Created with married_couple_salary_diff.py

With the information in the diagram above you can check if your relationship is competitive or not. Use the following process.
  1. If money is excluded how does the balance look in your relationship?
  2. What is the probability of finding a couple with an equal or worse imbalance? The direction is important here, whether the man or woman is the "winner".

    If there where only 10 couples with the following imbalances



    ... the probabilities would look like this.

    c1 probability = 1 / 10 = 0.1
    c2 probability = 2 / 10 = 0.2
    c4 probability = 7 / 10 = 0.7
    c6 probability = 5 / 10 = 0.5
  3. Locate the probability found in step 2 on the y-axis and read out the factor on the x-axis
Lets do an example. Alice wants to see if her marriage is competitive. If money is excluded she thinks she is a bit "better" than her husband Bob. Alice estimates that the woman is at least this much better than the man in 20% of all marriages. Looking at the diagram she sees that Bob should be making ~2.15 times as much as she does, which is the case, so no action needed.

How did I get hold of the data? The information originally comes from the Swedish tax authorities but to get hold of it in large quantities you need to buy it in book form, "Taxeringskalendern". To save space in the book people with low income have been filtered out, but the limits are pretty low so almost everyone working should be in there.

To use the information for anything more sophisticated than checking how much money your neighbor makes you need the data in digital form. To do this I shot a movie while flipping through the book and ran Tesseract (OCR software) on every frame (parse_tax_records.py). This approach worked pretty poorly but I managed to collect enough information to do the analysis in this post. I think the poor performance was mainly due to the book's content not being in Tesseract's dictionary and the font being really dense.

As a bonus I give you the salary distribution in the Malmö/Lund area, derived from the same data.

Created with salary_distribution.py

Estimate the likelihood of finding someone equal or better than you in the workforce (everyone working, not just your profession), locate the likelihood on the y-axis and read out the salary you should have on the x-axis.

Sunday, December 18, 2016

Better voice recognition

Edited 20180121

Code, a trained network, and training/testing data can be found here.

I have previously done voice recognition with my audio classifier network (here), and that has worked well, but the network can only recognize voices it has been trained to recognize. The goal here is to be able to label previously unheard voices. To achieve this I have constructed a network that takes two voice samples as inputs and outputs whether they came from the same person or not. By running the network extensively over an audio file and doing some clustering the voices in the file can be labeled (more details in voice_recognition.py).

Input 1.1
2 x loudness adjusted spectrograms (65-3500Hz, 4096 window size, 40ms step, logarithmic scale for amplitudes) created from 2.5 seconds of 44.1kHz, 16-bit mono audio.

Rather than having the amplitudes in the "value" dimension a new third dimension has been added to the spectrograms that holds the amplitudes (the value dimension is unused and will always be 0 or 1). The reason for this is that a single filter is very good at detecting if something is present or not, but it can not detect that A and B should both be present and A should be exactly twice as strong as B, i.e. the filters have poor expressiveness in the value dimension.

Amplitude normalization is done per spectrum rather than over the entire spectrogram. This makes it easier to detect amplitude patterns over frequencies. The downside is that temporal amplitude patterns are lost.

Pitch has been normalized to make timbre detection easier. Pitchless sounds, like the short t sound, are destroyed by this process and are handled separately in layer 1.3.

Layer 1.1
200ms filters that are swept over the spectrograms and pooled to one value (per spectrogram).

The idea is that these filters will capture timbre features that can be used to separate voices. Such a feature would be continuously present in many voices but not in all voices. Typically each filter would be able to split voices into two classes and by using multiple filters a very good separation can be achieved. In a perfect world 10 filters could split voices into 2^10=1024 classes.

Input 1.2
Same as input 1.1 but without all the unusual stuff, i.e. 2-d, amplitude normalization over the entire spectrogram, and no pitch normalization.

Layer 1.2
Same as layer 1.1 but with a focus on pitch features.

Input 1.3
Same as input 1.1 but without pitch normalization and with a 2048 window size and a 20ms step to get more temporal resolution and less frequency resolution.

Layer 1.3
Same as layer 1.1 but for pitchless sounds.

Each layer 1 filter outputs a match value for voice sample 1 and a match value for voice sample 2. The difference between the match values is calculated so that we have a diff for each filter. All the filter diffs are then added up and if the sum is smaller than X the voice samples are from the same person.

I wrote some code to test how well humans perform this task, to get a target to aim for, and the results are:

python3 voice_recognition.py --test-human-performance voice_data/training_1/* voice_data/training_2/*

Known language, 67 voices, ~110 iterations: 97.3%
Unknown language, 13 voices, ~60 iterations: 98.9%

My network produced the following results after training. The training data was 89 well recorded (english) voices, a few minutes of each.

python3 voice_recognition.py --train voice_data/training_1/* voice_data/training_2/* voice_data/training_3/*

Training data: 92%
Test data: 85%

Below is a video of the network labeling never before seen data.

python3 voice_recognition.py test.raw


Labeling the training data looks like this.


I experimented with other inputs like cepstrograms and waveforms, but they worked worse than spectrograms. Applying filters directly on the waveform was found to not work well with gradient descent optimization. The problem is that the frequency the filter is trying to find will exist in many different phases in a batch and the gradients from the different versions will cancel each other out.

I also tried to use spectrograms with phase information as input but this did not improve performance. The phases where normalized in such a way that the component with the highest magnitude in each spectrum had a zero phase. This should make the filters able to detect phase differences between overtones.

Monday, December 5, 2016

Using class distribution in the training data as optimization target

All resources referenced in this post can be found here.

In my audio classification network (post) every single example needs to be labeled. Labeling is very time consuming, and boring, so I would like to avoid it as much as possible. If the class distribution in the training data is known one could possibly use that as an optimization target and thereby label the entire training data at once. You would tell the network to split the training data into, for example, 2 classes with the probabilities 0.3 and 0.7. Hopefully the network splits the data the way you intended to.

The training data could be a news show where you know the anchorman speaks 20% of the time. To train the network to identify the anchorman's voice you would use x number of shows as training data and tell the network to split them into two classes with the probabilities 0.2 and 0.8. The 0.2 class will probably be assigned to the anchorman's voice.

Using the probability that a class wins in a loss function is not possible as it is not smooth. For the probability to change one example needs to change class and at that time the probability will jump to a new value. The result of this is a terraced search space where the gradient is either 0 or infinity at all positions. A gradient descent optimizer will not work in such a search space.

To work around this problem I used a composite loss function that looked at two things.
  1. The mean of the class probabilities for all the examples. In the news show example you would be aiming for 0.2, 0.8. Notice that this does not necessarily mean that class 0 has won 20% of the time and class 1 has won 80% of the time. If every example has generated the probabilities 0.2, 0.8 class 1 has won 100% of the time but the mean of the class probabilities is 0.2, 0.8.
  2. The standard deviation of the probabilities in one class. For class 0 in the new show example you would want 20% of the probabilities to be 1 and the rest 0. For class 1 you would want 80% of the probabilities to be 1 and the rest 0.
When combined the search space will be smooth and the minima will be correctly placed. For more detailed information look at the code in audio_classifier.py.

To test this idea I used my audio classifier network and the same Nathan Englander data I used last time. I just put the training data for both classes in one file and used the new class distribution loss function.

python audio_classifier.py --train --labeled-data-weight 0.0 nathan_data/nathan_englander_and_other.raw 0.135 0.865 nathan_data/nathan_englander_short.raw nathan_data/other_short.raw

The result looks as follows.

Interview with Nathan Englander
Nathan Englander reading a book
Interview with Ariana Grande
Dialog from the Ex Machina movie
Interview with Samuel L. Jackson
Skrillex - Bangarang
Will Self reading a book

The network has split the data the way I wanted it to but the accuracy is not as good as with labeled training data. Not sure why the accuracy dropped but it did not look like more training was going to fix it.

Adding some labeled data could possibly steer the solution in the right direction and increase the accuracy without requiring a lot of manual labor. Below I have labeled 2% of the training data.

python audio_classifier.py --train nathan_data/nathan_englander_and_other.raw 0.135 0.865 nathan_data/nathan_englander_short.raw nathan_data/other_short.raw

Interview with Nathan Englander
Nathan Englander reading a book
Interview with Ariana Grande
Dialog from the Ex Machina movie
Interview with Samuel L. Jackson
Skrillex - Bangarang
Will Self reading a book


Better. But still a bit worse than with fully labeled training data.

It would also be interesting to see how well the 2% set of the training data does on its own, without the class distribution. Maybe the class distribution only makes things worse. So I tried that also.

python audio_classifier.py --train --labeled-data-weight 1.0 nathan_data/nathan_englander_and_other.raw 0.135 0.865 nathan_data/nathan_englander_short.raw nathan_data/other_short.raw

Interview with Nathan Englander
Nathan Englander reading a book
Interview with Ariana Grande
Dialog from the Ex Machine movie
Interview with Samuel L Jackson
Skrillex - Bangarang
Will Self reading a book


It actually works much better than I expected. The mixed version is better, but not by much.

Sunday, November 20, 2016

Some political ideas

Price stability

With constant inflation prices change all the time and one can not intuitively tell if a price change was caused by the inflation or if there was a real underlying cause such as political decisions, or a change in supply or demand. This is not good as the results of poor political decisions may be hidden by the inflation fog.

Without inflation the prices would be stable. No one would expect the prices to change so if they did it would draw a lot of attention and people would want to know why. If the cause was poor political decisions people would take actions to halt the negative development.

No government lending

Most people don't care at all about politics unless their everyday life is affected. Because of this it is important that the result of a political decision is visible in peoples' lives as soon as possible to be able to halt a negative development early. Lending makes the government able to delay the effects of bad decisions, so that possibility should be removed. If the government needs money as a result of poor decisions it should raise the taxes, which will be visible to the voters.

Only tax people, not companies

A tax on a company is just a hidden tax on the people. A favorite is to put new taxes on the banks, cause no one likes them, but the banks just raise the price of their services and the actual cost ends up on the people.

Tax bill every month

Here in Sweden the taxation is "hidden" to a large degree, company taxes, sales tax that is included in the price, pre-deducted income tax, etc. It's a very successful strategy. Most people have no idea how much they pay in taxes. In many cases they don't even understand that they pay taxes as it is all automatic. They never transfered any money to the government so its not real to them. This is of course very bad. To be able to evaluate how well the system works you need to know how much you put in and how much you get out.

I suggest we delay all taxes to the end of the month, at which point you get a well specified bill that you need to pay, just like for your rent. This would make it very clear how much you pay, to whom, and that if the tax was lower you could have used that money for something else.

Government transparency

The idea here is that if everyone can monitor the government problems can be detected and fixed at an earlier stage. It's an old idea that many countries already have implemented. The problem, at least here in Sweden, is that the laws have not evolved with the technology. You can get all the information but you need to request it personally from the correct branch of the government and then you get it in paper form. Not a great system if you want to do automatic analysis. All the data should be made easily available in a form that enables automatic analysis. If this is done I'm sure people will come up with clever ways to automatically monitor the government that will be beneficial to us all.

One thing I would like to try is to analyze the bid spread in government procurements. Is any company winning by too little too often? Presumably because they have inside information. Is any company winning by too much? Could be an indication that the procurement was tuned for that company.

Monday, October 24, 2016

Audio classification with a convolutional neural network

Edited 20161120

All resources referenced in this post can be found here.

As the title says I have been experimenting with audio classification with a convolutional neural network. Input to the network is loudness adjusted spectrograms. The spectrograms cover 65-3500Hz for two seconds. The temporal resolution is 40ms and the frequency resolution is ~11Hz, 48x319 values.

The network looks like this:

80 6x250 (240ms x 2692Hz) filters that are supposed to capture overtone features (timbre)
ReLU
3x1 max pooling to keep the network size down
40 8x70 (960ms x 754Hz) filters that are supposed to capture longer temporal features
ReLU
Max pooling to one value

The classes are populated from the layer 2 outputs according to a weight vector for each class and then converted to probabilities using softmax. The network contains ~1.9 million trainable variables and performs ~377 million operations.

The loss function is the mean of the cross entropies between the expected probability distribution and the actual probability distribution for each example.

For more detailed information check out audio_classifier.py.

To test it all out I decided to train the network to recognize Nathan Englander's voice. To do this I used two classes. One class for Nathan's voice, which was trained on 50 minutes of Nathan's voice from three different recordings. Another class for everything else, which was trained on 5 hours of audio not containing Nathan's voice (music, sound from Youtube and movies, book readings, etc).

python audio_classifier.py --train 2 nathan_englander.raw other.raw

The network quickly achieved 100% accuracy on the training data, something like 10-20 hours on my i5-4460.

The following images show the performance on the test data. None of the test data is present in the training data. No person, except Nathan Englander, and no recording exists in both data sets.

python audio_classifier.py 2 nathan_englander_interview.raw

Interview with Nathan Englander
Nathan Englander reading a book
Interview with Ariana Grande
Dialog from the Ex Machina movie
Interview with Samuel L. Jackson
Skrillex - Bangarang
Will Self reading a book

Wednesday, September 28, 2016

Tired of buying clothes?

Updating your wardrobe can be quite the chore. Crowded shops, queues to the fitting rooms, scrolling through endless pages of clothes in the online shops, sending things back, garments shrinking, etc. Wouldn't it be great if you could find someone that looks, and dresses, roughly like you and just copy all his purchases. If you are a male, 181cm , 71.5kg, and looking for casual style clothes you are in luck. You can now copy all my purchases for autumn/winter 2016, check it out on the link below.

http://www.shopeasy.one

Saturday, August 27, 2016

A new way to navigate countryside backroads and trails

One of my hobbies is scenic countryside trips on my mountain bike. I usually plan the route manually on Swedish map service eniro.se which have quite detailed maps, including really small roads and trails. The problem is the navigation. Eniro have a navigation application but you have little control over the route and the application sometimes routes poorly in walk mode, so I developed an alternative, and it works as follows.

You define the route by drawing three point polylines indicating your path through junctions. This can be done in Eniro maps, the option can be found in the ruler menu in the lower right corner. The waypoints need to be pretty accurate for good performance so this step is best done on a desktop/laptop. Should look something like this.



When you are done save all the polylines in a GeoJSON file, also in the ruler menu. The route is now done.

Next install my Android application which can be found here. In the application load the route and set off. When you reach a marked junction the application will issue navigation cues, either as speech, or vibration patterns if the media volume is zero. Uploading the route file to Google drive is a good way to make it accessible from your phone.

An example route around the lake Immeln can be found here. To view it just drop the file in Eniro maps. This route contains straight ahead cues and should therefore only be used with speech navigation. Vibration navigation only tells you left or right, not the actual bearing change, and is therefore not suitable for straight ahead cues.

One thing to keep in mind when opening existing routes by dropping them into Eniro maps is that you can't edit them due to a bug in Eniro maps where it will only save polylines drawn in the current session. So if you open a route, add a few polylines and do "download all" only the new polylines will be stored, not the ones originating from the opened file.

Other map services can also be used, so long as they support drawing polylines and saving them in GeoJSON.

Thursday, August 25, 2016

Figuring out my neighbors' schedules from leaking sound

All resources referenced in this post can be found here.

Unfortunately there is a fair amount of sound leakage between the apartments where I live. Mostly thuds originating from people closing doors, windows, cupboards, etc. If I stored metadata about every single thud in a database I could possibly get some interesting information from that data, such as my neighbors' schedules.

I decided to give this a try. For the recording I used a cheap stereo sound recorder (Olympus LS-12). To filter out the external sounds I had to write some code, process_recording.py. When sound passes through a wall or floor it is distorted, higher frequencies are dampened more than lower frequencies, so a lack of high frequency content is an indication that the sound may be external. The script works according to this principle, it looks at the frequency distribution and makes a decision on whether the sound originated from my neighbors or not. This worked pretty well in my environment, the false positive rate is close to 0% and the false negative rate is ~50%.

The "detect external sounds" algorithm ended up having 8 parameters that needed to be tuned. For the tuning I used a hill climbing approach. I constructed a tuning recording with 62 thuds and about an hour of environment sound. The tuning script randomly adjusted the parameters, processed the tuning recording, evaluated the result, and kept only the successful adjustments. This ran until I decided the tuning was good enough. A few days if I remember correctly. See tune.py for details.

Since I had a stereo sound recorder I thought it would be interesting to add sound angle to the metadata, to see if I could identify any sound source, so I did. The implementation uses phase correlation to get the delay between the channels and can be found in process_recording.py.

I couldn't find any tools suitable for analyzing the gathered data so I had to write some myself. The first one shows the number of thuds per hour over time, see sounds_per_hour.py for details.



As can be seen I did not chose the best time to gather data. First of all it was vacation times in Sweden, where I live, so people may be a bit less schedule bound than usually. Secondly there are some non-standard events in the period, a new neighbor moving in and repairs being done on the building.

My second analysis tool can select and show sounds according to a temporal pattern. The exact details on how it works are a bit difficult to explain but it can for example show you all weekdays combined into one diagram, or all Saturdays combined into one diagram. The implementation can be found in sound_viewer.py.

Lets start by looking at the angles for all sounds.



The banding is an expected result of the algorithm that calculates the sound angles so that can be disregarded.

A lot of action on the negative angles with a peak at -10 degrees. Unfortunately that does not point out any specific neighbor as both my neighboring apartments cover those angles.

Next lets look at how the thuds are distributed over time. Here are two diagrams showing how thuds are distributed over the day on Mondays to Fridays.


Someone gets up at 07:20 and something is happening at 11:30 and 17:00. Best times to relax are 21:00-00:00 and 02:00-10:00.

Lets look a bit closer at that 07:20 peak. Below are the angles for all the thuds that occur between 07:00-07:40 on Monday to Friday.

 


Only one neighboring apartment should be able to produce high positive angles so I'm pretty sure which apartment that is responsible for this peak.

Here are the weekend days.


The person that gets up at 07:20 sleeps in at the weekends, along with everyone else. Weekend daytime is a bit busier than during the weeks. Much of the 13:00 peak comes from a single event. I have a bit too little data for the weekend days so a single event can stand out in the diagram, but the general trends should be valid.

Tuesday, August 9, 2016

Detecting image manipulation in the noise

All resources referenced in this post can be found here.

If you assume that image noise is uniform over the entire image, and unique to a specific image sensor + setting (exposure time, sensitivity, etc), it should be possible to detect some forms of image manipulation by looking at the noise. If for example part of an image originates from a different capture it should have different noise characteristics than the rest of the image, and that could possibly be detected.

I wrote some code to see if this was doable, noise_lab.py. The application compares the noise at each pixel with normal noise to create an image depicting the deviation from normal noise. You can zoom along the "z axis" in the image to be able to see very small deviations. You can, for example, set a deviation of 0.2 to be black and a deviation of 0.21 to be white when showing the image.

The noise is captured by doing a FFT on a pixel's surroundings and dropping the DC component and the phase information. The normal noise is captured in the same way but from a user specified area of the image where all changes are caused by noise, for example the sky or a white wall.

When trying out my new application I quickly realized that my assumption that noise is uniform all over the image is not correct. I think there are a number of reasons for this but lets first focus on the relationship between pixel intensity and noise amplitude.



As can be seen there appears to be a relationship between intensity and noise amplitude. To be able to compare areas of the image with different intensity I need to normalize the noise amplitudes. I decided to model the relationship as a linear relationship where the slope is calculated from the user specified noise only areas. So now the user needs to input at least two noise only areas instead of only one which was the case before. The result looks as follows.



The linear model does not work well for low intensity pixels but it's good enough to see if this approach to detecting image manipulation has any future.

Below is an image composed of two different captures from the rear camera on my Nexus 6. The settings where 20ms ISO160 and 13ms ISO80. If everything works I should be able to see a difference in the noise. The image looks weird because I've tried to disable as much as possible of the camera's post processing to remove error sources. The image is what was read out from the sensor + bilinear interpolation + gamma encoding + jpeg encoding. What you get when running the following command on a dng file and jpeg encoding the result.

dcraw -r 1.0 1.0 1.0 1.0 -q 0 -M -o 0 -g 2.4 12.92 -j -W -H 1 image.dng



And this is what it looks like in the application.




It is quite easy to see the foreign part of the image but the low intensity parts of the original image appear to have the same noise characteristics as the foreign part, which is not ideal. This is a result of the noise normalization method's poor performance on low intensity areas. If you go back to the "Intensity - Normalized noise amplitude" diagram you will see that low intensity areas of image 1 have the same noise amplitude as normal intensity areas of image 2.

So that worked pretty well, but what happens if I feed the application with images that have gone through the camera's post processing? This image is also composed of two different captures from the rear camera of my Nexus 6. The settings where 33ms ISO241 and 17ms ISO134.






The "Intensity - Normalized noise amplitude" diagram is the most interesting one here. The noise variance has gone up (thicker y bands for each image) and the two images have moved closer to each other along the y axis. Both these things are bad if you want to detect image manipulation in the noise, and indeed the application is unable to detect the foreign part of the image. The completely black parts are due to saturated pixels (<= 0.0 or >= 1.0) being represented as zero difference.

If I make the noise difference between the two source images larger, 33ms ISO241 and 83ms ISO895, the application can detect the foreign part, but with such a big difference I can detect the foreign part just by looking at the image so the application does not add anything. This approach to detecting image manipulation is really only applicable to raw images with a few noise only areas. Unfortunately manipulated raw images are not that common, as far as I know anyhow, so this was a dead end.

Saturday, July 30, 2016

Analyzing relationships in a social network

All resources referenced in this post can be found here.

I'm a member of an online social network where you can post activities that others can join, and join activities that others have posted. Great if you want to find someone to play tennis with, or some company for your Friday night beer. Being of a curious nature I thought it would be interesting to have a look at the the composition of this network. Are there discernible subgroups, who hangs with who, and so on.

Before any analysis can be done you need some data. I'm just a member of this service so I don't have direct access to the database. Luckily the web page contains a lot of interesting data that can easily be extracted with a few regular expressions. Most importantly you can extract the activities, and which users that participated. With this information I know how many times each user have met each other user, key data for analyzing the relationships. For more details see mine.py which does the actual data mining.

The "who meets who" data can be represented as a graph. Users are the nodes, edges are the meets, and the edge weights are the number of meets. Representing the data as a graph has the great advantage of making me able to use existing graph analysis tools. produce_gdf.py stores the "who meets who" data for a specified period of time as a gdf file (a graph file format).

For the analysis I'm using Gephi which is an open source application for graph analysis. After loading the gdf file some work is needed to extract the data I'm interested in. I start by working on the layout of the graph. I want users that have met each other a lot to be close, and users that have not met each other as much to be far away from each other. This way subgroups should be clearly visible just by looking at the graph.

I'm not the first one to request this type of layout so there are a few options in Gephi. The algorithms are force based, all nodes repel each other and connected nodes also attract each other, a simulation of the forces is run and after a while the layout stabilizes at a hopefully good representation of the data. I got best results with the "ForceAtlas 2" algorithm.


The graph is full of week connections, users that have met only once or twice during the sampling period. It's hard to determine a pattern from that few meets, do these two users know each other or did they just happen to meet once or twice. To get rid of all this unusable data I filter out all the low weight edges. Below I have filtered out any edges with a weight less than 2.77 and re-run the layout. For my three months of data this leaves any relationships where the participants meet slightly less than once a month, on average.


As can be seen there are some people that meet quite often. Lets zoom in on some clusters.


101 hangs out with 577 and 350, but 577 and 350 do not hang out with each other. Looks like 101 meets 577 and 350 separately and they don't hang out as a group.


9, 121 and 13 form a strong trio. 555 almost makes the trio a quartet but lacks a connection to 121. 9 also maintains an impressive number of other unrelated relationships. On the other side 50 and 647 appear to know each other well and jointly have relationships with a number of other users, but the other users don't know each other, so it does not appear to be a very tight group.


I had to reduce the filtering quite a bit to get a more pronounced subgroup to appear. All the interconnections between the users indicates that they hang out as a group. Users in the center of the cluster are more common participants than the users at the edges of the cluster. Should be noted that since the filtering is heavily reduced these people may only have met once, so this does not have much value for the analysis. Just wanted to show how it would look if there had been any larger subgroups in my data.

So to conclude there aren't that many relationships where the participants meet more than once a month, as can be seen by the huge size reduction when filtering out low weight edges. There are two subgroups with 3-4 members and the rest are one to one relationships.

If the layout is not good enough to identify subgroups there is also an implementation of graph modularity in Gephi. The algorithm tries to split the nodes into modules which have a lot of edges inside the module and few edges leaving the module. You can color the nodes after which module they belong to, the result looks as follows.


This type of analysis is not limited to this specific case. If you have data on how people interact you can do this type of analysis. Data sources could for example be phone, mail or instant messaging metadata.

I managed to put the mined data to some practical use also, by writing a SQL query that returns the cancel statistics for a user. It returns how often, and how long before an activity, a user canceled his participation, on average. Great for estimating how likely it is you'll be drinking that Friday beer alone after all. See cancel_stats.py for more details.

python cancel_stats.py User555
Likelihood, Total event count, Hours before, User (last 6 months)
0.21,  14,     5 User555