MCPcopy Index your code
hub / github.com/apachecn/ailearning / createDataSet

Function createDataSet

src/python/3.DecisionTree/DTSklearn.py:12–32  ·  view source on GitHub ↗

数据读入

()

Source from the content-addressed store, hash-verified

10
11
12def createDataSet():
13 ''' 数据读入 '''
14 data = []
15 labels = []
16 with open("input/3.DecisionTree/data.txt") as ifile:
17 for line in ifile:
18 # 特征: 身高 体重 label: 胖瘦
19 tokens = line.strip().split(' ')
20 data.append([float(tk) for tk in tokens[:-1]])
21 labels.append(tokens[-1])
22 # 特征数据
23 x = np.array(data)
24 # label分类的标签数据
25 labels = np.array(labels)
26 # 预估结果的标签数据
27 y = np.zeros(labels.shape)
28
29 ''' 标签转换为0/1 '''
30 y[labels == 'fat'] = 1
31 print data, '-------', x, '-------', labels, '-------', y
32 return x, y
33
34
35def predict_train(x_train, y_train):

Callers 1

DTSklearn.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected