intervals = [1,2,3,5] lookback = 60 optimizer =…
- User
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:
codefile_path = os.path.join(csv_directory, csv_file) unique_part = file_path.split('_')[-2] df = pd.read_csv(r'C:\Users\arisa\Desktop\ddd\Binance_1INCHBUSD_d.csv') 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_scaler_{unique_part}.sav') for i in intervals: y_cols = [[f'y_High_{i}d', 'y_Low_{i}d', 'y_Priority_{i}d']] targets = df[y_cols] target_scaler = MinMaxScaler(feature_range=(0, 1)) scaled_targets = target_scaler.fit_transform(targets) joblib.dump(feature_scaler,f'y_scalers/y{i}_scaler_{unique_part}.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{i}_mae_{mae}.h5') - Assistant
The issue in your code lies within the line where you're attempting to access the columns of the DataFrame
dfusing the variabley_cols. Here's the problematic line:pythontargets = df[y_cols]The error message indicates that the way you've structured
y_colsis not correct for selecting columns in a pandas DataFrame.y_colsis structured as a list of lists rather than a list of strings (which are the column names). Here’s how you can address the error:- Adjust how you create
y_colsto be a flat list of column names. - Correct the indexing to access the DataFrame with this list.
Here's the corrected portion of your code:
python - Adjust how you create