资源简介
本压缩包包含:
1.本决策树(DecisionTree)项目python源代码文件;
2.项目用的数据(csv格式);
3.一个普通文件,记录本项目的调试过程,用作实战参考

代码片段和文件信息
import matplotlib.pyplot as plt
from pylab import *
mpl.rcParams[‘font.sans-serif‘] = [‘SimHei‘]
# 定义文本框和箭头格式
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 #注解框位置
textcoords = ‘axes fraction‘
va = ‘center‘ 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(U‘决策节点‘ (0.5 0.1) (0.1 0.5) decisionNode)
plotNode(U‘叶节点‘ (0.8 0.1) (0.3 0.8) leafNode)
plt.show()
createPlot()
#获取叶节点的数目和树的层数
def getNumLeafs(myTree):
numLeafs = 0
firstStr = list(myTree.keys())[0]
secondDict = myTree[firstStr]
for key in secondDict.keys():
if type(secondDict[key]).__name__==‘dict‘:
numLeafs += getNumLeafs(secondDict[key])
else: numLeafs += 1
return numLeafs
def getTreeDepth(myTree):
maxDepth = 0
firstStr = list(myTree.keys())[0]
secondDict = myTree[firstStr]
for key in secondDict.keys():
if type(secondDict[key]).__name__==‘dict‘:
thisDepth = 1 + getTreeDepth(secondDict[key])
else: thisDepth = 1
if thisDepth > maxDepth: maxDepth = thisDepth
return maxDepth
#test code
#mt={‘no surfacing‘: {0: ‘no‘ 1: {‘flippers‘: {0: ‘no‘ 1: ‘yes‘}}}}
#print(getNumLeafs(mt))
#print(getTreeDepth(mt))
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-02-27 00:14 DecisionTree\
文件 807 2018-02-27 00:13 DecisionTree\tree.csv
文件 1852 2018-02-14 02:19 DecisionTree\treePlotter.py
文件 3115 2018-03-03 21:58 DecisionTree\trees.py
文件 8379 2018-02-21 23:57 DecisionTree\treestest
相关资源
- 机器学习(周志华)配套代码
- 机器学习-岭回归实现
- 012345手势识别神经网络代码
- 猫-非猫图二分类识别
- 机器学习k means算法实现图像分割
- 人工智能算法实现mnist手写数字识别
- kmeans聚类算法的python实现程序
- Python100经典练习题
- 南瓜书(PumpkinBook)
- 机器学习numpy和pandas基础
- 2020年面向人工智能新基建的知识图谱
- python机器学习Sebastian Raschka中文最新完
- Python-DeepMoji模型的pyTorch实现
- 《机器学习实战》源代码Python3
- Python-使用DeepFakes实现YouTube视频自动换
- python sklearn决策树
- Introduction to machine learning with python (
- python新浪微博爬虫,爬取微博和用户
- Python-一系列高品质的动漫人脸数据集
- Python-Insightface人脸检测识别的最小化
- 非线性回归Python代码
- 093 2018北风网人工智能视频(完结)转
- 决策树算法的PPT与实现代码
- python的色情图片识别
- 贝叶斯网络程序
- 北京大学曹健老师-人工智能实践:
- 《机器学习实战》Python3代码
- Python-自然场景文本检测PSENet的一个
- Python-在特征金字塔网络FPN的Pytorch实现
- Python-PyTorch实时多人姿态估计项目的实
评论
共有 条评论