<jupyter_start><jupyter_text>CNN<jupyter_code># load data

from tqdm import tqdm
from sklearn.model_selection import train_test_split

x, y = get_dataset("YOUR DATASET")
train_x, valid_x, train_y, valid_y = train_test_split(x, y, test_size = "YOUR ", random_state="YOUR SEED")

del(x, y)

print(train_x.shape)
print(train_y.shape)

print(valid_x.shape)
print(valid_y.shape)
# train
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import "YOUR LAYER"
from tensorflow.keras.optimizers import "YOUR OPTIMIZER"
from tensorflow.keras.metrics import "YOUR METRIC"
from tensorflow.keras import backend as K

K.clear_session()

# YOUR PARAMTERS
#######################################################################################
epoch = 10
l1_rate = 1e-5
lr = 0.001
batch_size = 64
#######################################################################################

model = Sequential()

# MODEL
#######################################################################################

model.add(Conv1D(input_shape=train_X.shape[1:], filters=16, kernel_size=10, strides=1, kernel_regularizer=regularizers.l1(l1_rate)))
# model.add(BatchNormalization())
model.add(ReLU())
model.add(MaxPooling1D(pool_size=29))
model.add(Flatten())
model.add(Dense(32, kernel_regularizer=regularizers.l1(l1_rate)))
model.add(ReLU())
model.add(Dropout(rate=0.5))
model.add(Dense(1, activation = 'sigmoid', kernel_regularizer=regularizers.l1(l1_rate)))
    
#######################################################################################

model.compile(loss='YOUR LOSS', optimizer="YOUR OPTIMIZER", metrics=["YOUR METRIC"])
model.summary()

history = model.fit(train_x, train_y, 
                    validation_data=(valid_x, valid_y), 
                    batch_size="YOUR BATCH SIZE", epochs="YOUR EPOCHS", shuffle=True, verbose=1)
# graph
import matplotlib.pyplot as plt

loss = history.history['loss']
val_loss = history.history['val_loss']

epochs = range(1,len(loss) + 1)

plt.plot(epochs, loss, 'r', label='Training Loss')
plt.plot(epochs, val_loss, 'b', label='Validation Loss')
plt.title('Training Loss vs Validation Loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup