# test.py
# 获取树的叶子树和深度
# http://blog.csdn.net/monkey131499/article/details/50766408
import tree
import trees
import treePlotter
'''
myDat, labels = trees.createDataSet()
myTree = treePlotter.retrieveTree(0)

# myLabels = labels
# myTree = trees.createTree(myDat, labels)
print('决策树叶子数：', treePlotter.getNumLeafs(myTree))
print('决策树深度：', treePlotter.getTreeDepth(myTree))

# 使用决策树的分类函数
print('输入数据[1,1]的决策结果：', tree.classify(myTree, labels, [1, 1]))

# 存储和获取决策树
tree.storeTree(myTree, 'data/lenses.txt')
print(tree.grabTree('data/lenses.txt'))

# 绘图
treePlotter.createPlot(myTree)
'''

fr = open('data/lenses.txt')
lenses = [inst.strip().split('\t')[1:] for inst in fr.readlines()]
print(lenses)
lensesLabels = ['age', 'prescript', 'astigmatic', 'tearRate']
labels = ['age', 'prescript', 'astigmatic', 'tearRate']
print('隐形眼镜标签集：', lensesLabels)
lensesTree = tree.createTree(lenses, labels)
print('隐形眼镜标签集：', labels, lensesLabels)
print('隐形眼镜数据集：', lenses)
print('隐形眼镜决策树：', lensesTree)

treePlotter.createPlot(lensesTree)
print(tree.classify(lensesTree, lensesLabels, ['1', '1', '1', '2']))
d8982966db81e0b6f8c99159d5fbf6e93db5741f
<mask token>

<mask token>
print(lenses)
<mask token>
print('隐形眼镜标签集：', lensesLabels)
<mask token>
print('隐形眼镜标签集：', labels, lensesLabels)
print('隐形眼镜数据集：', lenses)
print('隐形眼镜决策树：', lensesTree)
treePlotter.createPlot(lensesTree)
print(tree.classify(lensesTree, lensesLabels, ['1', '1', '1', '2']))

<mask token>
fr = open('data/lenses.txt')
lenses = [inst.strip().split('\t')[1:] for inst in fr.readlines()]
print(lenses)
lensesLabels = ['age', 'prescript', 'astigmatic', 'tearRate']
labels = ['age', 'prescript', 'astigmatic', 'tearRate']
print('隐形眼镜标签集：', lensesLabels)
lensesTree = tree.createTree(lenses, labels)
print('隐形眼镜标签集：', labels, lensesLabels)
print('隐形眼镜数据集：', lenses)
print('隐形眼镜决策树：', lensesTree)
treePlotter.createPlot(lensesTree)
print(tree.classify(lensesTree, lensesLabels, ['1', '1', '1', '2']))

import tree
import trees
import treePlotter
<mask token>
fr = open('data/lenses.txt')
lenses = [inst.strip().split('\t')[1:] for inst in fr.readlines()]
print(lenses)
lensesLabels = ['age', 'prescript', 'astigmatic', 'tearRate']
labels = ['age', 'prescript', 'astigmatic', 'tearRate']
print('隐形眼镜标签集：', lensesLabels)
lensesTree = tree.createTree(lenses, labels)
print('隐形眼镜标签集：', labels, lensesLabels)
print('隐形眼镜数据集：', lenses)
print('隐形眼镜决策树：', lensesTree)
treePlotter.createPlot(lensesTree)
print(tree.classify(lensesTree, lensesLabels, ['1', '1', '1', '2']))

# test.py
# 获取树的叶子树和深度
# http://blog.csdn.net/monkey131499/article/details/50766408
import tree
import trees
import treePlotter
'''
myDat, labels = trees.createDataSet()
myTree = treePlotter.retrieveTree(0)

# myLabels = labels
# myTree = trees.createTree(myDat, labels)
print('决策树叶子数：', treePlotter.getNumLeafs(myTree))
print('决策树深度：', treePlotter.getTreeDepth(myTree))

# 使用决策树的分类函数
print('输入数据[1,1]的决策结果：', tree.classify(myTree, labels, [1, 1]))

# 存储和获取决策树
tree.storeTree(myTree, 'data/lenses.txt')
print(tree.grabTree('data/lenses.txt'))

# 绘图
treePlotter.createPlot(myTree)
'''

fr = open('data/lenses.txt')
lenses = [inst.strip().split('\t')[1:] for inst in fr.readlines()]
print(lenses)
lensesLabels = ['age', 'prescript', 'astigmatic', 'tearRate']
labels = ['age', 'prescript', 'astigmatic', 'tearRate']
print('隐形眼镜标签集：', lensesLabels)
lensesTree = tree.createTree(lenses, labels)
print('隐形眼镜标签集：', labels, lensesLabels)
print('隐形眼镜数据集：', lenses)
print('隐形眼镜决策树：', lensesTree)

treePlotter.createPlot(lensesTree)
print(tree.classify(lensesTree, lensesLabels, ['1', '1', '1', '2']))