Add prediction Model

parent 81d4dbf1
# -*- 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')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment