-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstockNN.py
More file actions
40 lines (30 loc) · 734 Bytes
/
Copy pathstockNN.py
File metadata and controls
40 lines (30 loc) · 734 Bytes
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
35
36
37
38
39
40
from network import Network
import csv
import numpy as np
# readData
def encodeLabel(label):
label = float(label)
lab = np.zeros((3,1))
if label==1.:
lab[0]=1.0
elif label == 0.:
lab[1] = 1.0
elif label == -1.0:
lab[2] = 1.0
else:
print("No Match, error")
return lab
def encodeData(x):
floatv = np.vectorize(float)
return floatv(x).reshape(22,1)
filename = 'stock/jnjdata4.csv'
data = [row for row in csv.reader(open(filename))]
header = data.pop(0)
data = [(encodeData(row[1:]),encodeLabel(row[0])) for row in data]
inputDim = len(header)-1
shape = [22, 30, 3]
nn = Network(shape)
testStartIndex = len(data)-1000
trainSet = data[:10000]
testSet = data[testStartIndex:]
nn.TMB(trainSet, 10, 10, 5, testSet)