-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
61 lines (43 loc) · 1.33 KB
/
Main.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras import regularizers
from tensorflow.keras import models
import tensorflow_docs as tfdocs
import tensorflow_docs.modeling
import tensorflow_docs.plots
from IPython import display
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
from Stock_data import *
BATCH_SIZE=32
model = keras.Sequential()
model.add(layers.LSTM(64, name="InputLSTMLayer")),
model.add(layers.Dense(100, activation="selu", name="InnerLayer"))
model.add(layers.Dense(4, name="OutputLayer"))
model.compile(
optimizer=keras.optimizers.Adam(), # Optimizer
# Loss function to minimize
loss=keras.losses.MeanAbsoluteError(),
# List of metrics to monitor
metrics=["accuracy"],
)
stock_data = get_stock_data("03/05/2016", "29/12/2019")
data = keras.preprocessing.timeseries_dataset_from_array(
stock_data[:-1],
stock_data[1:],
stock_data.shape[1],
batch_size=BATCH_SIZE)
history = model.fit(
data,
batch_size=BATCH_SIZE,
epochs=100)
print(history.history)
plt.figure(figsize = (8,6))
plt.plot(history.history["accuracy"])
plt.plot(history.history["loss"])
plt.ylim([0,max(plt.ylim())])
plt.xlabel('Epoch')
_ = plt.ylabel('loss')
plt.show()