def predict_apple():
    csv = 'assets/Apple.csv'
    global model, graph, last, df
    model, graph = init('apple_model')
    df = pd.read_csv(csv)
    df = df.set_index('Date')
    df = df.iloc[:, 10:11].values
    df = np.array(df)
    df = scaler.fit_transform(df)
    last = length(csv)
    x = [df[last - 60:last, 0]]
    x = np.array(x)
    x = x.reshape(1, x.shape[1], 1)
    pred = model.predict(x)
    K.clear_session()
    prediction = scaler.inverse_transform(pred)
    return prediction[0]
Esempio n. 2
0
csv = '../assets/Apple.csv'
scaler = MinMaxScaler(feature_range=(0, 1))

df = pd.read_csv(csv, header=0)
df = df.set_index('Date')
df = df[::-1]
df = df.iloc[:, 10:11].values

print(df[0:5])

data = scaler.fit_transform(df)

X = []
y = []
for i in range(60, length(csv)):
    X.append(data[i - 60:i, 0])
    y.append(data[i, 0])

X = np.array(X)
y = np.array(y)

X = X.reshape(X.shape[0], X.shape[1], 1)

model = Sequential()

model.add(LSTM(64, input_shape=(X.shape[1], 1), return_sequences=True))
model.add(Dropout(.1))
model.add(LSTM(64, return_sequences=True))
model.add(Dropout(.1))
model.add(LSTM(64))