from sklearn.metrics import confusion_matrix
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
import numpy as np

df = pd.read_csv("data.csv")
age = df["variance"]
heart_attack = df["class"]
age_train, age_test, ha_train, ha_test = train_test_split(age, heart_attack, test_size=0.25, random_state=0)
x = np.reshape(age_train.ravel(), (len(age_train), 1))
y = np.reshape(ha_train.ravel(), (len(ha_train), 1))

classifier = LogisticRegression(random_state=0)
classifier.fit(x, y)
x_test = np.reshape(age_test.ravel(), (len(age_test), 1))
y_test = np.reshape(ha_test.ravel(), (len(ha_test), 1))

ha_prediction = classifier.predict(x_test)

predicted_val = []

for i in ha_prediction:
	if i == 0:
		predicted_val.append("No")
	else:
		predicted_val.append("Yes")

actual_val = []

for i in y_test.ravel():
	if i == 0:
		actual_val.append("No")
	else:
		actual_val.append("Yes")

labels = ["Yes", "No"]

cm = confusion_matrix(predicted_val, actual_val, labels)
ax = plt.subplot()
sns.heatmap(cm, annot=True, ax=ax)
ax.set_xlabel("Predicted")
ax.set_ylabel("Actual")
ax.set_title("Error Matrix")
plt.show()
from sklearn.metrics import confusion_matrix
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
import numpy as np

df = pd.read_csv("data.csv")
age = df["variance"]
heart_attack = df["class"]
age_train, age_test, ha_train, ha_test = train_test_split(age, heart_attack, test_size=0.25, random_state=0)
x = np.reshape(age_train.ravel(), (len(age_train), 1))
y = np.reshape(ha_train.ravel(), (len(ha_train), 1))

classifier = LogisticRegression(random_state=0)
classifier.fit(x, y)
x_test = np.reshape(age_test.ravel(), (len(age_test), 1))
y_test = np.reshape(ha_test.ravel(), (len(ha_test), 1))

ha_prediction = classifier.predict(x_test)

predicted_val = []

for i in ha_prediction:
	if i == 0:
		predicted_val.append("No")
	else:
		predicted_val.append("Yes")

actual_val = []

for i in y_test.ravel():
	if i == 0:
		actual_val.append("No")
	else:
		actual_val.append("Yes")

labels = ["Yes", "No"]

cm = confusion_matrix(predicted_val, actual_val, labels)
ax = plt.subplot()
sns.heatmap(cm, annot=True, ax=ax)
ax.set_xlabel("Predicted")
ax.set_ylabel("Actual")
ax.set_title("Error Matrix")
plt.show()