-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (23 loc) · 923 Bytes
/
main.py
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
# Import necessary libraries
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
# Load the dataset
data = pd.read_csv('heart-disease.csv')
# Define features (X) and target (y)
x = data.drop("target", axis=1) # assuming the target column is named 'target'
y = data["target"]
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
# Initialize the Logistic Regression model
model = LogisticRegression(max_iter=1000) # Increase max_iter
# Train the model
model.fit(X_train, y_train)
# Evaluate the model
predictions = model.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(f"Accuracy: {accuracy * 100:.2f}%")
import joblib
# # Save the model
# joblib.dump(model, 'logistic_regression_model.pkl')