Work on optimizing the model
This commit is contained in:
@@ -5,7 +5,7 @@ import datapuller
|
||||
import os
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
||||
from sklearn.model_selection import train_test_split
|
||||
from keras import Sequential, layers, optimizers
|
||||
from keras import Sequential, layers, optimizers, losses
|
||||
|
||||
def TrainAI():
|
||||
# Pull New Data
|
||||
@@ -17,8 +17,9 @@ def TrainAI():
|
||||
|
||||
# Load the dataset
|
||||
dataset = pd.read_parquet(os.path.join(DATA_DIR, "stocks.parquet"))
|
||||
X = dataset.drop('Target_Close_Tomorrow', axis=1)
|
||||
Y = dataset['Target_Close_Tomorrow']
|
||||
X = dataset.drop('Target_Close', axis=1)
|
||||
X = dataset.drop('Target_Direction', axis=1)
|
||||
Y = dataset['Target_Close']
|
||||
|
||||
# Show the datatypes
|
||||
print(dataset.dtypes)
|
||||
@@ -34,15 +35,15 @@ def TrainAI():
|
||||
dnn_linear_model = Sequential([
|
||||
layers.Input(shape=(train_features.shape[1],)), # Load the feature count dynamically
|
||||
normalizer,
|
||||
layers.Dense(64, activation='relu'),
|
||||
layers.Dense(64, activation='relu'),
|
||||
layers.Dense(64, activation='elu'),
|
||||
layers.Dense(64, activation='elu'),
|
||||
layers.Dense(1)
|
||||
])
|
||||
|
||||
# Configure the model
|
||||
dnn_linear_model.compile(
|
||||
optimizer=optimizers.Adam(learning_rate=0.001),
|
||||
loss='mean_absolute_error'
|
||||
optimizer=optimizers.Adam(learning_rate=0.0001, clipvalue=1.0),
|
||||
loss=losses.Huber()
|
||||
)
|
||||
|
||||
# Show the summary before training the model
|
||||
@@ -52,7 +53,7 @@ def TrainAI():
|
||||
Training_Data = dnn_linear_model.fit(
|
||||
train_features,
|
||||
train_labels,
|
||||
batch_size=1024,
|
||||
batch_size=64,
|
||||
epochs=100,
|
||||
# Show progress
|
||||
verbose=1,
|
||||
@@ -76,5 +77,7 @@ def TrainAI():
|
||||
test_features, test_labels, verbose=0
|
||||
)
|
||||
|
||||
print(f"Test Results: {test_results}")
|
||||
|
||||
# Save the model
|
||||
dnn_linear_model.save(os.path.join(DATA_DIR, "model.keras"))
|
||||
Reference in New Issue
Block a user