diff --git a/server/src/data_processing/model.py b/server/src/data_processing/model.py index 02589b495961e2ab477f143932fdf99731a4810a..2dd1c5bb61e972aae0cd956918aacca509b194aa 100644 --- a/server/src/data_processing/model.py +++ b/server/src/data_processing/model.py @@ -36,7 +36,7 @@ def modeling(standard_df): model = tf.keras.Sequential([ tf.keras.layers.LSTM(16, return_sequences=False, - input_shape=(6, 7)), + input_shape=(6, 8)), tf.keras.layers.Dense(1) ]) @@ -44,7 +44,3 @@ def modeling(standard_df): # model.fit(train_feature, train_label, epochs=50, batch_size=1000) model.save(os.getcwd() + '/src/data_processing/model.h5') - - -# 사용할때 -# new = tf.keras.models.load_model('/src/dataprocessing/model.h5') diff --git a/server/src/data_processing/prediction.py b/server/src/data_processing/prediction.py index 29c4abd570e9dd8e2633609ca40df9e29b5a752c..ed1b3f207a70257a2f5f8c7c1e8b32cddef7d8a1 100644 --- a/server/src/data_processing/prediction.py +++ b/server/src/data_processing/prediction.py @@ -5,6 +5,10 @@ import json import os import psycopg2 import sys +import pandas as pd +import tensorflow as tf +import numpy as np + if __name__ == "__main__": @@ -66,7 +70,30 @@ if __name__ == "__main__": data_file.close() cursor.close() - prediction = "Result_of_Prediction_Process" + data_list = pd.read_csv(data_dir) + new_data = data_list[-6:] + + date_time = pd.to_datetime(new_data['date'], format='%Y-%m-%d %H:%M') + timestamp_s = date_time.map(datetime.datetime.timestamp) + + new_data = new_data[['temp_out', 'humi_out', 'press', 'wind_speed']] + day = 24*60*60 + year = (365.2425)*day + + new_data['Day sin'] = np.sin(timestamp_s * (2 * np.pi / day)) + new_data['Day cos'] = np.cos(timestamp_s * (2 * np.pi / day)) + new_data['Year sin'] = np.sin(timestamp_s * (2 * np.pi / year)) + new_data['Year cos'] = np.cos(timestamp_s * (2 * np.pi / year)) + + feature_cols = ['temp_out', 'humi_out', 'press', + 'wind_speed', 'Day sin', 'Day cos', 'Year sin', 'Year cos'] + for col in feature_cols: + new_data[col] = (new_data[col] - mean[col]) / std[col] + + model_pro = tf.keras.models.load_model(model_dir) + prediction = model_pro.predict(new_data) + prediction = prediction * std['temp_out'] + mean['temp_out'] + # 사용한 파일 삭제 if os.path.isfile(data_dir):