October 18, 2014

125 Years of English Football!



    So the Barclay's Premier League is back since quite some time, and all the other leagues are back in action too. And for the first time, we have an Indian football league too! The ISL! ( I wish it changes Indian football forever!)

     Football league (as it was known back then) was created in 1888 by Aston Villa director William McGregor. Since then English Football has evolved into thousands of teams which play under hundreds of leagues. The BPL is just the tip of the iceberg. This blog gives complete information of the hierarchy of English Football.

    So, James Curley, assistant professor of psychology at Columbia University, in his free time, cobbled up data from a lots of sources and compiled all of them together, to make, what's probably the best collection of English football scores. Sitting silently on this Github page are scores of nearly 200,000 games played in the top 4 leagues since 1888. These 14 megabytes can tell us remarkable stories about 125 years of English Football!

    I have used R to perform all the manipulations on the data. The below code shows how to load data into R.

    Take the most common scoreline, for example, in 188,060 games, there were 13,475 0-0 draws. And the most common scoreline is 1-1, accounting for roughly 21000 (11%) games.
Top Five Full Time scores
Now, lets talk about goals! 

In 188,060 matches played in 125 years, a total of 542,288 goals were scored!
About 330,000 goals were scored by the home team and remaining by the visiting team.




We see that average home goals have reduced significantly and away goals keep oscillating.
Now this drop in average home goals and rise in the away goals in past twenty years explains the below graphs.
So, the home wins have greatly reduced to about 44% while away wins are on a gradual rise. This means that home matches won't matter as much as they used to matter earlier and slowly home dominance will begin to fade away.

Average goals per game have also reduced.


We see huge shifts in the average goals around the years 1925 and 1965. And the reason for is rule changes.


1958 - Substitutions were allowed for the first time
This roughly corresponds with the beginning of a steep decline in scoring in the 1960s. This could make for a plausible causal explanation: Perhaps playing with an injured player left teams extremely vulnerable on defense, leading to many goals. The addition of the substitute may have mitigated these effects.

The reduction in goals in the late 1920's isn't well explained. But it is believed that this majorly happened due to tactical changes. (Teams used to play many forwards, but later, defensive and midfield players increased.)


All the code used for plotting above charts and manipulation data can be found here.


Hope that it was a good read! 
Suggestions and feedback are always welcome! 

Happy Coding :D

August 10, 2014

A look at Rakshabandhan through Instagram


Due to none of my sisters in town, Rakshabandhan day is like any other day for me. No family get-together, no special lunch, nothing at all.

I wanted to use Instagram API since a long time and thought there would be no better day than this. It would be very interesting to know what people posted on Instagram related to this ocassion.

So after searching a lot, reading through the Instagram documentation and a bit of hacking I managed to make a Python script that will fetch images from Instagram in real time.
I ran the script for the keyword happyrakhsabandhan so I could fetch all the images hash-tagged with happyrakshabandhan as and when they are uploaded.

The script ran for about 15-20 minutes after which the rate limit got exceeded. My directory was filled with 335 images in just 15 minutes.

Here is my code snippet,

Just enter your credentials, set a search term and enter your path, you're good to go.

I prepared a quick collage of some random images.


General observations after glancing through the images,

  1. Majorly, there are close-ups of the rakhis either displayed in the plate or tied to the brother's wrist.
  2. Most of the pics show the brother-sister pair captured by a selfie.
  3. Some of the pics show all the cousins getting together for this occasion usually at someone's home.
  4. Also, girls have teasingly sent happy Rakshabandhan messages to their guy friends via trolls/selfies.
This is a very small project but this is just a start. It gave me many ideas for the future like, getting images which are selfies and using image processing to classify whether it is a boy or a girl, predicting hashtags based on the image and also predicting hashtags based on a given hashtag etc.
You can look forward to many more things in the future.
Feedback and suggestions are welcome.

And yes, *blog description and about us coming soon*

Happy Hacking :D