diff --git a/api/__pycache__/app.cpython-310.pyc b/api/__pycache__/app.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a694bd589ce1602823bdfe06ffd3bb86cfc44283 Binary files /dev/null and b/api/__pycache__/app.cpython-310.pyc differ diff --git a/api/run.py b/api/run.py index 188c22158bd562da0d6f8e190fc4d4780ac6c54b..1b6646a0893de1f2e320c89c4bd2960c5ac28c33 100644 --- a/api/run.py +++ b/api/run.py @@ -47,7 +47,7 @@ data_set = pd.DataFrame() index_data_set = pd.DataFrame() tranning_set = pd.DataFrame() result = pd.DataFrame() -predictions_set = pd.DataFrame() +predictions_set = pd.DataFrame(columns=["Date","Order_Demand"]) decompose_set = pd.DataFrame() model_settings = pd.DataFrame() @@ -335,10 +335,19 @@ def setup(): model.add(LSTM(units=hidden_layer_2, activation='relu', return_sequences=False)) + model.add(Dense(units=32)) + + model.add(Dense(units=16)) + + model.add(Dense(units=4)) + + model.add(Dense(units=2)) + # Adding the output layer model.add(Dense(units=output_units)) # Compiling model - model.compile(optimizer='adam', loss='mean_squared_error') + # model.compile(optimizer='adam', loss='mean_squared_error') + model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy']) print(model.input) print(model.output) @@ -349,7 +358,26 @@ def setup(): start_time = time.time() # Fitting the RNN to the Training set - model_history = model.fit(x_train, y_train, batch_size, epochs) + history = model.fit(x_train, y_train, batch_size, epochs) + + # list all data in history + print(history.history.keys()) + # summarize history for accuracy + plt.plot(history.history['accuracy']) + + plt.title('model accuracy') + plt.ylabel('accuracy') + plt.xlabel('epoch') + plt.legend(['train', 'test'], loc='upper left') + plt.show() + # summarize history for loss + plt.plot(history.history['loss']) + + plt.title('model loss') + plt.ylabel('loss') + plt.xlabel('epoch') + plt.legend(['train', 'test'], loc='upper left') + plt.show() end_time = time.time() execute_time = round((end_time-start_time)/60, 2) @@ -408,25 +436,7 @@ setup() # end points declaration -@app.route("/plot_result", methods=['GET']) -def plot_result(): - # plotting the full data - plt.plot(result["Predictions"], color='blue', - label='Predicted Order Demand') - plt.plot(result["OrderDemand"], color='lightblue', label='Original Price') - plt.title('Order Demand Predictions') - plt.xlabel(' Date') - plt.ylabel('Order Demand') - plt.legend() - fig = plt.gcf() - fig.set_figwidth(20) - fig.set_figheight(8) - plt.show() - - return "plot complete" - -#---------------------------------------------------------------- @app.route("/predict_for_one_product", methods=['POST']) def predict_for_one_product(): @@ -569,37 +579,28 @@ def predicpredict_result(): return predictions_set.to_json(orient='records') -@app.route("/plot_order-demands", methods=['GET']) -def plot_order_demands_total(): - global raw_data_set - sns.lineplot(x='Date', y='Order_Demand', - hue='Warehouse', data=raw_data_set) - plt.figure(figsize=(20, 7)) - plt.xticks(rotation=15) - plt.gcf().autofmt_xdate() - - plt.legend() - plt.show() - - return "Order demand" - - -@app.route("/plot_order_demand_total", methods=['GET']) -def plot_order_demands(): - global data_set - dtFmt = mdates.DateFormatter('%Y-%b') # define the formatting +@app.route("/plot_result", methods=['GET']) +def plot_result(): - sns.lineplot(x='Date', y='Order_Demand', data=data_set) - plt.figure(figsize=(20, 7)) - plt.gca().xaxis.set_major_formatter(dtFmt) - # show every 12th tick on x axes - plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1)) - plt.xticks(rotation=90, fontweight='light', fontsize='x-small',) + # plotting the full data + plt.plot(result["Date"],result["Predictions"], color='blue', + label='Predicted Order Demand') + plt.plot(result["Date"],result["OrderDemand"], color='lightblue', label='Order Demands') + plt.plot(predictions_set["Date"],predictions_set["Order_Demand"], color='orange', label='predicted') + plt.title('Order Demand Predictions') + plt.xlabel(' Date') + plt.ylabel('Order Demand') plt.legend() + plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=90)) + fig = plt.gcf() + fig.set_figwidth(20) + fig.set_figheight(8) plt.show() - return "Order demand" + return "plot complete" + +#---------------------------------------------------------------- @app.route("/products", methods=['GET']) @@ -636,37 +637,6 @@ def validation(): return result.to_json(orient='records') -@app.route("/forecast_to_date", methods=["POST"]) -def forecast_to_date(): - global data_set - global scaler - global index_data_set - global model - - # read incomming json data - data = request.get_json() - date = data['date'] - new_date = datetime.strptime(date, "%Y-%m-%d").date() - new_date = new_date - timedelta(days=(feature_length-1)) - new_date = new_date.strftime("%Y-%m-%d") - print(new_date) - - result = predict_given_date(index_data_set, new_date, feature_length) - # df=pd.DataFrame() - # # df=pd.DataFrame(data=result,columns=["Prediction"]) - # df['Date']=pd.date_range(start=new_date,periods=feature_length) - # df=df.loc[::-1] - # df['Prediction']=result - - # df['Date']= pd.to_datetime(df['Date']).dt.date - # df.sort_values('Date', inplace=True) - # df['Date']=df['Date'].astype(str) - # df=df.set_index(df['Date']) - # df=df.tail(1) - - return result - - @app.route("/forecast_to_range", methods=["POST"]) def forecast_to_range(): global data_set diff --git a/inc/function.php b/inc/function.php index e1c54d9b7226cf4a199736b4fb50b2d0d69f360c..5368ff118faee9e6c856ce191e96c0365982e8a7 100644 --- a/inc/function.php +++ b/inc/function.php @@ -15,8 +15,50 @@ function get_accurecy($conn){ } -function get_layer_1_nodes(){ +function get_layer_1_nodes($conn){ + $sql = "select input_units from model_settings ORDER BY id DESC LIMIT 1"; + + $result = mysqli_query($conn, $sql); + $res = mysqli_fetch_assoc($result); + + + return $res['input_units']; + +} + +function get_layer_2_nodes($conn){ + + $sql = "select hidden_layer_1 from model_settings ORDER BY id DESC LIMIT 1"; + + $result = mysqli_query($conn, $sql); + $res = mysqli_fetch_assoc($result); + + + return $res['hidden_layer_1']; + +} + +function get_layer_3_nodes($conn){ + + $sql = "select hidden_layer_2 from model_settings ORDER BY id DESC LIMIT 1"; + + $result = mysqli_query($conn, $sql); + $res = mysqli_fetch_assoc($result); + + + return $res['hidden_layer_2']; + +} +function get_layer_4_nodes($conn){ + + $sql = "select output_units from model_settings ORDER BY id DESC LIMIT 1"; + + $result = mysqli_query($conn, $sql); + $res = mysqli_fetch_assoc($result); + + + return $res['output_units']; } diff --git a/info_box.php b/info_box.php index fd750de381050d8de459889cb94f28e1878bc6ac..bda6f45cf17cab3c4fb0beb2b44d52ab2a38605d 100644 --- a/info_box.php +++ b/info_box.php @@ -8,8 +8,8 @@ <span class="info-box-icon bg-info elevation-1"><i class="fas fa-brain"></i></span> <div class="info-box-content"> - <span class="info-box-text">LSTM Time Steps</span> - <a href="user_daily_statement_dash.php"><span class="info-box-number"><?=get_time_steps($conn)?></span></a> + <span class="info-box-text">LSTM Nodes</span> + <a href="settings_list.php"><span class="info-box-number"><?=get_layer_1_nodes($conn)?>-<?=get_layer_2_nodes($conn)?>-<?=get_layer_3_nodes($conn)?>-<?=get_layer_4_nodes($conn)?></span></a> </div> <!-- /.info-box-content --> </div> @@ -22,7 +22,7 @@ <div class="info-box-content"> <span class="info-box-text">Accurecy</span> - <a href="winner_paid_list.php"><span class="info-box-number"><?=get_accurecy($conn)?> %</span></a> + <a href="perforemence_list.php"><span class="info-box-number"><?=get_accurecy($conn)?> %</span></a> </div> <!-- /.info-box-content --> </div> @@ -41,7 +41,7 @@ <div class="info-box-content"> <span class="info-box-text">Times Trained</span> - <a href="game_list.php"><span class="info-box-number"><?=get_epochs($conn)?></span></a> + <a href="perforemence_list.php"><span class="info-box-number"><?=get_epochs($conn)?></span></a> </div> <!-- /.info-box-content --> </div> @@ -54,7 +54,7 @@ <div class="info-box-content"> <span class="info-box-text">Train Time</span> - <a href="user_list.php"><span class="info-box-number"><?= get_execute_time($conn)?> minutes</span> + <a href="perforemence_list.php"><span class="info-box-number"><?= get_execute_time($conn)?> minutes</span> </a> </div>