0% found this document useful (0 votes)
12 views3 pages

regression- Naive- SVM.docx

The document outlines a methodology to evaluate and compare the performance of Linear Regression, Logistic Regression, Naïve Bayes, and Support Vector Machine (SVM) models for heart disease diagnosis. It details the steps from loading the dataset to training the models, making predictions, and evaluating their performance using accuracy and classification reports. The results indicate that the SVM model achieved the highest accuracy, followed by Logistic Regression and Naïve Bayes.

Uploaded by

haseenafrn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

regression- Naive- SVM.docx

The document outlines a methodology to evaluate and compare the performance of Linear Regression, Logistic Regression, Naïve Bayes, and Support Vector Machine (SVM) models for heart disease diagnosis. It details the steps from loading the dataset to training the models, making predictions, and evaluating their performance using accuracy and classification reports. The results indicate that the SVM model achieved the highest accuracy, followed by Logistic Regression and Naïve Bayes.

Uploaded by

haseenafrn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

8.

Evaluate the performance of Linear regression; logistic regression, naïve


Bayes and SVM based prediction models for heart disease diagnosis.

Aim
To evaluate and compare the performance of Linear Regression, Logistic
Regression, Naïve Bayes, and Support Vector Machine (SVM) models for heart
disease diagnosis
Algorithm
Step 1: Load the Dataset

●​ Import the heart disease dataset using Pandas.


●​ Identify features (X) and target variable (y).

Step 2: Data Preprocessing

●​ Split the dataset into training (80%) and testing (20%) sets using
train_test_split().

Step 3: Initialize Prediction Models

●​ Logistic Regression
●​ Naïve Bayes (GaussianNB)
●​ Support Vector Machine (SVM)

Step 4: Train the Models

●​ Fit each model using the training data (X_train, y_train).

Step 5: Make Predictions

●​ Predict heart disease diagnosis on the test set (X_test).

Step 6: Evaluate Model Performance

●​ Calculate Accuracy for each model using accuracy_score().


●​ Generate a Classification Report (Precision, Recall, F1-score).

Step 7: Compare Results


●​ Compare performance metrics to determine the best model.
Program
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, classification_report
# Load the heart disease dataset
data = pd.read_csv('heart.csv')

# Features and target variable


X = data.drop('target', axis=1) # Assuming 'target' is the column for
heart disease diagnosis
y = data['target']

# Split the dataset into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2, random_state=42)

# Initialize models
logistic_model = LogisticRegression(max_iter=1000)
naive_bayes_model = GaussianNB()
svm_model = SVC()

# Train the models


logistic_model.fit(X_train, y_train)
naive_bayes_model.fit(X_train, y_train)
svm_model.fit(X_train, y_train)

# Make predictions
logistic_predictions = logistic_model.predict(X_test)
naive_bayes_predictions = naive_bayes_model.predict(X_test)
svm_predictions = svm_model.predict(X_test)

# Evaluate the models


print("Logistic Regression:")
print(f"Accuracy: {accuracy_score(y_test, logistic_predictions):.4f}")
print(classification_report(y_test, logistic_predictions))

print("Naïve Bayes:")
print(f"Accuracy: {accuracy_score(y_test,
naive_bayes_predictions):.4f}")
print(classification_report(y_test, naive_bayes_predictions))

print("Support Vector Machine:")


print(f"Accuracy: {accuracy_score(y_test, svm_predictions):.4f}")
print(classification_report(y_test, svm_predictions))

Output

Result
Thus the SVM model achieved the highest accuracy ( ), followed by Logistic Regression
( ) and Naïve Bayes ( ) for heart disease diagnosis. The SVM model showed better
overall performance in terms of precision, recall, and F1-score.

You might also like