<jupyter_start><jupyter_text>Recurrent Neural Network  Part 1 - Data Preprocessing  Importing the libraries<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd<jupyter_output><empty_output><jupyter_text>Importing the training set<jupyter_code>dataset_train = pd.read_csv('cubtrain3.csv')
training_set = dataset_train.iloc[:, 1:2].values
len(training_set)<jupyter_output><empty_output><jupyter_text>Feature Scaling<jupyter_code>from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler(feature_range = (0, 1))
training_set_scaled = sc.fit_transform(training_set)
training_set_scaled<jupyter_output><empty_output><jupyter_text>Creating a data structure with 60 timesteps and 1 output<jupyter_code>X_train = []
y_train = []
for i in range(60, 1259):
    X_train.append(training_set_scaled[i-60:i, 0])
    y_train.append(training_set_scaled[i, 0])
X_train, y_train = np.array(X_train), np.array(y_train)<jupyter_output><empty_output><jupyter_text>Reshaping<jupyter_code>X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 1))<jupyter_output><empty_output><jupyter_text>Part 2 - Building and Training the RNN  Importing the Keras libraries and packages<jupyter_code>from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Dropout<jupyter_output><empty_output><jupyter_text>Initialising the RNN<jupyter_code>regressor = Sequential()<jupyter_output><empty_output><jupyter_text>Adding the first LSTM layer and some Dropout regularisation<jupyter_code>regressor.add(LSTM(units = 100, return_sequences = True, input_shape = (X_train.shape[1], 1)))
regressor.add(Dropout(0.5))<jupyter_output><empty_output><jupyter_text>Adding a second LSTM layer and some Dropout regularisation<jupyter_code>regressor.add(LSTM(units = 100, return_sequences = True))
regressor.add(Dropout(0.5))<jupyter_output><empty_output><jupyter_text>Adding a third LSTM layer and some Dropout regularisation<jupyter_code>regressor.add(LSTM(units = 100, return_sequences = True))
regressor.add(Dropout(0.5))<jupyter_output><empty_output><jupyter_text>Adding a fourth LSTM layer and some Dropout regularisation<jupyter_code>regressor.add(LSTM(units = 100))
regressor.add(Dropout(0.5))<jupyter_output><empty_output><jupyter_text>Adding the output layer<jupyter_code>regressor.add(Dense(units = 1))<jupyter_output><empty_output><jupyter_text>Compiling the RNN<jupyter_code>regressor.compile(optimizer = 'adam', loss = 'mean_squared_error',metrics="accuracy")<jupyter_output><empty_output><jupyter_text>Fitting the RNN to the Training set<jupyter_code>regressor.fit(X_train, y_train, epochs = 500, batch_size =10)<jupyter_output>Epoch 1/500
120/120 [==============================] - 29s 127ms/step - loss: 0.0089 - accuracy: 0.0011
Epoch 2/500
120/120 [==============================] - 17s 139ms/step - loss: 0.0070 - accuracy: 0.0014
Epoch 3/500
120/120 [==============================] - 16s 137ms/step - loss: 0.0052 - accuracy: 0.0014
Epoch 4/500
120/120 [==============================] - 17s 139ms/step - loss: 0.0049 - accuracy: 2.6198e-04
Epoch 5/500
120/120 [==============================] - 18s 148ms/step - loss: 0.0047 - accuracy: 0.0011
Epoch 6/500
120/120 [==============================] - 18s 152ms/step - loss: 0.0043 - accuracy: 4.9817e-04
Epoch 7/500
120/120 [==============================] - 19s 157ms/step - loss: 0.0043 - accuracy: 0.0026
Epoch 8/500
120/120 [==============================] - 19s 158ms/step - loss: 0.0042 - accuracy: 0.0016
Epoch 9/500
120/120 [==============================] - 18s 153ms/step - loss: 0.0035 - accuracy: 6.0410e-04
Epoch 10/500
120/120 [==============================[...]<jupyter_text>Part 3 - Making the predictions and visualising the results  Getting the real stock price of 2017<jupyter_code>dataset_test = pd.read_csv('cubtest3.csv')
real_stock_price = dataset_test.iloc[:, 1:2].values<jupyter_output><empty_output><jupyter_text>Getting the predicted stock price of 2017<jupyter_code>dataset_total = pd.concat((dataset_train['Open'], dataset_test['Open']), axis = 0)
inputs = dataset_total[len(dataset_total) - len(dataset_test) - 60:].values
inputs = inputs.reshape(-1,1)
inputs = sc.transform(inputs)
X_test = []
for i in range(60, 81):
    X_test.append(inputs[i-60:i, 0])
X_test = np.array(X_test)
X_test = np.reshape(X_test, (X_test.shape[0], X_test.shape[1], 1))
predicted_stock_price = regressor.predict(X_test)
predicted_stock_price = sc.inverse_transform(predicted_stock_price)<jupyter_output><empty_output><jupyter_text>Visualising the results<jupyter_code>plt.plot(real_stock_price, color = 'red', label = 'Real Google Stock Price')
plt.plot(predicted_stock_price, 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()
regressor.save('my_model_cub4.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17688584106494554, 'fraction_numerical': 0.06494554255748286, 'mean_word_length': 7.579584775086505, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 68, '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': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '247881', 'license': 'Apache-2.0', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1739, 'n_words': 334, 'path': 'Stock_price_prediction_.ipynb', 'repo_name': 'suriya7913/stock-price-prediction-using-lstm', 'size': '4958'}