Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- heart_disease_model.pkl +3 -0
- heart_disease_model_training.py +75 -0
- requirements..txt +5 -0
heart_disease_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b683e24bbf2a703692f163a49025058ad3f95ca433af9d2f5fe65f324921f0da
|
3 |
+
size 998
|
heart_disease_model_training.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
from sklearn.model_selection import train_test_split
|
4 |
+
from sklearn.linear_model import LogisticRegression
|
5 |
+
from sklearn.metrics import accuracy_score
|
6 |
+
import pickle
|
7 |
+
|
8 |
+
heart_data = pd.read_csv(r'C:\Student\data/Copy of heart_disease_data.csv')
|
9 |
+
# print first 5 rows of the dataset
|
10 |
+
heart_data.head()
|
11 |
+
heart_data.tail()
|
12 |
+
# number of rows and columns in the dataset
|
13 |
+
heart_data.shape
|
14 |
+
# getting some info about the data
|
15 |
+
heart_data.info()
|
16 |
+
# checking for missing values
|
17 |
+
heart_data.isnull().sum()
|
18 |
+
# statistical measures about the data
|
19 |
+
heart_data.describe()
|
20 |
+
# checking the distribution of Target Variable
|
21 |
+
heart_data['target'].value_counts()
|
22 |
+
# 1 --> Defective Heart
|
23 |
+
#0 --> Healthy Heart
|
24 |
+
|
25 |
+
#Splitting the Features and Target
|
26 |
+
X = heart_data.drop(columns='target', axis=1)
|
27 |
+
Y = heart_data['target']
|
28 |
+
print(X)
|
29 |
+
print(Y)
|
30 |
+
#Splitting the Data into Training data & Test Data
|
31 |
+
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, stratify=Y, random_state=2)
|
32 |
+
print(X.shape, X_train.shape, X_test.shape)
|
33 |
+
#Model Training
|
34 |
+
|
35 |
+
#Logistic Regression
|
36 |
+
model = LogisticRegression()
|
37 |
+
# training the LogisticRegression model with Training data
|
38 |
+
model.fit(X_train, Y_train)
|
39 |
+
#Model Evaluation
|
40 |
+
# Save the trained model to a pickle file
|
41 |
+
with open('heart_disease_model.pkl', 'wb') as model_file:
|
42 |
+
pickle.dump(model, model_file)
|
43 |
+
|
44 |
+
print("Model trained and saved as 'heart_disease_model.pkl'")
|
45 |
+
|
46 |
+
# Load the saved model from the pickle file
|
47 |
+
with open('heart_disease_model.pkl', 'rb') as model_file:
|
48 |
+
loaded_model = pickle.load(model_file)
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
#Accuracy Score
|
53 |
+
# accuracy on training data
|
54 |
+
X_train_prediction = model.predict(X_train)
|
55 |
+
training_data_accuracy = accuracy_score(X_train_prediction, Y_train)
|
56 |
+
print('Accuracy on Training data : ', training_data_accuracy)
|
57 |
+
# accuracy on test data
|
58 |
+
X_test_prediction = model.predict(X_test)
|
59 |
+
test_data_accuracy = accuracy_score(X_test_prediction, Y_test)
|
60 |
+
print('Accuracy on Test data : ', test_data_accuracy)
|
61 |
+
#Building a Predictive System
|
62 |
+
input_data = (99,1,4,300,600,1,2,500,1,7.2,0,2,5)
|
63 |
+
# change the input data to a numpy array
|
64 |
+
input_data_as_numpy_array= np.asarray(input_data)
|
65 |
+
|
66 |
+
# reshape the numpy array as we are predicting for only on instance
|
67 |
+
input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
|
68 |
+
|
69 |
+
prediction = model.predict(input_data_reshaped)
|
70 |
+
print(prediction)
|
71 |
+
|
72 |
+
if (prediction[0]== 0):
|
73 |
+
print('The Person does not have a Heart Disease')
|
74 |
+
else:
|
75 |
+
print('The Person has Heart Disease')
|
requirements..txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip
|
2 |
+
streamlit
|
3 |
+
numpy
|
4 |
+
pandas
|
5 |
+
sklearn
|