Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Telemedicine_App_Development
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashini Thilakarathne
Telemedicine_App_Development
Commits
afa8c4ba
Commit
afa8c4ba
authored
Jan 21, 2024
by
Shashini Thilakarathne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add prediction Model
parent
81d4dbf1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
0 deletions
+119
-0
heartdiseaseprediction.py
heartdiseaseprediction.py
+119
-0
No files found.
heartdiseaseprediction.py
0 → 100644
View file @
afa8c4ba
# -*- coding: utf-8 -*-
"""HeartDiseasePrediction.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1hhHh8Qb0fFC6wOQQ2LQtZaQwhztpL3Tr
"""
"""Importing Dependencies"""
import
numpy
as
np
import
pandas
as
pd
from
sklearn.model_selection
import
train_test_split
from
sklearn.linear_model
import
LogisticRegression
from
sklearn.metrics
import
accuracy_score
"""Data Collection and Processing"""
# Loading the csv data to a Pandas DataFrame
heart_data
=
pd
.
read_csv
(
'/content/data.csv'
)
# Print first 5 rows in the Dataset
heart_data
.
head
()
# Print last 5 rows in the Dataset
heart_data
.
tail
()
# Number of rows and columns in the Dataset
heart_data
.
shape
# Getting some information about the Data
heart_data
.
info
()
# Checking missing values
heart_data
.
isnull
()
.
sum
()
# Statiscical measure about the data
heart_data
.
describe
()
# Checking the destribution of target variable
heart_data
[
'target'
]
.
value_counts
()
"""1 --> Defective Heart
0 --> Healthy Heart
Splitting Features and Target
"""
x
=
heart_data
.
drop
(
columns
=
'target'
,
axis
=
1
)
Y
=
heart_data
[
'target'
]
print
(
x
)
print
(
Y
)
"""## Splitting Data into Training data & Test Data"""
x_train
,
x_test
,
Y_train
,
Y_test
=
train_test_split
(
x
,
Y
,
test_size
=
0.2
,
stratify
=
Y
,
random_state
=
2
)
print
(
x
.
shape
,
x_train
.
shape
,
x_test
.
shape
)
"""# Model Training
Logistic Regression Model
"""
model
=
LogisticRegression
()
# Training the LogisticRegression model with Training Data
model
.
fit
(
x_train
,
Y_train
)
"""# Model Evaluation
Accuracy Score
"""
# Accuracy Of Training Data
x_train_prediction
=
model
.
predict
(
x_train
)
training_data_accuracy
=
accuracy_score
(
x_train_prediction
,
Y_train
)
print
(
'Accuracy on Training data : '
,
training_data_accuracy
)
# accuracy on test data
x_test_prediction
=
model
.
predict
(
x_test
)
test_data_accuracy
=
accuracy_score
(
x_test_prediction
,
Y_test
)
print
(
'Accuracy on Test data : '
,
test_data_accuracy
)
"""# Building a Predictive System"""
input_data
=
(
62
,
0
,
0
,
140
,
268
,
0
,
0
,
160
,
0
,
3.6
,
0
,
2
,
2
)
# change the input data to a numpy array
input_data_as_numpy_array
=
np
.
asarray
(
input_data
)
# reshape the numpy array as we are predicting for only on instance
input_data_reshaped
=
input_data_as_numpy_array
.
reshape
(
1
,
-
1
)
prediction
=
model
.
predict
(
input_data_reshaped
)
print
(
prediction
)
if
(
prediction
[
0
]
==
0
):
print
(
'The Person does not have a Heart Disease'
)
else
:
print
(
'The Person has Heart Disease'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment