i have following code to train models on my csv dataset files : intervals = [1,2,3,5]…
- User
i have following code to train models on my csv dataset files : intervals = [1,2,3,5] look_back = 60
optimizer = keras.optimizers.Adam(learning_rate=0.0003,clipvalue=0.5)
for csv_file in csv_files:
file_path = os.path.join(csv_directory, csv_file) unique_part = file_path.split('_')[-2] df = pd.read_csv(file_path) include_substrings = ["y_"] exact_columns_to_keep = ["Open", "High", "Low", "Close","volume_base", "volume_crypto", "tradecount",] filtered_columns = [col for col in df.columns if any(col.startswith(s) for s in include_substrings)] columns_to_keep = list(set(exact_columns_to_keep + filtered_columns)) df = df[columns_to_keep] df.head() features = df.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) # Scale the features and targets feature_scaler = MinMaxScaler(feature_range=(0, 1)) scaled_features = feature_scaler.fit_transform(features) joblib.dump(feature_scaler,f'x_scalers/x_{unique_part}_scaler.sav') for p in intervals: # Corrected to create a flat list of column names y_cols = [f'y_High_{p}d', f'y_Low_{p}d', f'y_Priority_{p}d'] # Now you can properly index df with y_cols targets = df[y_cols] # Continuing with your existing code… target_scaler = MinMaxScaler(feature_range=(0, 1)) scaled_targets = target_scaler.fit_transform(targets) joblib.dump(target_scaler,f'y_scalers/y{i}_{unique_part}_scaler.sav') x_train = [] y_train = [] for i in range(look_back, len(scaled_features)): x_train.append(scaled_features[i-look_back:i]) y_train.append(scaled_targets[i]) # Assuming the target is the next time step x_train, y_train = np.array(x_train), np.array(y_train) input_shape = (x_train.shape[1], x_train.shape[2]) model = Sequential() model.add(LSTM(units = 100, activation = 'tanh', return_sequences=True)) model.add(Dropout(0.4)) model.add(LSTM(units = 240, activation = 'tanh')) model.add(Dropout(0.5)) model.add(Dense(units = 3)) model.compile(optimizer=optimizer, loss = 'mean_squared_error', metrics=[tf.keras.metrics.MeanAbsoluteError()]) model.fit(x_train, y_train,epochs = 1000) mae = model.evaluate(x_train, y_train) model.save(f'models/lstm_model_{unique_part}_y{p}_mae_{mae}.h5')how can i free resources(gpu,ram,...) after each model trained and saved ?
- Assistant
- User
also how can i clean up previously csv that loaded from ram
- Assistant
- User
{ "name": "ValueError", "message": "Unable to synchronously create dataset (name already exists)", "stack": "--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[3], line 79 75 model.fit(x_train, y_train,epochs = 1000) 77 mae = model.evaluate(x_train, y_train) ---> 79 model.save(f'models/lstm_model_{unique_part}_y{p}mae{mae}.h5') 80 tf.keras.backend.clear_session() 81 del model # Delete the model object
- Assistant
- User
is there any way to boost training models with my current code/
- Assistant
- User
how to set Leaky ReLU
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.