Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
eue
Commits
c1753ef8
Commit
c1753ef8
authored
Aug 04, 2021
by
박예은
Browse files
데이터 분석 과정 작성
parent
46008734
Changes
3
Show whitespace changes
Inline
Side-by-side
server/src/data_processing/main.py
View file @
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
()
...
...
server/src/data_processing/model.py
0 → 100644
View file @
c1753ef8
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
server/src/data_processing/preprocessing.py
View file @
c1753ef8
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment