I'm studying the Random Forests and I made a little example to validate my knowledge. I create two classifiers, one with the DecisionTreeClassifier and another with RandomForestClassifier. After I used a cross-validation with the iris dataset and calculate the score for each one, how you could see in the code below. But when I analyze the values of the print, the results differs, what is a little strange for me. In theory if I have a Random Forest with only 1 estimator, that is not equivalent to a simple Tree ? So i don't need to have the same score?
from sklearn import tree, cross_validation from sklearn.datasets import load_iris max_depth = 1 n_estimators = 1 X, y = iris.data[:, :2], iris.target #take only the first two column values X, y = shuffle(X, y, random_state=42) # Standardize mean, std = X.mean(axis=0), X.std(axis=0) X = (X - mean) / std kf_total = cross_validation.KFold(len(X), n_folds=2) clf1 = tree.DecisionTreeClassifier(max_depth = max_depth) clf2 = RandomForestClassifier(n_estimators=n_estimators) scoreForest = cross_validation.cross_val_score(clf1, X, y, cv=kf_total, n_jobs = 1) scoreTree = cross_validation.cross_val_score(clf2, X, y, cv=kf_total, n_jobs = 1) print 'forest', scoreForest , 'tree', scoreTree
My print result: forest [ 0.64 0.61333333] tree [ 0.69333333 0.66666667]