def ContactLensesClassifier():
    fr = open('lenses.txt')
    lines = fr.readlines()
    dataSet = [l.strip().split('\t') for l in lines]
    labels = ['age', 'prescript', 'astigmatic', 'tearRate']
    decisionTree = createTree(dataSet, labels)
    print(labels)
    plotDecisionTree.createPlot(decisionTree)
    storeTree(decisionTree, 'lensesDecisionTree.txt')
    tree = getTree('lensesDecisionTree.txt')
    plotDecisionTree.createPlot(tree)
Exemplo n.º 2
0
    labels = data_set.labels
    for i in range(len(data_set.feature_set[0])):
        new_feature = []
        for feature in data_set.feature_set:
            if feature[i] != '-':
                new_feature.append(feature[i])
                features_list[labels[i]] = set(new_feature)
    return features_list


df = pd.read_csv('watermelon_4_2a.csv')
data = df.values[:, :].tolist()
# data_test = df.values[11:, :].tolist()
labels = df.columns.values[0:-1].tolist()
data_set = DataSet(data, labels,[1]*len(data))
feature_dict = generate_full_features(data_set)
tree = DecisionTree(data_set,feature_dict)
plotDecisionTree.createPlot(tree)
# print tree.node.children[0].children[0].children[1].children











Exemplo n.º 3
0
# coding:utf-8

# 对隐形眼镜的分类

import decisionTree
import plotDecisionTree
import trees

fr = open('lenses.txt')
lenses = [inst.strip().split('\t') for inst in fr.readlines()]
fr.close()

print type(lenses)
for i in range(len(lenses)):
    print lenses[i]

print '... end lenses'


lensesFeatName = ['age', 'prescript', 'astigmatic', 'tearRate', 'lenses type']


lensesTree = decisionTree.createTree(lenses, lensesFeatName)
print lensesTree



plotDecisionTree.createPlot(lensesTree)
Exemplo n.º 4
0
# coding:utf-8

# 对隐形眼镜的分类

import decisionTree
import plotDecisionTree
import trees

fr = open('lenses.txt')
lenses = [inst.strip().split('\t') for inst in fr.readlines()]
fr.close()

print type(lenses)
for i in range(len(lenses)):
    print lenses[i]

print '... end lenses'

lensesFeatName = ['age', 'prescript', 'astigmatic', 'tearRate', 'lenses type']

lensesTree = decisionTree.createTree(lenses, lensesFeatName)
print lensesTree

plotDecisionTree.createPlot(lensesTree)