>>> from sklearn.tree import DecisionTreeClassifier
>>> tree_model = DecisionTreeClassifier(criterion=''gini',
... max_depth=4,
... random_state=1)
>>> tree_model.fit(X_train, y_train)
>>> X_combined = np.vstack((X_train, X_test))
>>> y_combined = np.hstack((y_train, y_test))
>>> plot_decision_regions(X_combined,
... y_combined,
... classifier=tree_model,
... test_idx=range(105, 150))
>>> plt.xlabel(''Petal length [cm]')
>>> plt.ylabel(''Petal width [cm]')
>>> plt.legend(loc=''upper left')
>>> plt.tight_layout()
>>> plt.show()
코드를 실행하면 축에 나란히 놓인 전형적인 결정 트리의 결정 경계를 얻습니다.