Am building a hybrid 1D CNN and Bi-LSTM model for heart disease prediction. However the model’s accuracy is 0.73 but I want to improve it to 0.80 and above. please any help on how this model can be improved. thank you. am expecting the accuracy to improve little bit.
my input shape look like this (70000,13)
import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv1D, MaxPooling2D, MaxPooling1D, LSTM, Bidirectional, Dense, Flatten, Dropout, Input, BatchNormalization, Reshape
from tensorflow.keras.callbacks import EarlyStopping
from sklearn.preprocessing import MinMaxScaler
from sklearn.utils.class_weight import compute_class_weight
dataset = pd.read_csv('heart_disease.csv')
dataset.shape
#Preprocess the dataset
X = dataset.drop(columns=['disease'])
y = dataset['disease']
`# Standardize the features
scaler = StandardScaler()
X = scaler.fit_transform(X)
# print(X)
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
print("Training set size:", X_train.shape)
print("Test set size:", X_test.shape)
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Reshape the data for the 1D CNN + Bi-LSTM model
X_train_dl = X_train_scaled.reshape((X_train_scaled.shape[0], X_train_scaled.shape[1], 1))
X_test_dl = X_test_scaled.reshape((X_test_scaled.shape[0], X_test_scaled.shape[1], 1))
#print(X_train_dl)
#print(X_test_dl)
# Build the hybrid model
model = Sequential()
model.add(Input(shape=(X_train_dl.shape[1], X_train_dl.shape[2])))
model.add(Conv1D(filters=32, kernel_size=2, activation='relu'))
model.add(MaxPooling1D(pool_size=2))
model.add(BatchNormalization(momentum=0.99))
model.add(Conv1D(filters=64, kernel_size=2, activation='relu'))
model.add(MaxPooling1D(pool_size=2))
model.add(BatchNormalization(momentum=0.99))
model.add(Bidirectional(LSTM(50, return_sequences=True)))
model.add(Dropout(0.5))
model.add(Flatten())
`model.add(Dense(128, activation='relu', kernel_regularizer=tf.keras.regularizers.l2(0.01)))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
#Compile the model
model.compile(optimizer= tf.keras.optimizers.Adam(learning_rate = 0.0001), loss='binary_crossentropy', metrics=['accuracy'])
# Early stopping callback
early_stopping = EarlyStopping(monitor='val_loss', patience=20, restore_best_weights=True)
# Train the model
history = model.fit(X_train_dl, y_train, epochs=10, batch_size=32, validation_data=(X_test_dl, y_test), callbacks=[early_stopping])
# saving the model
model.save('my_model.keras')
# Evaluate the model
loss accuracy = model.evaluate(X_test_dl, y_test)
print(f "Hybrid Model (1D CNN + Bi-LSTM) Accuracy: {accuracy:.2f}")