0
$\begingroup$

I am working on a project to predict the severity of the disease, Hemophilia using a deep learning model(FCNN or 1DCNN). I am working based on the information provided in this article: https://www.sciencedirect.com/science/article/pii/S0888754320308193?via%3Dihub#s0070

I have used the raw data files for Haemophilia ‘A’ Factor VIII gene mutations provided under the "Appendix A. Supplementary data" section. The dataset has 7784 rows and 17 columns. After preprocessing, the final dataset has 5257 rows and 58 columns. Here is the link to the preprocessed data: https://drive.google.com/file/d/1S3t5Ka_mhetB60sndZ9i7OsXaj0jxUVN/view?usp=sharing

I used 1DCNN to train the data, the result was not promising either. I also uploaded some of the learning curves to demonstrate the loss and accuracy of the models. Training accuracy vs Validation accuracy, #epochs=1000Train loss vs Validation Loss, #epochs=1000Training accuracy vs Validation accuracy, #epochs=200Train loss vs Validation Loss, #epochs=200

How can I fix this issue? Which part am I doing wrong?

The full version of my code is available below:

# Read the CSV file into a DataFrame
data = 'filtered_rows.csv'
df = pd.read_csv(data)
print("The dataset has {} rows and {} columns".format(df.shape[0], df.shape[1]))


# Separate features and labels
X = filtered_rows.drop(columns=['Severity']).values
y = filtered_rows['Severity'].values

print("The dataset has {} rows and {} columns".format(filtered_rows.shape[0], filtered_rows.shape[1]))


##################Class_Weight && Applying_OverSampling##################

# Calculate class weights manually
class_weights = {}
for cls in np.unique(y):
    class_weights[cls] = len(y) / (len(np.where(y == cls)[0]) * len(np.unique(y)))

# Apply oversampling to the 'Moderate' class
smote = SMOTE(sampling_strategy='auto', random_state=42)
X_oversampled, y_oversampled = smote.fit_resample(X, y)


from collections import Counter

# Assuming you have variables y and y_oversampled containing the original and oversampled labels
class_counts_original = Counter(y)
class_counts_oversampled = Counter(y_oversampled)

# Count samples in each class in the original dataset
total_samples_original = len(y)
samples_mild_original = class_counts_original[0]
samples_moderate_original = class_counts_original[1]
samples_severe_original = class_counts_original[2]

# Count samples in each class in the oversampled dataset
total_samples_oversampled = len(y_oversampled)
samples_mild_oversampled = class_counts_oversampled[0]
samples_moderate_oversampled = class_counts_oversampled[1]
samples_severe_oversampled = class_counts_oversampled[2]

print("Original Dataset:")
print(f"Total samples: {total_samples_original}")
print(f"Mild samples: {samples_mild_original}")
print(f"Moderate samples: {samples_moderate_original}")
print(f"Severe samples: {samples_severe_original}")

print("\nOversampled Dataset:")
print(f"Total samples: {total_samples_oversampled}")
print(f"Mild samples: {samples_mild_oversampled}")
print(f"Moderate samples: {samples_moderate_oversampled}")
print(f"Severe samples: {samples_severe_oversampled}")

########################################################################

# Create a StandardScaler instance
scaler = StandardScaler()

# Fit the scaler to your data and transform it
X_normalized = scaler.fit_transform(X_oversampled)

# Display the updated DataFrame
df_normalized = pd.DataFrame(data=X_normalized, columns=filtered_rows.columns[:-1])  # Exclude the 'Severity' column
display(df_normalized.head())

# Create a MinMaxScaler instance
scaler = MinMaxScaler()

# Fit the scaler to your data and transform it
X_scaled = scaler.fit_transform(X_normalized)

# Display the updated DataFrame
df_scaled = pd.DataFrame(data=X_scaled, columns=filtered_rows.columns[:-1])  # Exclude the 'Severity' column
display(df_scaled.head())

###########################FCNN_Model###########################
# Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y_oversampled, test_size=0.2, random_state=42, shuffle=True)


# Create a fully connected neural network model
model = Sequential()
model.add(Dense(128, input_dim=X_train.shape[1], activation='relu'))
#model.add(BatchNormalization())
#model.add(Dropout(0.3))
model.add(Dense(64, activation='relu'))
#model.add(Dense(64, activation='relu', kernel_regularizer=l1(0.001)))
model.add(Dense(3, activation='softmax'))

# Compile the model with a custom learning rate
model.compile(optimizer=Adam(learning_rate=0.001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])

# Train the model
history = model.fit(X_train, y_train, epochs=200, batch_size=32, validation_split=0.2, class_weight=class_weights)

# Evaluate the model on the test set
loss, accuracy = model.evaluate(X_test, y_test)
print(f"Test Loss: {loss:.4f}")
print(f"Test Accuracy: {accuracy * 100:.2f}%")

###################################

# Model Prediciton
y_pred = model.predict(X_test)
y_pred = np.argmax(y_pred, axis=1)  # Convert softmax output to class labels

# Create the confusion matrix
confusion = confusion_matrix(y_test, y_pred)


# Create a heatmap for the confusion matrix
sns.heatmap(confusion, annot=True, fmt="d", cmap="Blues")

# Add labels and titles
plt.xlabel('Predicted')
plt.ylabel('True')
plt.title('Confusion Matrix')

# Display the plot
plt.show()

###############Classification_Report##################

class_names = ["Mild", "Moderate", "Severe"]

# Calculate precision, recall, F1-score, and support
report = classification_report(y_test, y_pred, target_names=class_names, output_dict=True)

# Convert the report to a DataFrame for easy visualization
df_report = pd.DataFrame(report).transpose()

# List of columns you want to format
columns_to_format = ['precision', 'recall', 'f1-score', 'support']

# Apply formatting to each specified column
for column in columns_to_format:
    df_report[column] = df_report[column].map('{:.2f}'.format)

# Then, display the formatted DataFrame
print(df_report)

###########################1DCNN_Model###########################
# Define the 1D CNN model
#model = keras.Sequential()
#model.add(layers.Input(shape=(X_train.shape[1],)))  # Input layer
#model.add(layers.Reshape((X_train.shape[1], 1)))  # Reshape the input for 1D convolution

# Convolutional layers
#model.add(layers.Conv1D(64, kernel_size=3, activation='relu'))
#model.add(layers.MaxPooling1D(pool_size=2))
#model.add(layers.Conv1D(128, kernel_size=3, activation='relu'))
#model.add(layers.MaxPooling1D(pool_size=2))

#model.add(layers.Flatten())  # Flatten layer

# Fully connected layers
#model.add(layers.Dense(128, activation='relu'))
#model.add(layers.Dropout(0.3))  # Dropout layer to prevent overfitting
#model.add(layers.Dense(64, activation='relu'))
#model.add(layers.Dropout(0.3))
#model.add(layers.Dense(3, activation='softmax'))  # Output layer with 3 classes

# Compile the model
#model.compile(optimizer=Adam(learning_rate=0.001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])

# Train the model
#history_1DCNN = model.fit(X_train, y_train, epochs=100, batch_size=32, validation_split=0.2)

# Evaluate the model on the test set
#loss, accuracy = model.evaluate(X_test, y_test)
#print(f"Test Loss: {loss:.4f}")
#print(f"Test Accuracy: {accuracy * 100:.2f}%")
##############################################################
$\endgroup$

0

You must log in to answer this question.