All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Project 1: Suppose you are appointed as a Data scientist in any Pharma Company. That company makes medicine for heart disease. Your senior manager has given several clinical parameters about a patient, can you predict whether or not the patient has heart disease?There are following thirteens clinical parameters of the…
Akash Verma
updated on 15 Aug 2022
Project 1:
Suppose you are appointed as a Data scientist in any Pharma Company. That company makes medicine for heart disease. Your senior manager has given several clinical parameters about a patient, can you predict whether or not the patient has heart disease?
There are following thirteens clinical parameters of the patient.
1. age - age in years
2. sex - (1 = male; 0 = female)
3. cp - chest pain type
4. trtbps - resting blood pressure (in mm Hg on admission to the hospital) anything above 130-140 is typically cause for concern
5. chol - serum cholestoral in mg/dl
6. fbs - (fasting blood sugar > 120 mg/dl) (1 = true; 0 = false)
7. restecg - resting electrocardiographic results
8. thalachh - maximum heart rate achieved
9. exng - exercise induced angina (1 = yes; 0 = no)
10. oldpeak - ST depression induced by exercise relative to rest looks at stress of heart during excercise unhealthy heart will stress more
11. slp - the slope of the peak exercise ST segment
12. caa - number of major vessels (0-3) colored by flourosopy
13. thall - thalium stress result
14. output - have disease or not (1=yes, 0=no) (= the predicted attribute)
When you working on the health of patients then accuracy is deciding factor, Apply different machine learning algorithms and check the accuracy about predicting whether or not the patient has heart disease.
Apply all five different machine learning models Logistic Regression, K-Nearest Neighbours Classifier, Support Vector machine, Decision Tree Classifier, Random Forest Classifier on
the given dataset.
Solution:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 15 21:00:06 2022
@author: TUF
"""
"""
Logistic regressio n
"""
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# Importing Library for logistic regression
from sklearn.linear_model import LogisticRegression
# Importing performance metrics - accuracy_score, confusion_matrix
from sklearn.metrics import accuracy_score,confusion_matrix
###############################################################################
# Reading Data Set
crash_data = pd.read_csv('heart.csv')
"""
unique class
"""
print(np.unique(crash_data['sex'],return_counts=True))
# Storing the column names
crash_data_columns_list = list(crash_data.columns)
print(crash_data_columns_list)
# Separating the unput names from species
features = list(set(crash_data_columns_list)- set(['sex']))
print(features)
# Storing the output values in y
target = list(['sex'])
y= crash_data[target].values
y= crash_data['sex'].values
print(y)
# Storing the values from input features
x = crash_data[features].values
# Splitting the data into train and test
train_x, test_x, train_y, test_y = train_test_split(x, y, test_size=0.3,random_state=0)
# Data scaling
scaler= StandardScaler()
# Fit on training set only
scaler.fit(train_x)
# Apply transform to both the training set and the test set.
train_x = scaler.transform(train_x)
test_x = scaler.transform(test_x)
# Make an instance of the model
logistic = LogisticRegression()
# Fitting the values frof x and y
logistic.fit(train_x,train_y)
# Prediction from test data
prediction= logistic.predict(test_x)
# Confusion matrix
confusion_matrix = confusion_matrix(prediction,test_y)
print(confusion_matrix)
# Calculating the accuracy
accuracy_score= accuracy_score(prediction,test_y)
print(accuracy_score)
# Printing the misclassified valuesfrom prediction
print('Misclassified samples: %d' % (test_y != prediction).sum())
Output:
runfile('D:/3. skill lync/Challanges/7.ML/project1/project1.py', wdir='D:/3. skill lync/Challanges/7.ML/project1')
(array([0, 1], dtype=int64), array([ 96, 207], dtype=int64))
['age', 'sex', 'cp', 'trtbps', 'chol', 'fbs', 'restecg', 'thalachh', 'exng', 'oldpeak', 'slp', 'caa', 'thall', 'output']
['chol', 'restecg', 'slp', 'output', 'exng', 'cp', 'thalachh', 'age', 'thall', 'oldpeak', 'trtbps', 'fbs', 'caa']
[1 1 0 1 0 1 0 1 1 1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 1 0 1 1 0 1 0 1 1 1 1 0 0
1 0 0 0 1 1 0 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1 1 1 1
0 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 0 1 0 0 0 0
1 0 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 1 0 0
1 1 1 0 1 0 0 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 0 1 0 0 1 1 1 0 1
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0
1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1
0 1 0 1 1 1 0]
[[ 7 12]
[14 58]]
0.7142857142857143
Misclassified samples: 26
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 1
Project 1: Suppose you are appointed as a Data scientist in any Pharma Company. That company makes medicine for heart disease. Your senior manager has given several clinical parameters about a patient, can you predict whether or not the patient has heart disease?There are following thirteens clinical parameters of the…
15 Aug 2022 03:36 PM IST
Project 2
Project 2: Assume you are appointed as a Data scientist in any international humanitarian NGO, after the recent funding programmes, have been able to raise around $ 120 million. Now the CEO of the NGO call you to choose how to use this money strategically and effectively. The significant issues that comes while making…
15 Aug 2022 03:28 PM IST
Design and simulation of up/down converters using Simulink
1- Design a buck-boost converter with a source varying from 10 to 14 V. The output voltage is regulated at – 12 V. The load power is 15 W. The output voltage ripple must be less than 1 % for any operating condition.a) Determine the range of the duty ratio of the switch.b) Design the inductor and capacitor values…
03 Apr 2022 08:06 AM IST
Design and simulation of Boost converter using a SPICE based simulation tool
1- A group of engineers and entrepreneurs decided to design a solar laptop charger. The charger should be capable of charging an 18 V battery using the sun irradiation. They decided to use a semiconductor power electronic circuit to interface between the solar sheet and the laptop. Their financial budget would allow them…
03 Apr 2022 08:05 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.