this is my code to train a model: %% import pandas as pd import datetime as dt from…
- User
this is my code to train a model:
%%
import pandas as pd import datetime as dt from datetime import date import numpy as np import tensorflow as tf from sklearn.preprocessing import MinMaxScaler import tensorflow as tf import keras
%%
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]
%%
Assuming ‘data’ already contains the selected features and targets
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) targets = df[['y_High_5d', 'y_Low_5d', 'y_Priority_5d']]
Scale the features and targets
feature_scaler = MinMaxScaler(feature_range=(0, 1)) target_scaler = MinMaxScaler(feature_range=(0, 1))
scaled_features = feature_scaler.fit_transform(features) scaled_targets = target_scaler.fit_transform(targets)
%%
look_back = 60 # Number of previous time steps to consider for each output
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]) # (time steps, number of features)
%% [markdown]
# ML Model (LSTM)
---
%%
from tensorflow.keras.layers import Dense, Dropout, LSTM from tensorflow.keras.models import Sequential from tensorflow.keras.layers import BatchNormalization
%%
model = Sequential() model.add(LSTM(units = 100, activation = 'tanh', return_sequences=True ,input_shape = input_shape)) model.add(Dropout(0.4)) model.add(LSTM(units = 240, activation = 'tanh')) model.add(Dropout(0.5)) model.add(Dense(units = 3))
%%
optimizer = keras.optimizers.Adam(learning_rate=0.0003,clipvalue=0.5) model.compile(optimizer=optimizer, loss = 'mean_squared_error', metrics=[tf.keras.metrics.MeanAbsoluteError()]) model.fit(x_train, y_train,epochs = 250)
- Assistant
- User
implement spliting data to train and test and evaluating model after trained
- Assistant
- User
also how can i see model performance on specefic y's mae for each y,because there is 3 of them
- Assistant
- User
in the code you provided the x_test is the data that model not seen before and the x_train_full is the 80 percent of data ,right?
- Assistant