You can use warm_startto pre-compute trees:
clf = RandomForestClassifier(n_estimators=100, warm_start=True)
clf.fit(X1, y1)
clf.set_params(n_estimators=200)
clf.fit(X2, y2)
Alternatively
def generate_rf(X_train, y_train, X_test, y_test):
rf = RandomForestClassifier(n_estimators=5, min_samples_leaf=3)
rf.fit(X_train, y_train)
print "rf score ", rf.score(X_test, y_test)
return rf
def combine_rfs(rf_a, rf_b):
rf_a.estimators_ += rf_b.estimators_
rf_a.n_estimators = len(rf_a.estimators_)
return rf_a
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.33)
rf_clf = [generate_rf(X_train, y_train, X_test, y_test) for i in range(n)]
rf_clf_combined = reduce(combine_rfs, rfs)
source
share