Decision Tree:very popular, oldest, most useful
->trick, non-linear decision making
wind surf
linearly separable?
Decision Trees:
two outcomes Yes or No? to classify official data.
X < 3, Y < 2 sk learning: decision tree http://scikit-learn.org/stable/modules/tree.html classification
>>> from sklearn import tree >>> X = [[0, 0], [1, 1]] >>> Y = [0, 1] >>> clf = tree.DecisionTreeClassifier() >>> clf = clf.fit(X, Y) >>> clf.predict([[2., 2.]]) array([1]) >>> clf.predict_proba([[2., 2.]]) array([[ 0., 1.]]) >>> from sklearn.datasets import load_iris >>> from sklearn import tree >>> iris = load_iris() >>> clf = tree.DecisionTreeClassifier() >>> clf = clf.fit(iris.data, iris.target) >>> with open(“iris.dot”, ‘w’) as f: … f = tree.export_graphviz(clf, out_file=f) >>> import os >>> os.unlink(‘iris.dot’) >>> import pydotplus >>> dot_data = tree.export_graphviz(clf, out_file=None) >>> graph = pydotplus.graph_from_dot_data(dot_data) >>> graph.write_pdf(“iris.pdf”) >>> from IPython.display import Image >>> dot_data = tree.export_graphviz(clf, out_file=None, feature_names=iris.feature_names, class_names=iris.target_names, filled=True, rounded=True, special_characters=True) >>> graph = pydotplus.graph_from_dot_data(dot_data) >>> Image(graph.create_png())
DT decision boundary
import sys from class_vis import prettyPicture from prep_terrain_data import makeTerrainData import numpy as np import pylab as pl features_train, labels_train, features_test, labels_test = makeTerrainData() acc = def submitAccuracies(): return {"acc":round(acc,3)}