@@ -52,27 +52,30 @@ def MinMaxScaler(data):
52
52
# Open, High, Low, Volume, Close
53
53
xy = np .loadtxt ('data-02-stock_daily.csv' , delimiter = ',' )
54
54
xy = xy [::- 1 ] # reverse order (chronically ordered)
55
- xy = MinMaxScaler (xy )
56
- x = xy
57
- y = xy [:, [- 1 ]] # Close as label
58
-
59
- # build a dataset
60
- dataX = []
61
- dataY = []
62
- for i in range (0 , len (y ) - seq_length ):
63
- _x = x [i :i + seq_length ]
64
- _y = y [i + seq_length ] # Next close price
65
- print (_x , "->" , _y )
66
- dataX .append (_x )
67
- dataY .append (_y )
68
55
69
56
# train/test split
70
- train_size = int (len (dataY ) * 0.7 )
71
- test_size = len (dataY ) - train_size
72
- trainX , testX = np .array (dataX [0 :train_size ]), np .array (
73
- dataX [train_size :len (dataX )])
74
- trainY , testY = np .array (dataY [0 :train_size ]), np .array (
75
- dataY [train_size :len (dataY )])
57
+ train_size = int (len (xy ) * 0.7 )
58
+ train_set = xy [0 :train_size ]
59
+ test_set = xy [train_size - seq_length :] # Index from [train_size - seq_length] to utilize past sequence
60
+
61
+ # Scale each
62
+ train_set = MinMaxScaler (train_set )
63
+ test_set = MinMaxScaler (test_set )
64
+
65
+ # build datasets
66
+ def build_dataset (time_series , seq_length ):
67
+ dataX = []
68
+ dataY = []
69
+ for i in range (0 , len (time_series ) - seq_length ):
70
+ _x = time_series [i :i + seq_length , :]
71
+ _y = time_series [i + seq_length , [- 1 ]] # Next close price
72
+ print (_x , "->" , _y )
73
+ dataX .append (_x )
74
+ dataY .append (_y )
75
+ return np .array (dataX ), np .array (dataY )
76
+
77
+ trainX , trainY = build_dataset (train_set , seq_length )
78
+ testX , testY = build_dataset (test_set , seq_length )
76
79
77
80
# input place holders
78
81
X = tf .placeholder (tf .float32 , [None , seq_length , data_dim ])
0 commit comments