182k views
1 vote
Use deep neural networks (you may use any free deep learning software tool) to perform a binary classification task, show final classification accuracies by using 10-fold cross-validation for different cases such as different training epochs. Please show your steps clearly.You may use MS-Word to open this file. The first 13 columns are inputs, and the final column is class (either Healthy (0) or Sick (1, 2, 3, 4)). So you need to pre-process the data to make a training file for binary heart disease classification (the final column value will be either Healthy (+1) or Sick (-1), i.e., 1, 2, 3 and 4 are converted into Sick (-1)).Use SVM to perform the same heart disease classification task and show final classification accuracies by using 10-fold cross-validation for different cases such as different parameters of SVM. Please compare SVM and deep neural networks in classification performance.

User CAPSLOCK
by
5.2k points

1 Answer

5 votes

The following SVM is used to perform the same heart disease classification task and the final classficiation accuracies.

Step-by-step explanation:

import numpy as np

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

%matplotlib inline

dataset = pd.read_csv('heart_disease. csv')

dataset.head(2)

# creating target variables

from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()

y=le.fit_transform(dataset['Car Acceptability'])

#standardizing the input feature

from sklearn.preprocessing import StandardScaler

sc= StandardScaler()

X= sc.fit_transform(all_input_columns)

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, output_category, test_size=0.3)

# K fold validation

def build_classifier():

classifier = Sequential()

#First Hidden Layer

classifier.add(Dense(8, activation='relu', kernel_initializer='random_uniform', input_dim=13))

#Second Hidden Layer

classifier.add(Dense(8, activation='relu', kernel_initializer='random_uniform'))

#Output Layer

classifier.add(Dense(4, activation='softmax', kernel_initializer='random_uniform'))

#Compiling the neural network

classifier.compile(optimizer ='adam',loss='categorical_crossentropy', metrics =['accuracy'])

return classifier

We pass build_classifier function to the build_fn argument while constructing the KerasClassifier class. Batch_size is 10 and we run 150 epochs

classifier = KerasClassifier(build_fn=build_classifier, batch_size=10, nb_epoch=150)

As we have used the KerasClassifier to warp the model, we can use scikit-learn. Once we do that then we can use neural network like any other scikit algorithms like Random forest and perform 10 fold cross-validation.

accuracies = cross_val_score(estimator=classifier, X= X, y=output_category,cv=10, n_jobs=-1)

note: do with each fold by replacing 10 with other

User Rim
by
5.5k points