The random_state
argument should work but here are 2 different options
Option 1:
from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor(n_estimators=1000, criterion='mse', min_samples_leaf=4,
random_state= 0)
This should return the same results every single time.
Scikit-learn does not use its own global random state; whenever a
RandomState instance or an integer random seed is not provided as an
argument, it relies on the numpy global random state, which can be set
using numpy.random.seed
Option 2:
That being said, adding np.random.seed()
before importing the RandomForestRegressor
should also do the trick.
import numpy as np
np.random.seed(0)
Source: http://scikit-learn.org/stable/faq.html#how-do-i-set-a-random-state-for-an-entire-execution