<jupyter_start><jupyter_text>2D features<jupyter_code>x_shape, train_ds, validation_data, test_ds = h3(DATA_DIR + 'H3.fasta')
models
key = '<KEY>'

keras.backend.clear_session()
model = models[key](x_shape)
model.compile(optimizer='adam', loss='binary_crossentropy', metrics='accuracy')
model.summary()
csv_path = LOG_DIR + f'{key}-histone-dynamics.csv'
model_path = LOG_DIR + f'{key}-histone.h5'

callbacks = [
    keras.callbacks.CSVLogger(csv_path),
    keras.callbacks.LambdaCallback(
        on_epoch_end=lambda epoch, logs: gc.collect(),
        # on_train_end=lambda logs: model.save(model_path)
    ),
    keras.callbacks.ModelCheckpoint(model_path, save_best_only=True)
]

history = model.fit(train_ds, epochs=50, validation_data=validation_data,
                    callbacks=callbacks, verbose=3)
model = keras.models.load_model(model_path)
test_loss, test_accuracy = model.evaluate(test_ds, verbose=3)

y_score = model.predict(test_ds)
y_true = [int(y) for x, y in test_ds.unbatch()]
evaluate(model, history, test_accuracy, y_score, y_true, LOG_DIR, key, 'histone')
from sklearn.metrics import roc_curve, precision_recall_curve
import numpy as np

dataset = 'histone'
key = '<KEY>'
model_path = LOG_DIR + f'{key}-histone.h5'

model = keras.models.load_model(model_path)
test_loss, test_accuracy = model.evaluate(test_ds, verbose=3)
x_shape, train_ds, validation_data, test_ds = h3(DATA_DIR + 'H3.fasta')
y_score = model.predict(test_ds)
y_true = [int(y) for x, y in test_ds.unbatch()]

precision, recall, thresholds = precision_recall_curve(y_true, y_score)
pr = pd.DataFrame({
    'precision': precision,
    'recall': recall,
    'thresholds': np.append(thresholds, np.nan)
})
pr.to_csv(LOG_DIR + f'{key}-{dataset}-pr.csv', index=False)<jupyter_output><empty_output><jupyter_text>1D features<jupyter_code>x_shape, train_ds, validation_data, test_ds = h3(DATA_DIR + 'H3.fasta', 3, 2, False)
models
key = 'deepram_recurrent_onehot'

keras.backend.clear_session()
model = models[key](x_shape)
model.compile(optimizer='adam', loss='binary_crossentropy', metrics='accuracy')
model.summary()
csv_path = LOG_DIR + f'{key}-histone-dynamics.csv'
model_path = LOG_DIR + f'{key}-histone.h5'

callbacks = [
    keras.callbacks.CSVLogger(csv_path),
    keras.callbacks.LambdaCallback(
        on_epoch_end=lambda epoch, logs: gc.collect(),
        # on_train_end=lambda logs: model.save(model_path)
    ),
    keras.callbacks.ModelCheckpoint(model_path, save_best_only=True)
]

history = model.fit(train_ds, epochs=50, validation_data=validation_data,
                    callbacks=callbacks, verbose=3)
model = keras.models.load_model(model_path)
test_loss, test_accuracy = model.evaluate(test_ds, verbose=3)

y_score = model.predict(test_ds)
y_true = [int(y) for x, y in test_ds.unbatch()]
evaluate(model, history, test_accuracy, y_score, y_true, LOG_DIR, key, 'histone')<jupyter_output><empty_output><jupyter_text>Raw features<jupyter_code>x_shape, train_ds, validation_data, test_ds = h3_raw(DATA_DIR + 'H3.fasta')
models
key = 'deepram_recurrent_embed'

keras.backend.clear_session()
model = models[key](x_shape)
model.compile(optimizer='adam', loss='binary_crossentropy', metrics='accuracy')
model.summary()
csv_path = LOG_DIR + f'{key}-histone-dynamics.csv'
model_path = LOG_DIR + f'{key}-histone.h5'

callbacks = [
    keras.callbacks.CSVLogger(csv_path),
    keras.callbacks.LambdaCallback(
        on_epoch_end=lambda epoch, logs: gc.collect(),
        # on_train_end=lambda logs: model.save(model_path)
    ),
    keras.callbacks.ModelCheckpoint(model_path, save_best_only=True)
]

history = model.fit(train_ds, epochs=50, validation_data=validation_data,
                    callbacks=callbacks, verbose=3)
model = keras.models.load_model(model_path)
test_loss, test_accuracy = model.evaluate(test_ds, verbose=3)

y_score = model.predict(test_ds)
y_true = [int(y) for x, y in test_ds.unbatch()]
evaluate(model, history, test_accuracy, y_score, y_true, LOG_DIR, key, 'histone')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup