DT



In [4]:
from sklearn.datasets import fetch_openml

df = fetch_openml(name='Weather', version='1')
y = df.target
X = df.data

In [11]:
X


Out[11]:
array([[ 2., 85., 85.,  0.],
       [ 2., 80., 90.,  0.],
       [ 0., 83., 86.,  0.],
       [ 1., 70., 96.,  0.],
       [ 1., 68., 80.,  0.],
       [ 1., 65., 70.,  0.],
       [ 0., 64., 65.,  0.],
       [ 2., 72., 95.,  0.],
       [ 2., 69., 70.,  0.],
       [ 1., 75., 80.,  0.],
       [ 2., 75., 70.,  0.],
       [ 0., 72., 90.,  0.],
       [ 0., 81., 75.,  0.],
       [ 1., 71., 91.,  0.]])

In [5]:
from sklearn.tree import DecisionTreeClassifier

tree_model = DecisionTreeClassifier(criterion='entropy', max_depth=4, random_state=1)
tree_model.fit(X, y)


Out[5]:
DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='entropy',
                       max_depth=4, max_features=None, max_leaf_nodes=None,
                       min_impurity_decrease=0.0, min_impurity_split=None,
                       min_samples_leaf=1, min_samples_split=2,
                       min_weight_fraction_leaf=0.0, presort='deprecated',
                       random_state=1, splitter='best')

In [6]:
from sklearn import tree
import matplotlib.pyplot as plt

tree.plot_tree(tree_model)
plt.show()