Work on fine-tuning and Important Feature selections
This commit is contained in:
@@ -8,6 +8,7 @@ import os
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
||||
from sklearn.model_selection import train_test_split
|
||||
from keras import Sequential, layers, optimizers, losses
|
||||
from keras.callbacks import ReduceLROnPlateau
|
||||
|
||||
def TrainAI(include_pull):
|
||||
|
||||
@@ -35,36 +36,43 @@ def TrainAI(include_pull):
|
||||
# Split out the test and train
|
||||
train_features, test_features, train_labels, test_labels = train_test_split(X, Y, test_size=0.2)
|
||||
|
||||
# Create a normalizer to nomralize the data
|
||||
normalizer = layers.Normalization(axis=-1)
|
||||
normalizer.adapt(np.array(train_features))
|
||||
|
||||
# Create the DNN
|
||||
dnn_model = Sequential([
|
||||
layers.Input(shape=(train_features.shape[1],)), # Load the feature count dynamically
|
||||
normalizer,
|
||||
layers.Dense(64, activation='elu'),
|
||||
layers.Dense(64, activation='elu'),
|
||||
layers.Dense(1)
|
||||
layers.Dense(256, activation='elu'),
|
||||
layers.Dropout(0.1), # Small dropout to prevent it from memorizing noise
|
||||
layers.Dense(128, activation='elu'),
|
||||
layers.Dropout(0.1), # Small dropout to prevent it from memorizing noise
|
||||
layers.Dense(24, activation='elu'),
|
||||
layers.Dense(1, activation='linear')
|
||||
])
|
||||
|
||||
# Allow negative numbers
|
||||
dnn_model.add(layers.LeakyReLU(alpha=0.01))
|
||||
|
||||
# Configure the model
|
||||
dnn_model.compile(
|
||||
optimizer=optimizers.Adam(learning_rate=0.00001, clipvalue=1.0),
|
||||
loss=losses.Huber()
|
||||
optimizer=optimizers.Adam(learning_rate=0.0001, clipvalue=1.0),
|
||||
loss="mse",
|
||||
metrics=['mae'] # See it train while it runs
|
||||
)
|
||||
|
||||
# Show the summary before training the model
|
||||
dnn_model.summary()
|
||||
|
||||
# Learning rate reducer
|
||||
reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=5, min_lr=0.0000001)
|
||||
|
||||
# Train the model
|
||||
Training_Data = dnn_model.fit(
|
||||
train_features,
|
||||
train_labels,
|
||||
batch_size=64,
|
||||
epochs=39, # Tuned to the point before overfitting
|
||||
epochs=50, # Tuned to the point before overfitting
|
||||
verbose=1, # Show progress
|
||||
validation_split = 0.2 # Calculate validation results on 20% of the training data.
|
||||
validation_split = 0.2, # Calculate validation results on 20% of the training data.
|
||||
shuffle=True,
|
||||
callbacks=[reduce_lr] # Reduce the learning_rate every run
|
||||
)
|
||||
|
||||
# Predict
|
||||
@@ -79,7 +87,7 @@ def TrainAI(include_pull):
|
||||
_ = plt.plot(lims, lims)
|
||||
|
||||
|
||||
# Current Test Results: 1.221876300405711e-05
|
||||
# Current Test Results: 0.3382711112499237
|
||||
test_results = dnn_model.evaluate(
|
||||
test_features, test_labels, verbose=0
|
||||
)
|
||||
@@ -89,4 +97,6 @@ def TrainAI(include_pull):
|
||||
dnn_model.save(os.path.join(DATA_DIR, "model.keras"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
TrainAI(False)
|
||||
TrainAI(True)
|
||||
|
||||
# Last train Predicted Target_Close: [0.0022113274317234755, 0.0021446370519697666, 0.0022628342267125845, 0.002175702480599284, 0.0021452796645462513, 0.0020838389173150063, 0.0017336219316348433, 0.002210840117186308, 0.0021144403144717216, 0.0021278387866914272, 0.0021266420371830463, 0.002261851681396365, 0.002108299173414707, 0.002121902070939541, 0.0022294146474450827]
|
||||
Reference in New Issue
Block a user