import numpy as np import matplotlib.pyplot as plt import gradio as gr import pandas as pd import seaborn as sns from sklearn.preprocessing import LabelEncoder from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn import svm from sklearn.model_selection import KFold from sklearn.model_selection import cross_val_score from sklearn.tree import DecisionTreeClassifier from sklearn.linear_model import LogisticRegression def main(Gender,Age,Hypertension,Heart_disease,Ever_married,Work_type,Residence_type,Avg_glucose_level,BMI,Smoking_status ): url = "https://raw.githubusercontent.com/ADITHYASNAIR2021/Dataset-cart/main/stroke%20data.csv" data = pd.read_csv(url) data.drop("id",axis=1,inplace=True) data['bmi'].fillna(method="ffill",limit=1,inplace =True) data['bmi'].fillna(method="ffill",limit=1,inplace =True) data['bmi'].fillna(method="ffill",limit=1,inplace =True) label_encoder = LabelEncoder() data['gender']= label_encoder.fit_transform(data['gender']) data['ever_married']= label_encoder.fit_transform(data['ever_married']) data['work_type']= label_encoder.fit_transform(data['work_type']) data['Residence_type']= label_encoder.fit_transform(data['Residence_type']) data['smoking_status']= label_encoder.fit_transform(data['smoking_status']) data['avg_glucose_level'] = data['avg_glucose_level'].astype(int) data['bmi'] = data['bmi'].astype(int) data['age'] = data['age'].astype(int) y=data['stroke'] X=data.drop('stroke',axis=1) data=pd.DataFrame(data) X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=.25) X_train = StandardScaler().fit_transform(X_train) X_test = StandardScaler().fit_transform(X_test) Log_reg = DecisionTreeClassifier(random_state=0) Log_reg.fit(X_train,y_train) data = {'gender':Gender,'age':Age,'hypertension':Hypertension,'heart_disease':Heart_disease,'ever_married':Ever_married,'work_type':Work_type,'Residence_type':Residence_type,'avg_glucose_level':Avg_glucose_level,'bmi':BMI,'smoking_status':Smoking_status} index = [0] cust_df = pd.DataFrame(data, index) predLog = Log_reg.predict(cust_df) if predLog == 0: Prediction = "There is less chance for the patient to catch a Stroke" if predLog == 1: Prediction = "There is more chance for the patient to catch a Stroke." return Prediction iface = gr.Interface(fn = main, inputs =['number','number','number','number','number','number','number','number','number','number'], outputs =['text'], title="Onset of Stroke prediction", description =''' Description Stroke is a disease that affects the arteries leading to and within the brain. A stroke occurs when a blood vessel that carries oxygen and nutrients to the brain is either blocked by a clot or ruptures. According to the WHO, stroke is the 2nd leading cause of death worldwide. Globally, 3% of the population is affected by subarachnoid haemorrhage, 10% with intracerebral haemorrhage, and the majority of 87% with ischemic stroke. 80% of the time these strokes can be prevented, so putting in place proper education on the signs of stroke is very important. The existing research is limited in predicting risk factors pertained to various types of strokes. Early detection of stroke is a crucial step for efficient treatment and ML can be of great value in this process. To be able to do that, Machine Learning (ML) is an ultimate technology which can help health professionals make clinical decisions and predictions. During the past few decades, several studies were conducted on the improvement of stroke diagnosis using ML in terms of accuracy and speed. The existing research is limited in predicting whether a stroke will occur or not. Gender => Male = 0, Female = 1 Age Hypertension => Yes = 1, No = 0 Heart_disease => Yes = 1, No = 0 Ever_married => Yes = 1, No = 0 Work_type => govt =0, student =1, private =2, self-employed =3 Residence_type => urban =1, rural =0 Avg_glucose_level (Lab tested) BMI Smoking_status => unknown =0, formerly smokes =1, never smokes =2, smoking =3 ''', examples=[[1,67.0,0,1,1,2,1,228.69,36.6,1],[0,18.0,0,0,0,2,1,82.85,46.9,0]]) iface.launch(debug =True)