i add some more features and targets to my dataset and implemented the code:
%%
import pandas as pd
import numpy as np
from tensorflow import keras
def data_generator(file_path, batch_size):
chunksize = batch_size
while True: # Loop forever, so the generator never terminates
for chunk in pd.read_csv(file_path, chunksize=chunksize):
# Assuming your CSV has headers that match features/targets
feature_data = chunk.drop([
'Date', 'Symbol',
'y_High_1d', 'y_Low_1d', 'y_Priority_1d',
'y_High_2d', 'y_Low_2d', 'y_Priority_2d',
'y_High_3d', 'y_Low_3d', 'y_Priority_3d',
'y_High_5d', 'y_Low_5d', 'y_Priority_5d'], axis=1).values
target_data = chunk[['y_High_1d'
, 'y_Low_1d', 'y_Priority_1d',
'y_High_2d', 'y_Low_2d', 'y_Priority_2d',
'y_High_3d', 'y_Low_3d', 'y_Priority_3d',
'y_High_5d', 'y_Low_5d', 'y_Priority_5d'
]].values
yield feature_data, target_data
%%
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense,Dropout
def build_model(input_shape):
model = Sequential([
Dense(6427, activation='relu',input_shape=input_shape),
Dropout(0.25),
Dense(3200, activation='relu'),
Dropout(0.20),
Dense(1800, activation='relu'),
Dropout(0.15),
Dense(1024, activation='relu'),
Dropout(0.10),
Dense(512, activation='relu'),
Dropout(0.05),
Dense(256, activation='relu'),
Dense(128, activation='relu'),
Dense(64, activation='relu'),
Dense(32, activation='relu')
])
model.compile(optimizer='adam',
loss='mse', # Use Mean Squared Error for regression
metrics=['mae']) # Mean Absolute Error as an additional metric
return model
%%
file_path = r"C:\Users\arisa\Desktop\combined_day.csv"
batch_size = 128
Placeholder for input shape, adjust based on your actual data
input_shape = (6247,)
Instantiate the model
model = build_model(input_shape)
%%
Setup the data generator
train_generator = data_generator(file_path,batch_size)
Assuming you know or calculate the total number of rows in advance
total_samples = 1000000 # Example number, replace with your dataset's size
steps_per_epoch = total_samples // batch_size
Train the model
model.fit(train_generator, steps_per_epoch=1000, epochs=10)
im getting following error:
{
"name": "ValueError",
"message": "Exception encountered when calling Sequential.call().
Input 0 of layer "dense_9" is incompatible with the layer: expected axis -1 of input shape to have value 6247, but received input with shape (None, 6427)
Arguments received by Sequential.call():
• inputs=tf.Tensor(shape=(None, 6427), dtype=float32)
• training=True
• mask=None",
"stack": "---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[9], line 9
6 steps_per_epoch = total_samples // batch_size
8 # Train the model
----> 9 model.fit(train_generator, steps_per_epoch=1000, epochs=10)
File c:\Users\arisa\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\src\utils\traceback_utils.py:122, in filter_traceback..error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.traceback)
120 # To get the full stack trace, call:
121 # keras.config.disable_traceback_filtering()
--> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb
File c:\Users\arisa\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\src\layers\input_spec.py:227, in assert_input_compatibility(input_spec, inputs, layer_name)
222 for axis, value in spec.axes.items():
223 if value is not None and shape[axis] not in {
224 value,
225 None,
226 }:
--> 227 raise ValueError(
228 f'Input {input_index} of layer "{layer_name}" is '
229 f"incompatible with the layer: expected axis {axis} "
230 f"of input shape to have value {value}, "
231 "but received input with "
232 f"shape {shape}"
233 )
234 # Check shape.
235 if spec.shape is not None:
ValueError: Exception encountered when calling Sequential.call().
Input 0 of layer "dense_9" is incompatible with the layer: expected axis -1 of input shape to have value 6247, but received input with shape (None, 6427)
Arguments received by Sequential.call():
• inputs=tf.Tensor(shape=(None, 6427), dtype=float32)
• training=True
• mask=None"
}