-
Notifications
You must be signed in to change notification settings - Fork 0
/
lstm1.py
34 lines (33 loc) · 1.41 KB
/
lstm1.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
# LSTM Model with window 100 out 1
from keras.models import load_model
import pandas as pd
import numpy as np
def lstm(start,end):
model = load_model('./model/lstm_k_100_o_1.h5')
df = pd.read_csv("./csv-files/BTC-USD.csv")
df['Date'] = pd.to_datetime(df['Date'])
df = df[df['Date'] >= start]
df = df[df['Date'] <= end]
df = df.reset_index(drop=True)
indexes = df.index.values
endindex = max(indexes)
dc = pd.DataFrame(df[['Open', 'Close', 'High', 'Low']])
# EG = df.iloc[0:100]
predict = dc.iloc[endindex-100 : endindex]
date = pd.DataFrame(df[['Date']])
date = date.iloc[endindex:]
expecteddf = pd.DataFrame(df[['Date', 'Close']])
expecteddf['Type'] = 'Observed'
tm = [3667.54092308, 3671.81879714, 3769.26483999, 3557.91619642]
ts = [3962.52179229, 3963.50740991, 4095.59464515, 3805.53750232]
predict = (predict - tm) / ts
predict = np.expand_dims(predict, axis = 0)
x = model.predict(predict)
x = (x * ts[1]) + tm[1]
dataframe = pd.DataFrame(x, columns=['Close'])
dataframe1 = pd.concat([date.reset_index(drop=True), dataframe], axis=1)
dataframe1['Type'] = 'Predicted'
print("\n\nAs this LSTM has one output might be possible that you undable to see so screen do output is displayed in terminal.")
print(dataframe1)
real = pd.concat([expecteddf, dataframe1]).reset_index(drop=True)
return real