标签:c style class blog code java
图1
1、信息熵:
2、数据集的划分
3、创建树:
4、绘制树图
#-*- coding:cp936 -*- #=============================================================================== # 使用文本注解绘制树节点 #=============================================================================== import matplotlib.pyplot as plt decisionNode = dict(boxstyle = ‘sawtooth‘, fc = ‘0.8‘) leafNode = dict(boxstyle = ‘round4‘, fc = ‘0.8‘) arrow_args = dict(arrowstyle = ‘<-‘) def plotNode(nodeTxt, centerPt, parentPt, nodeType): createPlot.ax1.annotate(nodeTxt, xy = parentPt, xycoords = ‘axes fraction‘, xytext = centerPt, ha = ‘center‘, bbox = nodeType, arrowprops = arrow_args) def createPlot(): fig = plt.figure(1, facecolor=‘white‘) fig.clf() createPlot.ax1 = plt.subplot(111, frameon = False) plotNode(‘a decision node‘, (0.5,0.1), (0.1,0.5), decisionNode) plotNode(‘a leaf node‘, (0.8,0.1), (0.3,0.8), leafNode) plt.show() createPlot()
5、使用决策树执行分类
标签:c style class blog code java
原文地址:http://www.cnblogs.com/mmhx/p/3758405.html