highest probability is predicted analyzing random forests let' apply random forest consisting of five trees to the two_moons dataset we studied earlierin[ ]from sklearn ensemble import randomforestclassifier from sklearn datasets import make_moons xy make_moons(n_samples= noise= random_state= x_trainx_testy_trainy_test train_test_split(xystratify=yrandom_state= forest randomforestclassifier(n_estimators= random_state= forest fit(x_trainy_trainthe trees that are built as part of the random forest are stored in the estimator_ attribute let' visualize the decision boundaries learned by each treetogether with their aggregate prediction as made by the forest (figure - )in[ ]figaxes plt subplots( figsize=( )for (axtreein enumerate(zip(axes ravel()forest estimators_))ax set_title("tree {}format( )mglearn plots plot_tree_partition(x_trainy_traintreeax=axmglearn plots plot_ d_separator(forestx_trainfill=trueax=axes[- - ]alpha axes[- - set_title("random forest"mglearn discrete_scatter(x_train[: ]x_train[: ]y_trainyou can clearly see that the decision boundaries learned by the five trees are quite different each of them makes some mistakesas some of the training points that are plotted here were not actually included in the training sets of the treesdue to the bootstrap sampling the random forest overfits less than any of the trees individuallyand provides much more intuitive decision boundary in any real applicationwe would use many more trees (often hundreds or thousands)leading to even smoother boundaries supervised machine learning algorithms