应用决定计划树分类
- def classify(inputTree,featLabels,testVec):
- firstStr = inputTree.keys()[0]
- secondDict = inputTree[firstStr]
- featIndex = featLabels.index(firstStr)
- # print 'featIndex %s' % (featIndex)
- key = testVec[featIndex]
- # print 'key %s' % (key)
- valueOfFeat = secondDict[key]
- if isinstance(valueOfFeat, dict):
- classLabel = classify(valueOfFeat, featLabels, testVec)
- else: classLabel = valueOfFeat
- return classLabel
- dataSet, labels = createDataSet()
- mytree = createTree(dataSet, labels[:]) #因为内部会删除labels里的值所以用如许copy一份
- print mytree
- # {'no surfacing': {0: 'no', 1: {'flippers': {0: 'no', 1: 'yes'}}}}
- print classify(mytree, labels, [0,1])
- no
决定计划树的存储

构造决定计划树是耗时的义务,即使处理很小的数据集。所以我们可以应用构造好的决定计划树。
长处
- 计算复杂度不高
- 输出结不雅易于懂得
- 对中心值缺掉不敏感
- 可以处理不相干特侦
推荐阅读
前几天我们正在运营的一款产品产生了崩溃,我花了两天测验测验用 gdb 分析了 coredump ,固然最后照样没能找到 bug ,但照样认为应当做一些总结。产品是基于 skynet 开辟的,因为汗青原因>>>详细阅读
本文标题:机器学习决策树算法学习笔记
地址:http://www.17bianji.com/lsqh/35136.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示