Predicting Income with Random Forests

Regarding the project for Random Forests, Predicting Income with Random Forests

The last task, suggesting to print forest.feature_importances_ is a bit short to see the actual importances.

I would suggest actually running:

import numpy as np

importances = forest.feature_importances_
indices = np.argsort(importances)[::-1]

for i in range(train_data.shape[1]):
    print(
        f"{i + 1} {train_data.columns[indices[i]]} ({round(importances[indices[i]],4)})"
    )

The output from the code actually sorts the features by importances

1 capital-gain (0.3665)
2 age (0.2682)
3 capital-loss (0.1524)
4 hours-per-week (0.1455)
5 sex_int (0.0675)
6 country_int (0.0)

Can someone explain in Predicting Income with Random Forests the RandomForestClassifier result is 0.8142734307824592 but when I applying the same data using DecisionTreeClassifier I’m getting 0.8226262129959464 isn’t the Decision Tree supposed to be lower ??