Skip to content

Commit

Permalink
Corrections added, tensorflow==2.15.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jzsmoreno committed Nov 5, 2024
1 parent 6951e38 commit 3f57c42
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
10 changes: 6 additions & 4 deletions forecasting/app.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 13 additions & 7 deletions forecasting/model_tensor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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])
Expand All @@ -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)
Expand All @@ -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")
Expand Down
Binary file modified forecasting/models/model_tensor.h5
Binary file not shown.

0 comments on commit 3f57c42

Please sign in to comment.