Skip to content
No description, website, or topics provided.
Branch: master
Clone or download

Latest commit

Latest commit e33e4b4 Feb 13, 2020


Type Name Latest commit message Commit time
Failed to load latest commit information.
demo use wrf in run_iRF Feb 13, 2020
irf use wrf in run_iRF Feb 13, 2020
.gitignore Modify setup files to make the package running. Jul 17, 2017 Update Feb 12, 2020
COPYING Add scikit-learn COPYING Jul 25, 2017 MAINT Include binary_tree.pxi in source distribution Jul 4, 2014 update the demo in Feb 10, 2020 update to version 0.2.1 Feb 10, 2020

iterative Random Forest

The algorithm details are available at:

Sumanta Basu, Karl Kumbier, James B. Brown, Bin Yu, Iterative Random Forests to detect predictive and stable high-order interactions,

The implementation is a joint effort of several people in UC Berkeley. See the for the complete list. The weighted random forest implementation is based on the random forest source code and API design from scikit-learn, details can be found in API design for machine learning software: experiences from the scikit-learn project, Buitinck et al., 2013.. The setup file is based on the setup file from skgarden.



The irf package requires

  • Python (>= 3.3)
  • Numpy (>= 1.8.2)
  • Scipy (>= 0.13.3)
  • Cython
  • pydotplus
  • matplotlib
  • jupyter
  • pyyaml
  • scikit-learn (>= 0.22)

Before the installation, please make sure you installed the above python packages correctly via pip:

pip install cython numpy scikit-learn pydotplus jupyter pyyaml matplotlib

Basic setup and installation

Installing irf package is simple. Just clone this repo and use pip install.

git clone

Then go to the iterative-Random-Forest folder and use pip install:

pip install -e .

If irf is installed successfully, you should be able to see it using pip list:

pip list | grep irf

and you should be able to run all the tests (assume the working directory is in the package iterative-Random-Forest):

python irf/tests/
python irf/tests/

A simple demo

In order to use irf, you need to import it in python.

import numpy as np
from irf import irf_utils
from irf.ensemble import RandomForestClassifierWithWeights

Generate a simple data set with 2 features: 1st feature is a noise feature that has no power in predicting the labels, the 2nd feature determines the label perfectly:

n_samples = 1000
n_features = 10
X_train = np.random.uniform(low=0, high=1, size=(n_samples, n_features))
y_train = np.random.choice([0, 1], size=(n_samples,), p=[.5, .5])
X_test = np.random.uniform(low=0, high=1, size=(n_samples, n_features))
y_test = np.random.choice([0, 1], size=(n_samples,), p=[.5, .5])
# The second feature (which is indexed by 1) is very important
X_train[:, 1] = X_train[:, 1] + y_train
X_test[:, 1] = X_test[:, 1] + y_test

Then run irf

all_rf_weights, all_K_iter_rf_data, \
    all_rf_bootstrap_output, all_rit_bootstrap_output, \
    stability_score = irf_utils.run_iRF(X_train=X_train,
                                        K=5,                          # number of iteration
                                        rf = RandomForestClassifierWithWeights(n_estimators=20),
                                        random_state_classifier=2018, # random seed

all_rf_weights stores all the weights for each iteration:


The proposed feature combination and their scores:

You can’t perform that action at this time.