# -*- coding: utf-8 -*-
"""RNNGoogle.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/118emqjT_vowzhKLjeVb2NlSDeOCr10Pt
"""

import numpy as np
import pandas as pd

from sklearn.preprocessing import StandardScaler,MinMaxScaler
import matplotlib.pyplot as plt

data=pd.read_csv("GOOG.csv")
print(data.shape)

training_data=data[data['Date']<'2020-02-06'].copy()
print(training_data)

training_data=training_data.drop(["Date", "Adj Close"],axis=1)
past_50_days=training_data.tail(50)
print(training_data)

scaler=MinMaxScaler()
training_data=scaler.fit_transform(training_data)
print(training_data)

X_train=[]
Y_train=[]

training_data.shape

for i in range(20,training_data.shape[0]):
  X_train.append(training_data[i-20:i])
  Y_train.append(training_data[i,0])

X_train , Y_train=np.array(X_train) , np.array(Y_train)

X_train.shape , Y_train.shape

from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, LSTM, Dropout

regressior=Sequential()

regressior.add(LSTM(units=60,activation='relu',return_sequences=True,input_shape=(X_train.shape[1],5)))
regressior.add(Dropout(0.2))

regressior.add(LSTM(units=60,activation='relu',return_sequences=True))
regressior.add(Dropout(0.2))

regressior.add(LSTM(units=60,activation='relu',return_sequences=True))
regressior.add(Dropout(0.2))

regressior.add(LSTM(units=60,activation='relu'))
regressior.add(Dropout(0.2))

regressior.add(Dense(units=1))

regressior.summary()

regressior.compile(optimizer="adam",loss="mean_squared_error")

data=pd.read_csv("GOOG.csv")
regressior.fit(X_train,Y_train,epochs=25,batch_size=16)

inputs=scaler.transform(past_50_days)
inputs

X_test=[]
Y_test=[]

for i in range(20,inputs.shape[0]):
  X_test.append(inputs[i-20:i])
  Y_test.append(inputs[i,0])

X_test ,Y_test = np.array(X_test) , np.array(Y_test)
X_test.shape  , Y_test.shape

y_pred=regressior.predict(X_test)
Y_test

scaler.scale_

scale=1/2.21882032e-03
scale

y_pred=y_pred*scale
Y_test=Y_test*scale

Y_test

y_pred

plt.figure(figsize=(15, 5));
plt.plot(Y_test,color="red",label="Real Prices")
plt.plot(y_pred,color="blue",label="Predicted Prices")
plt.title("Google Stock Price Prediction")
plt.xlabel("Time")
plt.ylabel("Price")
plt.legend()
plt.show()

from keras.applications import VGG16
conv_base = VGG16(weights='imagenet',
                  include_top=False,
                  input_shape=(240, 240, 3))