diff --git a/forecasting/app.py b/forecasting/app.py index 0a289f9..d2e79e1 100644 --- a/forecasting/app.py +++ b/forecasting/app.py @@ -1,12 +1,13 @@ import numpy as np import pandas as pd import streamlit as st -from figure import * from likelihood.tools import * +from tensorflow.keras.models import load_model + +from figure import * # This files are in the forecasting folder from series import * -from tensorflow.keras.models import load_model np.random.seed(0) neural_network = load_model("forecasting/models/model_tensor.h5") @@ -50,7 +51,8 @@ # The dataset is generated data_ = generate_series(n, n_steps=100, incline=val) -data_scale, values = rescale(np.copy(data_)) +scaler = DataScaler(np.copy(data_)) +data_scale = scaler.rescale() series = convert_to_df(np.copy(data_)).describe() train, test = create_train_test_set(np.copy(data_scale), p_train=p_train) neural_network.fit(train[0], train[1]) @@ -82,7 +84,7 @@ """ ) -prediction = forecasting(model, train, data_.shape[1], values) +prediction = forecasting(model, train, data_.shape[1], scaler) fig2 = plot_series(convert_to_df(data_), prediction, i=i_serie) st.plotly_chart(fig2) diff --git a/forecasting/model_tensor.py b/forecasting/model_tensor.py index b5513a1..a8f8b0d 100644 --- a/forecasting/model_tensor.py +++ b/forecasting/model_tensor.py @@ -1,3 +1,8 @@ +import os + +os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" +os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0" + import matplotlib.pyplot as plt import numpy as np import pandas as pd @@ -58,8 +63,8 @@ def on_epoch_end(self, epoch, logs): print(".", end="") -def make_predictions(model, input, n_steps): - X = input.copy() +def make_predictions(model, input_model, n_steps): + X = input_model.copy() for step_ahead in range(n_steps): y_pred_one = model.predict(X[:, step_ahead:]) y_pred_one = y_pred_one[:, :, np.newaxis] @@ -69,12 +74,13 @@ def make_predictions(model, input, n_steps): if __name__ == "__main__": - num_series = 500 + num_series = 80 series_size = 100 n_steps = 5 - input = generate_series(num_series, series_size, incline=False) - y_new = input[:, :-n_steps] + input_serie = generate_series(num_series, series_size, incline=False) + y_new = input_serie[:, :-n_steps] + print(y_new.shape) scaler = DataScaler(y_new) y_new = scaler.rescale() size_ = int(0.8 * y_new.shape[0]) @@ -92,7 +98,7 @@ def make_predictions(model, input, n_steps): # model(x_train[:, :, np.newaxis]) model.compile(loss="mse", optimizer="sgd", metrics=["mae"]) history = model.fit( - x_train[:, :, np.newaxis], y_train, epochs=30, validation_split=0.2, callbacks=[PrintDot()] + x_train[:, :, np.newaxis], y_train, epochs=100, validation_split=0.2, callbacks=[PrintDot()] ) hist = pd.DataFrame(history.history) @@ -110,7 +116,7 @@ def make_predictions(model, input, n_steps): print(X.shape) X = scaler.scale(X) - plt.plot(range(len(input[0, :])), input[0, :], "o-", label="real value") + plt.plot(range(len(input_serie[0, :])), input_serie[0, :], "o-", label="real value") plt.plot(range(len(X[0, :]))[-n_steps * 4 :], X[0, :][-n_steps * 4 :], "-r", label="prediction") plt.xlabel("Time") plt.ylabel("Value") diff --git a/forecasting/models/model_tensor.h5 b/forecasting/models/model_tensor.h5 index 59da3f9..f9ec713 100644 Binary files a/forecasting/models/model_tensor.h5 and b/forecasting/models/model_tensor.h5 differ