Spaces:
Runtime error
Runtime error
import numpy | |
import gradio as gr | |
import pandas as pd | |
from sklearn.preprocessing import LabelEncoder | |
from sklearn.model_selection import train_test_split | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.metrics import accuracy_score | |
from sklearn.svm import SVC | |
from sklearn.preprocessing import MinMaxScaler | |
def heart(Age,Sex,ChestPainType,RestingBP,Cholesterol,FastingBS,RestingECG,MaxHR,ExerciseAngina,Oldpeak,ST_Slope): | |
d=pd.read_csv("https://raw.githubusercontent.com/akarshsnair/Dataset-cart/main/heart.csv") | |
for col in d.columns: | |
if d[col].dtype == 'object': | |
d[col] = LabelEncoder().fit_transform(d[col]) | |
svm=SVC(probability=True) | |
xdf=d.drop("HeartDisease",axis=1) | |
ydf=d["HeartDisease"] | |
x_train,x_test,y_train,y_test=train_test_split(xdf,ydf,test_size=0.35,random_state=20) | |
mms=MinMaxScaler(feature_range=(0,1)) | |
x_train=mms.fit_transform(x_train) | |
x_test=mms.fit_transform(x_test) | |
x_train=pd.DataFrame(x_train) | |
x_test=pd.DataFrame(x_test) | |
svm=SVC(probability=True) | |
svm.fit(x_train,y_train) | |
predictions=svm.predict(x_test) | |
data = {'Age':Age,'Sex':Sex,'Chest Pain Type':ChestPainType,'Resting Blood Pressure':RestingBP,'Cholesterol level ':Cholesterol,'Fasting Blood Sugar':FastingBS,'Resting E.C.G':RestingECG,'Maximum Heart Rate achieved ':MaxHR,'Exercise induced Angina ':ExerciseAngina,'Old peak':Oldpeak,'ST_Slope':ST_Slope} | |
index = [0] | |
cust_df = pd.DataFrame(data, index) | |
costpredLog = svm.predict(cust_df) | |
if costpredLog ==0: | |
Prediction = "There is less chance for the patient to catch with heart disease" | |
else: | |
Prediction = "There is more of a chance for the patient to catch heart disease." | |
return Prediction | |
iface = gr.Interface(fn = heart, | |
inputs =['number','number','number','number','number','number','number','number','number','number','number'], | |
outputs =['text'], | |
title="Onset of heart disease failure prediction", | |
description =''' Description | |
Cardiovascular diseases (CVDs) are the number 1 cause of death globally, taking an estimated 17.9 million lives each year, which accounts for 31% of all deaths worlwide. | |
Heart failure is a common event caused by CVDs and this dataset contains 12 features that can be used to predict mortality by heart failure. | |
Most cardiovascular diseases can be prevented by addressing behavioural risk factors such as tobacco use, unhealthy diet and obesity, | |
physical inactivity and harmful use of alcohol using population-wide strategies. People with cardiovascular disease or who are at high cardiovascular risk | |
(due to the presence of one or more risk factors such as hypertension, diabetes, hyperlipidaemia or already established disease) | |
need early detection and management wherein a machine learning model can be of great help. | |
More details about the Inputs taken and how they needed to be taken are given below: | |
* Age (Your Age) | |
* Sex (Male (1) or Female (0)) | |
* Chest pain | |
1) ASY - 0 | |
2) ATA - 1 | |
3) NAP - 2 | |
4) TA - 3 | |
* RestingBP - Resting Blood pressure | |
* Cholesterol - Cholesterol level as of now | |
* FastingBS - Fasting blood sugar | |
1) Above 120,Type 1 | |
2) Below 120,Type 0 | |
* RestingECG | |
1) LVH - 0 | |
2) NORMAL - 1 | |
3) ST - 2 | |
* MaxHR - Is the maximum heart rate recorded | |
* ExerciseAngina - Do you have Angine while you exercise | |
1) No - 0 | |
2) Yes - 1 | |
* Oldpeak - ST depression induced by exercise relative to rest. | |
* ST_Slope - The ST segment shift relative to exercise-induced increments in heart rate | |
1) Down - 0 | |
2) Flat - 1 | |
3) UP - 2 | |
''', | |
article=''' This application is made for Hackathon'22 | |
Through this project, we are looking forward to providing insight into the health of each and every person. | |
The dataset is taken from Kaggle and the link for the dataset is provided here: | |
Dataset link as Raw form: https://raw.githubusercontent.com/ADITHYASNAIR2021/Dataset-cart/main/heart.csv | |
''') | |
iface.launch(debug = True) |