0% found this document useful (0 votes)
14 views1 page

Lab 61007022

The document outlines a Python script that uses the Naive Bayes algorithm to predict heart disease based on a dataset from the UCI Machine Learning Repository. It includes data preprocessing steps, model training, and evaluation, ultimately reporting the model's accuracy and making a prediction for a sample input. The script utilizes libraries such as pandas and scikit-learn for data handling and machine learning tasks.

Uploaded by

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

Lab 61007022

The document outlines a Python script that uses the Naive Bayes algorithm to predict heart disease based on a dataset from the UCI Machine Learning Repository. It includes data preprocessing steps, model training, and evaluation, ultimately reporting the model's accuracy and making a prediction for a sample input. The script utilizes libraries such as pandas and scikit-learn for data handling and machine learning tasks.

Uploaded by

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

import pandas as pd

from sklearn.model_selection import train_test_split


from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score

url = "https://archive.ics.uci.edu/ml/machine-learning-databases/heart-disease/
processed.cleveland.data"

columns = ["age", "sex", "cp", "trestbps", "chol", "fbs", "restecg",


"thalach", "exang", "oldpeak", "slope", "ca", "thal", "heartdisease"]

data = pd.read_csv(url, names=columns, na_values="?", skipinitialspace=True)

data.dropna(inplace=True)
data = data.astype(int)

X = data.drop(columns=["heartdisease"])
y = data["heartdisease"]

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


random_state=42)

model = GaussianNB()
model.fit(X_train, y_train)

y_pred = model.predict(X_test)

accuracy = accuracy_score(y_test, y_pred)


print(f"Model Accuracy: {accuracy:.2f}")

sample_input = [[63, 1, 3, 145, 233, 1, 0, 150, 0, 2.3, 3, 0, 6]]


prediction = model.predict(sample_input)

print(f"Predicted Heart Disease Level: {prediction[0]}")

You might also like