09.10.2023 Views

Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5

Deep Learning and Neural Networks

def run_network(model=None, data=None, error=False):

global_start_time = time.time()

epochs = 2

ratio = 0.5

sequence_length = 100

X_train, y_train, X_test, y_test = process_data(

data, sequence_length, ratio,error)

print ('\nData Loaded. Compiling...\n')

if model is None:

model = build_model()

try:

model.fit(

X_train, y_train,

batch_size=512, nb_epoch=epochs, validation_

split=0.05)

predicted = model.predict(X_test)

predicted = np.reshape(predicted, (predicted.size,))

except KeyboardInterrupt:

print ('Training duration (s) : ', time.time() -

global_start_time)

return model, y_test, 0

try:

fig = plt.figure()

ax = fig.add_subplot(111)

ax.plot(y_test[:100]*result_max)

plt.plot(predicted[:100]*result_max)

plt.show()

117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!