my code:
# %%
from sklearn.preprocessing import StandardScaler
import pandas as pd
import numpy as np
from tensorflow import keras

def calculate_features_scaling_params(file_path, features_to_drop):
    scaler = StandardScaler()
    for chunk in pd.read_csv(file_path, chunksize=10000):  # Adjust chunksize based on your memory capacity
        filtered_chunk = chunk.drop(features_to_drop, axis=1)
        scaler.partial_fit(filtered_chunk)  # Accumulate means and variances
    
    return scaler.mean_, scaler.var_

def calculate_targets_scaling_params(file_path):
    scaler = StandardScaler()
    for chunk in pd.read_csv(file_path, chunksize=10000):  # Adjust chunksize based on your memory capacity
        filtered_chunk = 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'
                   ]]
        scaler.partial_fit(filtered_chunk)  # Accumulate means and variances
    
    return scaler.mean_, scaler.var_

# %%
import tensorflow as tf
if tf.test.gpu_device_name(): 
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
    print('Please install GPU version of TF')

# %%
file_path = r"C:\Users\arisa\Desktop\combined_day.csv"
batch_size = 128

# %%
features_to_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']
f_mean_, f_var_ = calculate_features_scaling_params(file_path, features_to_drop)
t_mean_, t_var_ = calculate_targets_scaling_params(file_path)

# %%
# Suppose mean_ and var_ have been obtained as above
x_scaler = StandardScaler()
x_scaler.mean_ = f_mean_
x_scaler.var_ = f_var_
x_scaler.scale_ = np.sqrt(f_var_) 


y_scaler = StandardScaler()
y_scaler.mean_ = t_mean_
y_scaler.var_ = t_var_
y_scaler.scale_ = np.sqrt(t_var_) 

# %%


# %%
row_counter = 0

# %%

def data_generator(file_path, batch_size, data_type, x_scaler, y_scaler):
    chunksize = batch_size
    total_rows = 301617  # Adjust with your dataset's actual number of rows
    split_ratio = 0.92  # Assuming 80% for train, 20% for validation
    train_rows = int(total_rows * split_ratio)
    while True:  # Loop forever, so the generator never terminates
        for chunk in pd.read_csv(file_path, chunksize=chunksize):

            if data_type == 'train' and row_counter >= train_rows:
                continue  # Skip the rest if we are fetching training data but have reached the end of the train set
            elif data_type == 'val' and row_counter < train_rows:
                row_counter += len(chunk)
                continue  # Skip this chunk if we are fetching validation data but are still in the train range
            # Assuming your CSV has headers that match features/targets
            # Normalizing the features
            filtered_c = chunk.drop(['Date', 'Symbol'], axis=1)
            
            feature_data = filtered_c.drop([
                '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)
            target_data = filtered_c[['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'
                   ]]
            
            feature_data_scaled = pd.DataFrame(x_scaler.transform(feature_data), columns=feature_data.columns)
            # Assuming target_data also needs to be scaled, apply scaler separately
            target_data_scaled = pd.DataFrame(y_scaler.transform(target_data), columns=target_data.columns)

            # Now, feature_data_scaled and target_data_scaled are both DataFrames, scaled and ready to use
            yield feature_data_scaled.values, target_data_scaled.values
            row_counter += len(chunk)


# %%

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Input
import tensorflow as tf

def build_model():
    input_shape = (6427,)
    
    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'),
    Dense(12),
    ])
    
    model.compile(optimizer='adam',
                  loss='mse',  # Use Mean Squared Error for regression
                  metrics=['mae'])  # Mean Absolute Error as an additional metric
    return model


# %%


# Instantiate the model
model = build_model()

model.summary()

# %%
train_generator = data_generator(file_path, batch_size, 'train',x_scaler=x_scaler,y_scaler=y_scaler)
val_generator = data_generator(file_path, batch_size, 'val',x_scaler=x_scaler,y_scaler=y_scaler)

total_samples = 301617  # Assuming same example size
train_samples = int(total_samples * 0.92)
val_samples = total_samples - train_samples

steps_per_epoch = train_samples // batch_size
validation_steps = val_samples // batch_size

# Modify the model fitting call to include validation data
model.fit(
    train_generator, 
    steps_per_epoch=steps_per_epoch, 
    epochs=1000,
    validation_data=val_generator, 
    validation_steps=validation_steps
)



error:
{
	"name": "UnboundLocalError",
	"message": "local variable 'row_counter' referenced before assignment",
	"stack": "---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[21], line 12
      9 validation_steps = val_samples // batch_size
     11 # Modify the model fitting call to include validation data
---> 12 model.fit(
     13     train_generator, 
     14     steps_per_epoch=steps_per_epoch, 
     15     epochs=1000,
     16     validation_data=val_generator, 
     17     validation_steps=validation_steps
     18 )

File c:\\Users\\arisa\\.conda\\envs\\tf\\lib\\site-packages\\keras\\utils\\traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     67     filtered_tb = _process_traceback_frames(e.__traceback__)
     68     # To get the full stack trace, call:
     69     # `tf.debugging.disable_traceback_filtering()`
---> 70     raise e.with_traceback(filtered_tb) from None
     71 finally:
     72     del filtered_tb

Cell In[20], line 9, in data_generator(file_path, batch_size, data_type, x_scaler, y_scaler)
      6 while True:  # Loop forever, so the generator never terminates
      7     for chunk in pd.read_csv(file_path, chunksize=chunksize):
----> 9         if data_type == 'train' and row_counter >= train_rows:
     10             continue  # Skip the rest if we are fetching training data but have reached the end of the train set
     11         elif data_type == 'val' and row_counter < train_rows:

UnboundLocalError: local variable 'row_counter' referenced before assignment"
}