Code for reproducing the data filtering and analyses in our paper Measuring Online Social Bubbles
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


  • This is the code to reproduce the experiments in Dimitar G Nikolov, Diego F. M. Oliveira, Alessandro Flammini, Filippo Menczer. Measuring Online Social Bubbles, 2015.
  • All scripts run on Python 2.7. If you do not have Python set up, the easiest way to do it and ensure you have the necessary libraries to run the code, is to download the Python 2.7 Anaconda distribution.
  • The first thing you need to do is go to and request the full dataset of web requests. The data is public, but not open, meaning that you will need to submit a request for it that will go through a review. This is necessary due to sensitivity of the data, and us wanting to be confident it will be used for legitimate research purposes.
  • Once you have the data, you can follow the steps below to process it and generate the various plots from the paper. The scripts are designed to be self-contained and run with minimal changes, but you may need to change a few paths around when you carry out the news targets data preparation. In addition, most of the scripts are designed to run in parallel on 16 cores. Changing the parallelism level is per script and should be pretty easy to do when you look at the code.
  • Before you begin, make sure that the following environmental variables are created on your machine: TC, TR, TP, TD (short for Traffic Code, Traffic Results, Traffic Plots and Traffic Data, respectively). For example, one way to do this is to put the following lines in your .bashrc file.
export TBASE="/home/you/projects/web-traffic"
export TC="$TBASE/code"
export TR="$TBASE/results"
export TP="$TBASE/plots"
export TD="$TBASE/data"

You can follow the following data path in running the experiments.

Data Preparation

Change the granularity of the data (hour to day, day to month) and conver to 3rd level domains.

  1. Get rid of invalid requests and transform the valid ones to a form easier to parse later:
  2. Create visit matrix files from the human requests click files:
  3. Change the granularity of the vm files from hour to day and from day to month:
  4. transform/
  5. transform/
  6. Create a dataset with maximum domain level of 3: transform/

Data Filtering

Remove ads, auto, iu and intra category traffic, filter referrers to be in the categories of interest, etc.

  1. Remove traffic not coming from the categories of interest: filter/
  2. Remove traffic going to the categories of interest: filter/
  3. Remove IU traffic: filter/
  4. Remove advertising and data serving traffic: filter/
  5. Make the following symbolic link to make things easier: ln -s $TD/vm/level3-domain/month/filtered-referrers--filtered-targets--no-iu--no-unwanted $TD/vm/level3-domain/month/filtered

More Data Preparation

Convert to 2nd level domains and create a separate dataset for each category.

  1. Split the vms into categories for search, social media, mail: transform/
  2. Create level2 domain datasets from the category data: transform/

Preparing News-Only Data

  1. Run scrapy to crawl the news sources from in $TC/news run 'scrapy crawl NewsLinksSpider'
  2. Filter the news urls: news/
  3. Filter the full-domain data by url: filter/
  4. Run these scripts from the filtering pipeline on the news-only data:,,,
  5. Run filter/ to filter some of the likely non-human news traffic.
  6. Make a link to the filtered data: ln -s $TD/vm/news/full-domain/month/filtered-referrers--filtered-targets--no-iu--no-unwanted--no-junk $TD/vm/news/full-domain/month/filtered
  7. Split up the dataset by category: transform/

Traffic Volume Analysis

  1. Compute the traffic volumes for each category in the entire dataset: analyze/ Run for both news and all targets.
  2. Plot the traffic volume: plot/

Overall Entropy Analysis

  1. Using the results from the traffic volume computation, determine how many visits to sample from all time periods. Used in the analysis were 1,000 for news-only targets and 80,000 for all targets.
  2. Run the sampling script passing it the number obtained above: filter/
  3. creates samples for each month. An alternative way to do this is to run filter/, which samples the full dataset multiple times. In the first case, the results have a temporal component, in the second, they don't.
  4. Compute the entropy of the newly sampled dataset: analyze/
  5. Plot the entropy that was just computed: plot/

Entropy Over Time Analysis

  1. Note that steps 1 and 2 were probably already completed.
  2. Using the results from the traffic volume computation, determine how many visits to sample per time period.
  3. Run the sampling script passing it the number obtained above: filter/
  4. Create smoothing datasets for the different categories: transform/
  5. Compute the entropy of the newly smoothed dataset: analyze/
  6. Plot the entropy that was just compute: plot/

Entropy vs Traffic Volume Analysis

  1. Create random datasets with increasing numbers of requests: transform/
  2. Compute the entropy versus traffic volume results: analyze/
  3. Plot the entropy and traffic volume just computed: plot/

Twitter and AOL Computations

See README in twitter directory.