<jupyter_start><jupyter_text>Days of prediction:<jupyter_code># How many periods looking back to learn
n_per_in  = 90
# How many periods to predict
n_per_out = 30
# Features 
n_features = df.shape[1]
# Splitting the data into appropriate sequences
X, y = split_sequence(df.to_numpy(), n_per_in, n_per_out)<jupyter_output><empty_output><jupyter_text>Modding the network:<jupyter_code>## Creating the NN

# Instatiating the model
model = Sequential()

# Activation
activ = "tanh"

# Input layer
model.add(LSTM(90, 
               activation=activ, 
               return_sequences=True, 
               input_shape=(n_per_in, n_features)))

# Hidden layers
layer_maker(n_layers=1, 
            n_nodes=50, 
            activation=activ)

# Final Hidden layer
model.add(LSTM(60, activation=activ))

# Output layer
model.add(Dense(n_per_out))

# Model summary
model.summary()

# Compiling the data with selected specifications
model.compile(optimizer='adam', loss='mse', metrics=['accuracy'])

## Fitting and Training
res = model.fit(X, y, epochs=200, batch_size=128, validation_split=0.1)
visualize_training_results(res)
# Transforming the actual values to their original price
actual = pd.DataFrame(close_scaler.inverse_transform(df[["Close"]]), 
                      index=df.index, 
                      columns=[df.columns[0]])

# Getting a DF of the predicted values to validate against
predictions = validater(n_per_in, n_per_out)

# Printing the RMSE
print("RMSE:", val_rmse(actual, predictions))
    
# Plotting
pp.figure(figsize=(16,6))

# Plotting those predictions
pp.plot(predictions, label='Predicted')

# Plotting the actual values
pp.plot(actual, label='Actual')

pp.title(f"Predicted vs Actual Closing Prices")
pp.ylabel("Price")
pp . legend ()
# pp . xlim ( '2015-05-01' , '2020-05-01' )
pp.show()
# Predicting off of the most recent days from the original DF
yhat = model.predict(np.array(df.tail(n_per_in)).reshape(1, n_per_in, n_features))

# Transforming the predicted values back to their original format
yhat = close_scaler.inverse_transform(yhat)[0]

# Creating a DF of the predicted prices
preds = pd.DataFrame(yhat, 
                     index=pd.date_range(start=df.index[-1]+timedelta(days=1), 
                                         periods=len(yhat), 
                                         freq="B"), 
                     columns=[df.columns[0]])

# Number of periods back to plot the actual values
pers = n_per_in

# Transforming the actual values to their original price
actual = pd.DataFrame(close_scaler.inverse_transform(df[["Close"]].tail(pers)), 
                      index=df.Close.tail(pers).index, 
                      columns=[df.columns[0]]).append(preds.head(1))

# Printing the predicted prices
print(preds)

# Plotting
pp.figure(figsize=(16,6))
pp.plot(actual, label="Actual Prices")
pp.plot(preds, label="Predicted Prices")
pp.ylabel("Price")
pp.xlabel("Dates")
pp.title(f"Forecasting the next {len(yhat)} days")
pp . legend ()
pp.show()<jupyter_output>Close
2020-05-25  4037.141602
2020-05-26  4419.875000
2020-05-27  4144.038086
2020-05-28  4141.793945
2020-05-29  4467.413574
2020-06-01  4275.016113
2020-06-02  4079.013184
2020-06-03  3970.238281
2020-06-04  4183.469238
2020-06-05  3941.726318
2020-06-08  4045.078125
2020-06-09  4131.540039
2020-06-10  4403.567383
2020-06-11  4384.712891
2020-06-12  4689.707031
2020-06-15  4965.892578
2020-06-16  4843.812988
2020-06-17  5389.931152
2020-06-18  5655.073242
2020-06-19  6072.718750
2020-06-22  6277.929199
2020-06-23  6442.253906
2020-06-24  6295.768066
2020-06-25  6322.183594
2020-06-26  6333.503418
2020-06-29  5820.988281
2020-06-30  5685.297852
2020-07-01  5393.449219
2020-07-02  5466.540039
2020-07-03  5372.300781
{'fraction_non_alphanumeric': 0.12031082529474812, 'fraction_numerical': 0.15809217577706325, 'mean_word_length': 3.492178098676294, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '322772', 'license': 'MIT', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1336, 'n_words': 290, 'path': 'Stocks/Stock King 2.1-Copy1.ipynb', 'repo_name': 'ali-kin4/JupyterNotes-1', 'size': '3732'}