Skip to content

Commit e295e36

Browse files
committed
[ update ]: remove asyncio features
1 parent 995815e commit e295e36

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

training/data_processor.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ filterwarnings('ignore')
66

77

88
""" Get Datasets """
9-
async def get_datasets(str datasets_path):
9+
def get_datasets(str datasets_path):
1010
cdef list items = os.listdir(datasets_path)
1111
cdef list csv_files = []
1212
cdef str item
@@ -19,7 +19,7 @@ async def get_datasets(str datasets_path):
1919

2020

2121
""" Create Sequences """
22-
async def create_sequences(df, int sequence_length):
22+
def create_sequences(df, int sequence_length):
2323
cdef list labels = []
2424
cdef list sequences = []
2525
cdef int i
@@ -34,7 +34,7 @@ async def create_sequences(df, int sequence_length):
3434

3535

3636
""" Pre-Process Data """
37-
async def preprocess_data(dataframe):
37+
def preprocess_data(dataframe):
3838
cdef str col
3939

4040
for col in dataframe.columns:
@@ -48,7 +48,7 @@ async def preprocess_data(dataframe):
4848

4949

5050
""" Scale Data """
51-
async def scale_data(dataframe, scaler_cls):
51+
def scale_data(dataframe, scaler_cls):
5252
scaler = scaler_cls()
5353
dataframe['Close'] = scaler.fit_transform(dataframe[['Close']])
5454
return scaler, dataframe

training/main.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,43 @@ from training.model_builder import (
2424
from warnings import filterwarnings
2525
filterwarnings('ignore')
2626

27-
async def main(algorithm: str, sequence_length: int, epochs: int, batch_size: int):
27+
def main(algorithm: str, sequence_length: int, epochs: int, batch_size: int):
2828
datasets_path = './datasets'
2929
models_path = './models'
3030
posttrained = './posttrained'
3131
pickle_file = './pickles'
3232

3333

34-
for dataset in await get_datasets(datasets_path):
34+
for dataset in get_datasets(datasets_path):
3535
print(f"[TRAINING] {dataset.replace('.csv', '')} ")
3636

3737
dataframe = pd.read_csv(os.path.join(datasets_path, dataset), index_col='Date')[['Close']]
3838
model_file = os.path.join(models_path, f"{dataset.replace('.csv', '')}.keras")
3939

4040
# dataframe = preprocess_data(dataframe)
4141
dataframe.dropna(inplace = True)
42-
standard_scaler, dataframe = await scale_data(dataframe, StandardScaler)
43-
minmax_scaler, dataframe = await scale_data(dataframe, MinMaxScaler)
42+
standard_scaler, dataframe = scale_data(dataframe, StandardScaler)
43+
minmax_scaler, dataframe = scale_data(dataframe, MinMaxScaler)
4444

45-
sequences, labels = await create_sequences(dataframe, sequence_length)
45+
sequences, labels = create_sequences(dataframe, sequence_length)
4646
input_shape = (sequences.shape[1], sequences.shape[2])
4747

4848
if algorithm == "GRU":
49-
model = await gru_model(input_shape)
49+
model = gru_model(input_shape)
5050

5151
elif algorithm == "LSTM":
52-
model = await lstm_model(input_shape)
52+
model = lstm_model(input_shape)
5353

5454
elif algorithm == "LSTM_GRU":
55-
model = await lstm_gru_model(input_shape)
55+
model = lstm_gru_model(input_shape)
5656

57-
else: model = await lstm_model(input_shape)
57+
else: model = lstm_model(input_shape)
5858

5959
train_size = int(len(sequences) * 0.8)
6060
X_train, X_test = sequences[:train_size], sequences[train_size:]
6161
y_train, y_test = labels[:train_size], labels[train_size:]
6262

63-
await train({
63+
train({
6464
'model': model,
6565
'model_file': model_file,
6666
'sequence_length': sequence_length,
@@ -70,7 +70,7 @@ async def main(algorithm: str, sequence_length: int, epochs: int, batch_size: in
7070

7171
dataframe_json = {'Date': dataframe.index.tolist(), 'Close': dataframe['Close'].tolist()}
7272

73-
await save_json(
73+
save_json(
7474
os.path.join(posttrained, f'{dataset.replace(".csv", "")}-posttrained.json'),
7575
dataframe_json
7676
)

training/model_builder.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ filterwarnings('ignore')
66

77

88
""" GRU (Gated Recurrent Units) Model """
9-
async def gru_model(input_shape):
9+
def gru_model(input_shape):
1010
cdef object model = Sequential([
1111
GRU(50, return_sequences = True, input_shape = input_shape),
1212
Dropout(0.2),
@@ -28,7 +28,7 @@ async def gru_model(input_shape):
2828

2929

3030
""" LSTM (Long Short-Term Memory) Model """
31-
async def lstm_model(input_shape):
31+
def lstm_model(input_shape):
3232
cdef object model = Sequential([
3333
LSTM(50, return_sequences = True, input_shape = input_shape),
3434
Dropout(0.2),
@@ -53,7 +53,7 @@ async def lstm_model(input_shape):
5353
LSTM (Long Short-Term Memory) and
5454
GRU (Gated Recurrent Units) Model
5555
"""
56-
async def lstm_gru_model(input_shape):
56+
def lstm_gru_model(input_shape):
5757
cdef object model = Sequential([
5858
LSTM(50, return_sequences = True, input_shape = input_shape),
5959
Dropout(0.2),

training/post_processor.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ filterwarnings('ignore')
66

77

88
""" Inverse Transform """
9-
async def inverse_transform(object scaler, data):
9+
def inverse_transform(object scaler, data):
1010
return scaler.inverse_transform(data)
1111

1212

1313
""" save json """
14-
async def save_json(str filename, data):
14+
def save_json(str filename, data):
1515
with open(filename, 'w') as f:
1616
json.dump(data, f)
1717

training/trainer.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ filterwarnings('ignore')
55

66

77
""" Trainer """
8-
async def train(dict configuration, X_train, y_train, X_test, y_test):
8+
def train(dict configuration, X_train, y_train, X_test, y_test):
99
cdef object early_stopping = EarlyStopping(
1010
monitor = 'val_loss',
1111
patience = 5,

trainingcli.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import asyncio
1+
# import asyncio
22
import argparse
33
from training.main import main as training
44

@@ -14,17 +14,25 @@ def main() -> None:
1414
parser.add_argument('-s', '--sequences', type = int, required = True, help = 'sequences length')
1515

1616
args = parser.parse_args()
17-
event_loop = asyncio.get_event_loop()
18-
19-
event_loop.run_until_complete(
20-
training(
21-
epochs = args.epochs,
22-
batch_size = args.batchs,
23-
algorithm = args.algorithm,
24-
sequence_length = args.sequences
25-
)
17+
18+
training(
19+
epochs = args.epochs,
20+
batch_size = args.batchs,
21+
algorithm = args.algorithm,
22+
sequence_length = args.sequences
2623
)
2724

25+
# event_loop = asyncio.get_event_loop()
26+
27+
# event_loop.run_until_complete(
28+
# training(
29+
# epochs = args.epochs,
30+
# batch_size = args.batchs,
31+
# algorithm = args.algorithm,
32+
# sequence_length = args.sequences
33+
# )
34+
# )
35+
2836

2937
if __name__ == "__main__": main()
3038

0 commit comments

Comments
 (0)