-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.py
80 lines (63 loc) · 3.12 KB
/
Functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import pandas as pd
import numpy as np
# import data
# create training sets and test sets
def import_data():
file_names = [
'Commercial1.csv', 'Commercial2.csv', 'Commercial3.csv', 'Commercial4.csv', 'Commercial5.csv',
'Commercial6.csv', 'Commercial7.csv', 'Commercial8.csv', 'Commercial9.csv', 'Commercial10.csv',
'Hospital1.csv', 'Hospital2.csv', 'Hospital3.csv',
'Office1.csv', 'Office2.csv', 'Office3.csv', 'Office4.csv', 'Office5.csv',
'Sport1.csv', 'Sport2.csv', 'Sport3.csv',
'Tourist1.csv', 'Tourist2.csv', 'Tourist3.csv', 'Tourist4.csv',
'Residential1.csv', 'Residential2.csv', 'Residential3.csv', 'Residential4.csv', 'Residential5.csv'
]
X = []
for file in file_names:
dataset = pd.read_csv(f'D:/Edge/ECE1724F/Project/Reference/nh2358f5mf-4/nh2358f5mf-4/dataset/{file}')
rate_values = dataset['RATE'].values.astype('float32')
X.append(rate_values)
train_size = int(0.8 * len(X[0]))
test_size = len(X[0]) - train_size
return X, train_size, test_size
# trend feature
def create_interval_dataset(dataset, look_back):
dataX, dataY = [], []
for i in range(len(dataset) - look_back):
dataX.append(dataset[i])
dataY.append(dataset[i+look_back])
return np.asarray(dataX), np.asarray(dataY)
# cycle feature
def create_cycle_dataset(dataset, look_back):
dataX, dataY = [], []
for i in range(len(dataset) - look_back * 2):
dataX.append(dataset[i:i + look_back])
dataY.append(dataset[i + look_back:i + look_back + look_back])
return np.asarray(dataX), np.asarray(dataY)
# RNN parameters
def create_RNNs_dataset(dataset, look_back):
dataX, dataY = [], []
for i in range(len(dataset) - look_back * 2):
dataX.append(dataset[i:i + look_back])
dataY.append(dataset[i + look_back + look_back])
return np.asarray(dataX), np.asarray(dataY)
# import time-series-decomposition dataset
def import_TSD_data():
file_names = [
'Commercial1.csv', 'Commercial2.csv', 'Commercial3.csv', 'Commercial4.csv', 'Commercial5.csv',
'Commercial6.csv', 'Commercial7.csv', 'Commercial8.csv', 'Commercial9.csv', 'Commercial10.csv',
'Hospital1.csv', 'Hospital2.csv', 'Hospital3.csv',
'Office1.csv', 'Office2.csv', 'Office3.csv', 'Office4.csv', 'Office5.csv',
'Sport1.csv', 'Sport2.csv', 'Sport3.csv',
'Tourist1.csv', 'Tourist2.csv', 'Tourist3.csv', 'Tourist4.csv',
'Residential1.csv', 'Residential2.csv', 'Residential3.csv', 'Residential4.csv', 'Residential5.csv'
]
RATE, FS, INDICATOR = [], [], []
for file in file_names:
dataset = pd.read_csv(f'D:/Edge/ECE1724F/Final/Project_test/dataset/{file}')
RATE.append(dataset['RATE'].values.astype('float32'))
FS.append(dataset['FS'].values.astype('float32')) # Cycle features after FT
INDICATOR.append(dataset['INDICATOR'].values.astype('float32'))
train_size = int(0.8 * len(RATE[0]))
test_size = len(RATE[0]) - train_size
return RATE, FS, INDICATOR, train_size, test_size