-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTraining.py
38 lines (33 loc) · 1.04 KB
/
Training.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
from tensorflow import keras
import xgboost as xgb
def run_experiment(model, x_train, y_train, learning_rate, loss, num_epochs, batch_size, optimizer):
# Compile the model.
model.compile(
optimizer=optimizer(learning_rate),
loss=loss(from_logits=True),
metrics=['accuracy'],
)
# Create an early stopping callback.
early_stopping = keras.callbacks.EarlyStopping(
monitor="val_loss", patience=5, restore_best_weights=True
)
reduce_lr = keras.callbacks.ReduceLROnPlateau(
patience=2
)
# Fit the model.
history = model.fit(
x=x_train,
y=y_train,
epochs=num_epochs,
batch_size=batch_size,
validation_split=0.15,
callbacks=[early_stopping, reduce_lr],
)
return history
def run_experiment_XGB(model, x_train, y_train):
dtrain = xgb.DMatrix(data=x_train, label=y_train)
obj = xgb.train(model.__getparams__(),
dtrain=dtrain,
num_boost_round=500,
)
return obj