<jupyter_start><jupyter_text>data<jupyter_code>stocks_str = 'AAPL'#'GSIT, ICAD, XAIR, LTRN, ARKK, ARKF, ARKW'
ticker_list = [ticker.strip() for ticker in stocks_str.upper().split(',')]
stock_names = ticker_list[0:3]
time_diff_years= 8
column_metric = 'Adj Close'
company_name = 'AAPL'
lookback_length=100
batch_size=30
latest_day=-lookback_length
future_num_days=30
nodes=100
mf = ModelFit
# model=mf.gru_model(nodes=nodes)
model = mf.gru_stacked_model(nodes=nodes)
# model=mf.lstm_dense_model()
# model=mf.stack_3_lstm_model()
# model=mf.bi_stack_lstm_model()


file_name = IngestStocks.get_file_name(ticker_list=ticker_list, time_diff_years=time_diff_years)
# stocks_df = pd.read_pickle(file_name)
stocks_df = IngestStocks.ingest_stocks_to_df(ticker_list=ticker_list, time_diff_years=time_diff_years)
display(stocks_df)
stocks_df.to_pickle(file_name)
plot = VisualizeStocks.add_stocks_fig(stock_names=ticker_list, column_metric=column_metric,stocks_df=stocks_df)<jupyter_output><empty_output><jupyter_text>fit<jupyter_code>def main(model=None):
    train_ds, val_ds, test_ds = KerasPreprocess.keras_batch_preprocess(stocks_df=stocks_df, company_name=company_name, metric=column_metric, lookback_length=lookback_length, batch_size=batch_size)
    history, model = mf.train_model(train_data=train_ds, validation_data=val_ds, model=model)
    test_error = ModelPredict.evaluate_model(model, test_ds)
    train_error = pd.DataFrame(history.history)
    prediction_data = KerasPreprocess.get_prediction_data(stocks_df=stocks_df, company_name=company_name, metric=column_metric, lookback_length=lookback_length, latest_day=latest_day)
    predictions = ModelPredict.pred_next_days(future_num_days=future_num_days, previous_days=prediction_data, model=model)
    future_fig = VisualizeStocks.plot_future(predictions=predictions, stocks_df=stocks_df, latest_day=latest_day, future_num_days=future_num_days, company_name=company_name, column_metric=column_metric)
    return future_fig, train_error, test_error, model
fig, train_error, test_error, model = main()
display(train_error)
display(test_error)
fig = plot_model(model, expand_nested=True)
plt.show()
train_ds, val_ds, test_ds = KerasPreprocess.keras_batch_preprocess(stocks_df=stocks_df, company_name=company_name, metric=column_metric, lookback_length=lookback_length, batch_size=batch_size)
predictions = model.predict(test_ds).flatten()
column_list = KerasPreprocess.get_column_list(stocks_df=stocks_df, company_name=company_name, metric=column_metric)
data, targets = KerasPreprocess.get_data_targets_split(column_list=column_list, lookback_length=lookback_length)
data_train, data_val, data_test = KerasPreprocess.train_val_test_split(data)
targets_train, targets_val, targets_test = KerasPreprocess.train_val_test_split(targets)
display(model.evaluate(test_ds))
display(predictions[:-1].shape)
display(targets_test[lookback_length:].shape)
results = pd.DataFrame({'predict':predictions[:-1], 'targets':targets_test[lookback_length:]})
sns.lineplot(data=results)<jupyter_output>10/10 [==============================] - 0s 14ms/step - loss: 2812.2244 - mse: 2812.2244
{'fraction_non_alphanumeric': 0.11239193083573487, 'fraction_numerical': 0.012487992315081652, 'mean_word_length': 11.299212598425196, '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': '542501', 'license': 'MIT', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1139, 'n_words': 140, 'path': 'forecasting/end_to_end/app_dev.ipynb', 'repo_name': 'Duncan-Haywood/finance_ml_analysis', 'size': '3123'}