refactor train/test

This commit is contained in:
Jamie
2021-05-07 15:41:10 -04:00
parent e92d844f92
commit 6706ace1c8
2 changed files with 10 additions and 5 deletions

View File

@@ -1023,7 +1023,6 @@ def lstm(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
)
if not ns_parser:
return
# Setup backtesting
# df_stock, df_future = _setup_backtesting(df_stock, ns_parser)
@@ -1046,7 +1045,7 @@ def lstm(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
test_data,
dates_test,
scaler,
) = prepare_scale_train_valid_test(df_stock, ns_parser)
) = prepare_scale_train_valid_test(df_stock["5. adjusted close"], ns_parser)
# Build Neural Network model
model = build_neural_network_model(
cfg_nn_models.Long_Short_Term_Memory, ns_parser.n_inputs, ns_parser.n_days
@@ -1061,6 +1060,13 @@ def lstm(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
validation_data=(X_test, y_test),
)
preds = model.predict(X_test.reshape(X_test.shape[0], X_test.shape[1], 1))
plt.scatter(df_stock.index, df_stock["5. adjusted close"].values, s= 3)
for i in range(len(y_test)):
plt.plot(y_dates_test[i], scaler.inverse_transform(preds[i].reshape(-1,1)), "r", lw=3)
plt.fill_between(y_dates_test[i])
plt.show()
# for idx_loop in range(ns_parser.n_loops):
# Train our model
# model.fit(

View File

@@ -102,10 +102,10 @@ def prepare_scale_train_valid_test(
dates[idx + n_input_days : idx + n_input_days + n_predict_days]
)
input_dates = np.array(input_dates)
input_dates = np.asarray(input_dates)
input_prices = np.array(input_prices)
next_n_day_prices = np.array(next_n_day_prices)
next_n_day_dates = np.array(next_n_day_dates)
next_n_day_dates = np.asarray(next_n_day_dates)
(
X_train,
@@ -123,7 +123,6 @@ def prepare_scale_train_valid_test(
next_n_day_dates,
test_size=test_size,
)
return (
X_train,
X_test,