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:
X = 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.iloc[i:i+batch_size] y_batch = Y_scaled[i:i+batch_size] yield np.array(X_batch), np.array(y_batch)%%
from tensorflow.keras.layers import Dense, Dropout from tensorflow.keras import Model from tensorflow.keras.layers import Input, Dropout
def build_model(): input_shape = (6427,)
inputs = Input(shape=input_shape) # Corrected the input shape specification x = Dense(6427, activation='relu')(inputs) x = Dropout(0.25) (x) x = Dense(3200, activation='relu') (x) x = Dropout(0.20) (x) x = Dense(1800, activation='relu') (x) x = Dropout(0.15) (x) x = Dense(1024, activation='relu') (x) x = Dropout(0.10) (x) x = Dense(512, activation='relu') (x) x = Dropout(0.05) (x) x = Dense(256, activation='relu') (x) x = Dense(128, activation='relu') (x) x = Dense(64, activation='relu') (x) x = Dense(32, activation='relu') (x) # Defining three separate outputs out_high_1d = Dense(1, name='high_output_1d')(x) # No activation, linear output out_low_1d = Dense(1, name='low_output_1d')(x) # No activation, linear output out_priority_1d = Dense(1, activation='sigmoid', name='priority_output_1d')(x) out_high_2d = Dense(1, name='high_output_2d')(x) # No activation, linear output out_low_2d = Dense(1, name='low_output_2d')(x) # No activation, linear output out_priority_2d = Dense(1, activation='sigmoid', name='priority_output_2d')(x) out_high_3d = Dense(1, name='high_output_3d')(x) # No activation, linear output out_low_3d = Dense(1, name='low_output_3d')(x) # No activation, linear output out_priority_3d = Dense(1, activation='sigmoid', name='priority_output_3d')(x) out_high_5d = Dense(1, name='high_output_5d')(x) # No activation, linear output out_low_5d = Dense(1, name='low_output_5d')(x) # No activation, linear output out_priority_5d = Dense(1, activation='sigmoid', name='priority_output_5d')(x) # Constructing the model model = Model(inputs=inputs, outputs=[ out_high_1d, out_low_1d, out_priority_1d,out_high_2d, out_low_2d, out_priority_2d, out_high_3d, out_low_3d, out_priority_3d,out_high_5d, out_low_5d, out_priority_5d]) model.compile(optimizer='adam', loss={ 'high_output_1d': 'mse', 'low_output_1d': 'mse', 'priority_output_1d': 'binary_crossentropy', 'high_output_2d': 'mse', 'low_output_2d': 'mse', 'priority_output_2d': 'binary_crossentropy', 'high_output_3d': 'mse', 'low_output_3d': 'mse', 'priority_output_3d': 'binary_crossentropy', 'high_output_5d': 'mse', 'low_output_5d': 'mse', 'priority_output_5d': 'binary_crossentropy' }, metrics={ 'high_output_1d': ['mae'], 'low_output_1d': ['mae'], 'priority_output_1d': ['accuracy'], 'high_output_2d': ['mae'], 'low_output_2d': ['mae'], 'priority_output_2d': ['accuracy'], 'high_output_3d': ['mae'], 'low_output_3d': ['mae'], 'priority_output_3d': ['accuracy'], 'high_output_5d': ['mae'], 'low_output_5d': ['mae'], 'priority_output_5d': ['accuracy'] }, loss_weights={ 'high_output_1d': 1.0, 'low_output_1d': 1.0, 'priority_output_1d': 1.0, 'high_output_2d': 1.0, 'low_output_2d': 1.0, 'priority_output_2d': 1.0, 'high_output_3d': 1.0, 'low_output_3d': 1.0, 'priority_output_3d': 1.0, 'high_output_5d': 1.0, 'low_output_5d': 1.0, 'priority_output_5d': 1.0 } ) return model - Assistant
The error you're encountering:
AttributeError: 'numpy.ndarray' object has no attribute 'iloc'is due to trying to use the
.ilocmethod on a NumPy array (X_scaled), which is not a valid operation. The.ilocmethod is specific to Pandas DataFrames, not NumPy arrays.To fix this error, you can simply use slicing without
.ilocsinceX_scaledis already a NumPy array due to the call tofit_transform()which returns a NumPy array and not a Pandas DataFrame. - User
new error: { "name": "OperatorNotAllowedInGraphError", "message": "Iterating over a symbolic
tf.Tensoris not allowed. You can attempt the following resolutions to the problem: If you are running in Graph mode, use Eager execution mode or decorate this function with @tf.function. If you are using AutoGraph, you can try decorating this function with @tf.function. If that does not work, then you may be using an unsupported feature or your source code may not be visible to AutoGraph. See for more information.", "stack": "--------------------------------------------------------------------------- OperatorNotAllowedInGraphError Traceback (most recent call last) Cell In[41], line 3 1 model = build_model() ----> 3 history = model.fit(data_generator(), steps_per_epoch=100, epochs=10) - Assistant
- User
gimme full code of 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], # Continue for all needed outputs… }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.