Ex 12
Ex 12
DISEASE ANALYSIS.
EX.NO:
DATE:
AIM:
To write a python program to implement a Bayesian inference in cardiovascular disease analysis.
ALGORITHM:
1. Import the necessary libraries including pandas, sklearn, matplotlib, and seaborn.
2. Load the cardiovascular disease dataset (cardio_train.csv) using pandas with sep=';'.
4. Define the feature matrix X by selecting all columns except the target column cardio.
5. Define the target variable y as the cardio column which indicates disease presence (1)
or absence (0).
6. Check the dataset for any missing or null values and handle them if necessary.
7. Use the train_test_split function to split the data into 80% training and 20% testing
sets.
10. Train the model using the training dataset with the fit() method.
11. Make predictions on the testing dataset using the predict() method.
12. Calculate the accuracy of the model using the accuracy_score() function.
metrics.
import pandas as pd
X = data.drop('cardio', axis=1)
y = data['cardio']
gnb = GaussianNB()
gnb.fit(X_train, y_train)
y_pred = gnb.predict(X_test)
cm = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(6, 5))
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.title('Confusion Matrix')
plt.show()
OUTPUT:
RESULT: