From 00d4d179271db8e0baedaec372c18da88436cc3c Mon Sep 17 00:00:00 2001 From: amilashanaka <dsa.amilashanaka@gmail.com> Date: Thu, 5 Jan 2023 01:41:06 +0000 Subject: [PATCH] Update model --- api/run.py | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/api/run.py b/api/run.py index 7efe0bb..eaad0e6 100644 --- a/api/run.py +++ b/api/run.py @@ -57,9 +57,13 @@ model = Sequential() feature_length = 100 testing_records=50 batch_size = 5 -epochs = 100 +epochs = 10 accuracy=0 execute_time=0 +layer_1_units=100 +layer_2_units=50 +layer_3_units=50 +dense_units=1 # Scaler scaler = MinMaxScaler() @@ -254,18 +258,18 @@ def setup(): #Add First LSTM Layer - model.add(LSTM(units = 100, activation = 'relu', input_shape = (time_steps, features), return_sequences=True)) + model.add(LSTM(units = layer_1_units, activation = 'relu', input_shape = (time_steps, features), return_sequences=True)) # Adding the Second hidden layer and the LSTM layer - model.add(LSTM(units = 50, activation = 'relu', input_shape = (time_steps, features), return_sequences=True)) + model.add(LSTM(units = layer_2_units, activation = 'relu', input_shape = (time_steps, features), return_sequences=True)) # Adding the Third hidden layer and the LSTM layer - model.add(LSTM(units = 50, activation = 'relu', return_sequences=False )) + model.add(LSTM(units = layer_3_units, activation = 'relu', return_sequences=False )) # Adding the output layer - model.add(Dense(units = 1)) + model.add(Dense(units = dense_units)) # Compiling model model.compile(optimizer = 'adam', loss = 'mean_squared_error') @@ -302,29 +306,13 @@ def setup(): # Generating predictions on full data TrainPredictions=scaler.inverse_transform(model.predict(x_train)) TestPredictions=scaler.inverse_transform(model.predict(x_test)) - FullDataPredictions=np.append(TrainPredictions, TestPredictions) - FullDataOrig=data[time_steps:] - - # plotting the full data - plt.plot(FullDataPredictions, color = 'blue', label = 'Predicted Price') - plt.plot(FullDataOrig , color = 'lightblue', label = 'Original Price') - - plt.title('Stock Price Predictions') - plt.xlabel('Trading Date') - plt.ylabel('Stock Price') - plt.legend() - fig=plt.gcf() - fig.set_figwidth(20) - fig.set_figheight(8) - plt.show() + # Save data to result data set result["Date"]=data_set.iloc[time_steps:]["Date"] result["Predictions"]=FullDataPredictions result["OrderDemand"]=data[time_steps:] - - print(data_set.tail(10)) # ==================================================================== # main function call -- GitLab