<jupyter_start><jupyter_text>Model and Training<jupyter_code>regressor = Sequential()

regressor.add(LSTM(units=50, return_sequences=True, input_shape=(X_train.shape[1], 1)))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50, return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50, return_sequences=False))
regressor.add(Dropout(0.2))
regressor.add(Dense(units=1))

regressor.compile(optimizer='adam', loss='mean_squared_error', metrics=['accuracy'])

regressor.summary()
regressor.fit(X_train, y_train, epochs=100, batch_size=32)<jupyter_output>Epoch 1/100
38/38 [==============================] - 1s 13ms/step - loss: 0.0461 - accuracy: 0.0017
Epoch 2/100
38/38 [==============================] - 0s 12ms/step - loss: 0.0060 - accuracy: 0.0017
Epoch 3/100
38/38 [==============================] - 0s 12ms/step - loss: 0.0053 - accuracy: 0.0017
Epoch 4/100
38/38 [==============================] - 0s 12ms/step - loss: 0.0056 - accuracy: 0.0017
Epoch 5/100
38/38 [==============================] - 0s 12ms/step - loss: 0.0052 - accuracy: 0.0017
Epoch 6/100
38/38 [==============================] - 0s 12ms/step - loss: 0.0049 - accuracy: 0.0017
Epoch 7/100
38/38 [==============================] - 0s 12ms/step - loss: 0.0046 - accuracy: 0.0017
Epoch 8/100
38/38 [==============================] - 0s 12ms/step - loss: 0.0046 - accuracy: 0.0017
Epoch 9/100
38/38 [==============================] - 0s 12ms/step - loss: 0.0041 - accuracy: 0.0017
Epoch 10/100
38/38 [==============================] - 1s 17ms/step - loss: 0.0042 - accuracy: 0.0017[...]<jupyter_text>Testing<jupyter_code>dataset_test = pd.read_csv('Google_Stock_Price_Test.csv')
real_stock_prices = dataset_test.iloc[:, 1:2].values
# Getting predicted values of google stock price for the next month where the training set ends
dataset_total = pd.concat((dataset_train['Open'], dataset_test['Open']), axis=0)
# to predict stock price of one day we will need all the stock prices of 60 days before that day which will come from both training and test set
# therefore we concatenate the training and test sets
inputs = dataset_total[len(dataset_total)-len(dataset_test)-60:]
# inputs contains all the values we are going to need for making predictions of stock prices for one month after the training dataset
inputs = inputs.values.reshape(-1, 1)
print(inputs.shape)
# 80 because one month only has 20 financial days (20+60)
inputs = sc.transform(inputs)
X_test = []
for i in range(60, 80):  # 20 financial days in one month
    X_test.append(inputs[i-60:i, 0])
    # stores all 20 arrays containing 60 values used for making prediction for each financial day in a month
X_test = np.array(X_test)
X_test = np.reshape(X_test, (X_test.shape[0], X_test.shape[1], 1))
X_test.shape
predicted_stock_prices = regressor.predict(X_test)
predicted_stock_prices = sc.inverse_transform(predicted_stock_prices)
predicted_stock_prices.shape
plt.plot(real_stock_prices, color='red', label='Real Google Stock Price')
plt.plot(predicted_stock_prices, color='blue', label='Predicted Google Stock Price')
plt.title('Google Stock Price Prediction')
plt.xlabel('Time')
plt.ylabel('Google Stock Price')
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20973103656693864, 'fraction_numerical': 0.08099123602296766, 'mean_word_length': 5.810699588477366, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '257315', 'license': 'MIT', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1083, 'n_words': 285, 'path': 'RNN-StockPrices/model.ipynb', 'repo_name': 'Frostday/Small-Tensorflow-Projects', 'size': '3309'}