-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReadData.py
34 lines (29 loc) · 878 Bytes
/
ReadData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from numpy import random
# 数据是16*8的矩阵
import numpy as np
class LetterData:
data = []
target = []
def __init__(self):
reader = open("./letter.data")
i = 0
for line in reader:
i += 1
lineList = line.split()
symbol = np.zeros(26)
info = ord(lineList[1]) - ord('a')
symbol[info] = 1
self.target.append(symbol)
tmp = []
for item in lineList[6:]:
tmp.append(int(item))
self.data.append(tmp)
reader.close()
def take_test_set(k, letterdata):
n = len(letterdata.data)
indexlist = random.randint(0, n, size=k)
result = {'data': [], 'target': []}
for i in indexlist:
result['data'].append(letterdata.data[i])
result['target'].append(letterdata.target[i])
return result