code : %% from sklearn.preprocessing import StandardScaler import numpy as np from…
- User
code :
%%
from sklearn.preprocessing import StandardScaler import numpy as np from sklearn.preprocessing import StandardScaler
%%
import pandas as pd
chunk_size = 10000 # This depends on your available memory batch_size = 72
%%
def data_generator(): reader = pd.read_csv(r"C:\Users\arisa\Desktop\combined_day.csv", chunksize=chunk_size) for chunk in reader:
codeX = 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 Y = 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 xScaler = StandardScaler() yScaler = StandardScaler() X_scaled = xScaler.fit_transform(X) Y_scaled = yScaler.fit_transform(Y) # Yield batches for i in range(0, len(X_scaled), batch_size): X_batch = X_scaled[i:i+batch_size] y_batch = { 'high_output_1d': Y_scaled[i:i + batch_size, 0], 'low_output_1d': Y_scaled[i:i + batch_size, 1], 'priority_output_1d': Y_scaled[i:i + batch_size, 2], 'high_output_2d': Y_scaled[i:i + batch_size, 3], 'low_output_2d': Y_scaled[i:i + batch_size, 4], 'priority_output_2d': Y_scaled[i:i + batch_size, 5], 'high_output_3d': Y_scaled[i:i + batch_size, 6], 'low_output_3d': Y_scaled[i:i + batch_size, 7], 'priority_output_3d': Y_scaled[i:i + batch_size, 8], 'high_output_5d': Y_scaled[i:i + batch_size, 9], 'low_output_5d': Y_scaled[i:i + batch_size, 10], 'priority_output_5d': Y_scaled[i:i + batch_size, 11], } yield np.array(X_batch), np.array(y_batch) - Assistant
The error you're encountering is due to the shape and structure of the
y_batchdata you're yielding from thedata_generatorfunction. When training a Keras model with multiple outputs, you need to provide the target data () as a list or a dictionary that maps output names to their corresponding arrays. Each array in this list or dictionary should be a 2D array (or higher-dimensional, but commonly 2D for most tasks), where the first dimension is the batch size, and the second dimension is the number of targets for that output. However, in the data you're yielding, each array in the dictionary is a 1D array, not structured to properly match the expected output form of your model. - User
- Assistant