使用决策树进行分类
来源:互联网 发布:正版cad软件多少钱 编辑:程序博客网 时间:2024/06/07 05:46
#创建数据集def createDataSet(): dataSet = [[1, 1, 'yes'], [1, 1, 'yes'], [1, 0, 'no'], [0, 1, 'no'], [0, 1, 'no']] labels = ['no surfacing', 'flippers'] return dataSet, labels#测试的树数据def retrieveTree(i): listOfTrees = [{'no surfacing': {0: 'no', 1: {'flippers': {0: 'no', 1:'yes'}}}}, {'no surfacing': {0: 'no', 1: {'flippers': {0: {'head': {0: 'no', 1:'yes'}}, 1: 'no'}}}}] return listOfTrees[i]#使用决策树进行分类def classify(inputTree, featLabels, testVec): #inputTree为输入的树,featLabels为特征值标签,testVec为测试的特征值结果 first = list(inputTree.keys()) firstStr = first[0] #树的根节点 secondDict = inputTree[firstStr] #子树 featIndex = featLabels.index(firstStr) #返回特征值的索引 for key in secondDict.keys(): if testVec[featIndex] == key: #testVec[featIndex]为测试数据当前特征值的结果 if type(secondDict[key]).__name__=="dict": #判断是否为字典,有没有子树 classLabel = classify(secondDict[key], featLabels, testVec) else: classLabel = secondDict[key] #这个测试值得标签则树子节点的值 return classLabel#测试[1,0]的标签为myDat, labels = createDataSet()myTree = retrieveTree(0)classLabel = classify(myTree, labels, [1, 0])print(classLabel)>>no
阅读全文
0 0
- 使用决策树进行分类
- python3 使用决策树进行分类
- 使用Orange进行数据挖掘之分类(3)------决策树
- 使用决策树实现分类
- 使用R完成决策树分类
- Python实现决策树对西瓜进行分类
- 决策树进行多属性分类 C++实现
- 决策树分类
- 分类:决策树
- 决策树分类
- 分类-决策树
- 决策树分类
- 分类决策树
- 分类决策树
- 分类决策树
- 初识机器学习之决策树对鸢尾花进行分类
- 使用libsvm进行分类
- R完成--决策树分类 一个使用rpart完成决策树分类的例子如下:
- cookie小实例第二弹------浏览记录
- spring cloud开发实战讲解
- ethtool 命令详解
- 学习日记12-08
- Python checkio Monkey Typing解决方案
- 使用决策树进行分类
- 第一章
- 弱口令字典
- AI与伦理道德
- 坦克小战的游戏规则说明(1)
- RxJava2 中常用操作符和Subject常用子类说明
- 总结:整理 oracle异常错误处理
- Sublime Text3插件详解
- Tomcat配置登录拦截功能