Code for "Mondrian Forests: Efficient Online Random Forests"
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 5 commits behind balajiln:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

This folder contains the scripts used in the following paper:

Mondrian Forests: Efficient Online Random Forests

Balaji Lakshminarayanan, Daniel M. Roy, Yee Whye Teh

Please cite the above paper if you use this code.

I ran my experiments using Enthought python (which includes all the necessary python packages). If you are running a different version of python (e.g. anaconda), you will need the following python packages (and possibly other packages) to run the scripts:

  • numpy
  • scipy
  • matplotlib (for plotting Mondrian partitions)
  • pydot and graphviz (for printing Mondrian trees)
  • sklearn (for reading libsvm format files)

Some of the packages (e.g. pydot, matplotlib) are necessary only for '--draw_mondrian 1' option. If you just want to run experiments without plotting the Mondrians, these packages may not be necessary.

Paul Heideman has created requirements.txt, which makes it easy to install the packages using 'pip install -r requirements.txt'. Dan Stowell pointed out that dvipng package is required in ubuntu to draw the Mondrians.

The datasets are not included here; you need to download them from the UCI repository. You can run experiments using toy data though. Run in process_data folder for automatically downloading and processing the datasets. I have tested these scripts only on Ubuntu, but it should be straightforward to process datasets in other platforms.

If you have any questions/comments/suggestions, please contact me at

Code released under MIT license (see COPYING for more info).

Copyright © 2014 Balaji Lakshminarayanan

List of scripts in the src folder:


Help on usage can be obtained by typing the following commands on the terminal:

./ -h

Example usage:

./ --dataset toy-mf --n_mondrians 100 --budget -1 --normalize_features 1

Examples that draw the Mondrian partition and Mondrian tree:

./ --draw_mondrian 1 --save 1 --n_mondrians 10 --dataset toy-mf --store_every 1 --n_mini 6 --tag demo

./ --draw_mondrian 1 --save 1 --n_mondrians 1 --dataset toy-mf --store_every 1 --n_mini 6 --tag demo

Example on a real-world dataset:

assuming you have successfully run in process_data folder

./ --dataset satimage --n_mondrians 100 --budget -1 --normalize_features 1 --save 1 --data_path ../process_data/ --n_minibatches 10 --store_every 1

I generated commands for parameter sweeps using 'build_cmds' script by Jan Gasthaus, available publicly at

Some examples of parameter sweeps are:

./build_cmds ./ "--op_dir={results}" "--init_id=1:1:6" "--dataset={letter,satimage,usps,dna,dna-61-120}" "--n_mondrians={100}" "--save={1}" "--discount_factor={10.0}" "--budget={-1}" "--n_minibatches={100}" "--bagging={0}" "--store_every={1}" "--normalize_features={1}" "--data_path={../process_data/}" >> run

Note that the results (predictions, accuracy, log predictive probability on training/test data, runtimes) are stored in the pickle files. You need to write additional scripts to aggregate the results from these pickle files and generate the plots.