Commit a74a13f7 authored by KangMin An's avatar KangMin An
Browse files

Merge branch 'yeni111' into premaster

parents adecec1c c1753ef8
......@@ -6,6 +6,7 @@
"""
import datetime
from server.src.data_processing.model import modeling
import sys
import psycopg2
......@@ -37,14 +38,14 @@ for user in users:
host = {"email": user[0], "loc_code": user[1], "using_aircon": user[2]}
# 데이터 전처리
preprocess(cursor, host)
standard_df, mean_df , std_df = preprocess(cursor, host)
# 데이터 분석
params = "main_proceduer_function"
modeling(standard_df)
# 데이터 분석 결과 저장
cursor.execute("INSERT INTO \"Data_Processings\" (host,collected_at,params) VALUES (%s,%s,%s)",
(host["email"], collected_at, params))
# cursor.execute("INSERT INTO \"Data_Processings\" (host,collected_at,params) VALUES (%s,%s,%s)",
# (host["email"], collected_at, params))
# Cursor와 Connection 종료
cursor.close()
......
from preprocessing import standard_df
import numpy as np
import tensorflow as tf
def modeling(standard_df):
n= len(standard_df)
test_size = int(0.3 * n)
train = standard_df[:-test_size]
test = standard_df[-test_size:]
def make_dataset(data, label, window_size = 24):
feature_list = []
label_list = []
for i in range(len(data) - window_size):
feature_list.append(np.array(data.iloc[i:i+window_size]))
label_list.append(np.array(label.iloc[i + window_size ]))
return np.array(feature_list), np.array(label_list)
feature_cols = ['temp_out','humi_out','press','wind_speed','Day sin','Day cos','Year sin','Year cos']
label_cols = ['temp_out']
train_feature = train[feature_cols]
train_label = train[label_cols]
test_feature = test[feature_cols]
test_label = test[label_cols]
train_feature, train_label = make_dataset(train_feature, train_label,window_size=6)
test_feature, test_label = make_dataset(test_feature, test_label,window_size=6)
model = tf.keras.Sequential([
tf.keras.layers.LSTM(16,
return_sequences=False,
input_shape = (6,7)),
tf.keras.layers.Dense(1)
])
model.compile(loss = 'mse',optimizer = 'adam')
model.fit(train_feature, train_label,
epochs =50, batch_size = 1000)
model.save('/src/dataprocessing/model.h5')
#사용할때
# new = tf.keras.models.load_model('/src/dataprocessing/model.h5')
\ No newline at end of file
......@@ -6,6 +6,10 @@
"""
import pandas as pd
import datetime
import numpy as np
def preprocess(cursor, host):
"""
### preprocess(cursor, host)
......@@ -34,3 +38,27 @@ def preprocess(cursor, host):
result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7]))
file.close()
df = pd.read_csv("/src/dataprocessing/temp.csv")
date_time = pd.to_datetime(df['date'], format='%Y-%m-%d %H:%M')
timestamp_s = date_time.map(datetime.datetime.timestamp)
df = df[['temp_out','humi_out','press','wind_speed']]
day = 24*60*60
year = (365.2425)*day
df['Day sin'] = np.sin(timestamp_s * (2 * np.pi / day))
df['Day cos'] = np.cos(timestamp_s * (2 * np.pi / day))
df['Year sin'] = np.sin(timestamp_s * (2 * np.pi / year))
df['Year cos'] = np.cos(timestamp_s * (2 * np.pi / year))
def standard(dataframe):
mean = dataframe.mean()
std = dataframe.std()
zscore = ( dataframe - mean ) / std
return zscore, mean, std
standard_df, mean_df , std_df = standard(df)
return standard_df, mean_df , std_df
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment