bayesian network heart disease

 import pandas as pd

from sklearn.model_selection import train_test_split

from sklearn.naive_bayes import GaussianNB

from sklearn.metrics import accuracy_score


data = pd.read_csv("heart.csv") # Load dataset (ensure heart.csv is available)

X, y = data.iloc[:, :-1], data.iloc[:, -1] # Features and target

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

model = GaussianNB().fit(X_train, y_train) # Train Naive Bayes model

y_pred = model.predict(X_test) # Predict on test data

print("Accuracy:", accuracy_score(y_test, y_pred))

sample = [[57, 1, 2, 130, 236, 0, 0, 174, 0, 0.0, 1, 1, 3]] # Example input

print("Diagnosis:", "Heart Disease" if model.predict(sample)[0] else "No Heart Disease")

Comments

Popular posts from this blog

Web

Lab 1 ai