AdithyaSNair commited on
Commit
d1b0630
1 Parent(s): a0440fc

App and requirements

Browse files
Files changed (2) hide show
  1. app.py +79 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+ import gradio as gr
4
+ import pandas as pd
5
+ import seaborn as sns
6
+ from sklearn.preprocessing import LabelEncoder
7
+ from sklearn.model_selection import train_test_split
8
+ from sklearn.preprocessing import StandardScaler
9
+ from sklearn import svm
10
+ from sklearn.model_selection import KFold
11
+ from sklearn.model_selection import cross_val_score
12
+ from sklearn.tree import DecisionTreeClassifier
13
+ from sklearn.linear_model import LogisticRegression
14
+ def main(Gender,Age,Hypertension,Heart_disease,Ever_married,Work_type,Residence_type,Avg_glucose_level,BMI,Smoking_status ):
15
+ url = "https://raw.githubusercontent.com/ADITHYASNAIR2021/Dataset-cart/main/stroke%20data.csv"
16
+ data = pd.read_csv(url)
17
+ data.drop("id",axis=1,inplace=True)
18
+ data['bmi'].fillna(method="ffill",limit=1,inplace =True)
19
+ data['bmi'].fillna(method="ffill",limit=1,inplace =True)
20
+ data['bmi'].fillna(method="ffill",limit=1,inplace =True)
21
+ label_encoder = LabelEncoder()
22
+ data['gender']= label_encoder.fit_transform(data['gender'])
23
+ data['ever_married']= label_encoder.fit_transform(data['ever_married'])
24
+ data['work_type']= label_encoder.fit_transform(data['work_type'])
25
+ data['Residence_type']= label_encoder.fit_transform(data['Residence_type'])
26
+ data['smoking_status']= label_encoder.fit_transform(data['smoking_status'])
27
+ data['avg_glucose_level'] = data['avg_glucose_level'].astype(int)
28
+ data['bmi'] = data['bmi'].astype(int)
29
+ data['age'] = data['age'].astype(int)
30
+ y=data['stroke']
31
+ X=data.drop('stroke',axis=1)
32
+ data=pd.DataFrame(data)
33
+ X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=.25)
34
+ X_train = StandardScaler().fit_transform(X_train)
35
+ X_test = StandardScaler().fit_transform(X_test)
36
+ Log_reg = DecisionTreeClassifier(random_state=0)
37
+ Log_reg.fit(X_train,y_train)
38
+ 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}
39
+ index = [0]
40
+ cust_df = pd.DataFrame(data, index)
41
+ predLog = Log_reg.predict(cust_df)
42
+ if predLog == 0:
43
+ Prediction = "There is less chance for the patient to catch a Stroke"
44
+ if predLog == 1:
45
+ Prediction = "There is more chance for the patient to catch a Stroke."
46
+ return Prediction
47
+
48
+ iface = gr.Interface(fn = main,
49
+
50
+ inputs =['number','number','number','number','number','number','number','number','number','number'],
51
+
52
+ outputs =['text'],
53
+
54
+ title="Onset of Stroke prediction",
55
+
56
+ description =''' Description
57
+
58
+ 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.
59
+
60
+ 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.
61
+
62
+ 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.
63
+
64
+ The existing research is limited in predicting whether a stroke will occur or not.
65
+
66
+ Gender => Male = 0, Female = 1
67
+ Age
68
+ Hypertension => Yes = 1, No = 0
69
+ Heart_disease => Yes = 1, No = 0
70
+ Ever_married => Yes = 1, No = 0
71
+ Work_type => govt =0, student =1, private =2, self-employed =3
72
+ Residence_type => urban =1, rural =0
73
+ Avg_glucose_level (Lab tested)
74
+ BMI
75
+ Smoking_status => unknown =0, formerly smokes =1, never smokes =2, smoking =3
76
+ ''',
77
+ 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]])
78
+
79
+ iface.launch(debug =True)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ pandas
4
+ matplotlib
5
+ scikit-learn
6
+ seaborn