-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregression2
More file actions
52 lines (40 loc) · 1.29 KB
/
Copy pathregression2
File metadata and controls
52 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Logistic regression code :
# Import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
# Load dataset
df = pd.read_csv("heart_failure_clinical_records_dataset.csv")
# Feature and target
X = df.drop("DEATH_EVENT", axis=1)
y = df["DEATH_EVENT"]
# Train-test split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
# Feature scaling
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# Model
model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)
# Prediction
y_pred = model.predict(X_test)
# Accuracy
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy Score:", accuracy)
# Classification report
print("\nClassification Report:\n", classification_report(y_test, y_pred))
# Confusion Matrix
cm = confusion_matrix(y_test, y_pred)
print("\nConfusion Matrix:\n", cm)
# Heatmap
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues',
xticklabels=["Alive", "Dead"],
yticklabels=["Alive", "Dead"])