i have following code to train a NN model on my data : %% from sklearn.preprocessing…
- User
i have following code to train a NN model on my data :
%%
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_)
%%
def data_generator(file_path, batch_size, data_type, x_scaler, y_scaler): global row_counter 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)
- Assistant
- User
but my dataset csv file is a large file and i cant load it fully at once
- Assistant
- User
update my code for Preprocess and Convert Your Data to XGBoost’s External Memory Format:
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.