# 机器学习（一）：决策树算法及使用python构造一个决策树

# _*_ coding: utf-8 _*_

from sklearn.feature_extraction import DictVectorizer
import csv
from sklearn import preprocessing
from sklearn import tree
from sklearn.externals.six import StringIO

allData = open("E:\eclipse_file\Deeplearning\data\decisionTree.csv", "rU")

featureList = []
lableList = []
lableList.append(row[len(row)-1])
rowDic = {}
for i in range(1,len(row)-1):
featureList.append(rowDic)
print("featureList:"+str(featureList))
print("lablelist:"+str(lableList))
vec = DictVectorizer()
dummyX = vec.fit_transform(featureList).toarray()

print("dummyX:"+str(dummyX))
print("get_feature_names():"+str(vec.get_feature_names()))

lb = preprocessing.LabelBinarizer()
dummyY = lb.fit_transform(lableList)
print("dummyY:"+str(dummyY))

clf = tree.DecisionTreeClassifier(criterion="entropy")
clf = clf.fit(dummyX, dummyY)
print("clf:"+str(clf))

f = tree.export_graphviz(clf, feature_names=vec.get_feature_names(),out_file = f)

oneRow = dummyX[0]
print("oneRow:"+str(oneRow))
oneRow[0] = 1
oneRow[2] = 0
predictY = clf.predict(oneRow)
print("predictY:"+str(predictY))

#### 决策树原理实例（python代码实现）

2017-03-26 23:04:13

#### Python3《机器学习实战》学习笔记（二）：决策树基础篇之让我们从相亲说起

2017-07-21 16:44:27

#### 决策树原理及Python代码实现

2017-03-16 15:31:47

#### 机器学习经典算法详解及Python实现--决策树（Decision Tree）

2014-12-14 19:32:08

#### 机器学习算法的Python实现 (2)：ID3决策树

2016-04-01 22:42:39

#### python绘制决策树

2017-08-01 21:55:37

#### 详解决策树、python实现决策树

2017-12-10 21:57:47

#### Python机器学习（三）--决策树算法

2014-07-14 13:57:55

#### python实现决策树分类（一）

2017-06-23 14:38:44

#### 用Python开始机器学习（2：决策树分类算法）

2014-11-18 01:05:07