-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
69 lines (56 loc) · 2.31 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, render_template, request
import time
import random
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.naive_bayes import GaussianNB
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import LabelEncoder
from sklearn.compose import ColumnTransformer
from sklearn.linear_model import LogisticRegression
from sklearn.svm import LinearSVC
import numpy as np
from imblearn.combine import SMOTEENN
from imblearn.combine import SMOTETomek
import sklearn
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
import ml
from joblib import dump, load
# Init flask application
app = Flask(__name__)
#ct, pipe = ml.fitModel()
# load notebook here
pipe = load('savedModel.joblib')
ct = load('savedColumnTransformer.joblib')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/prediction', methods=['POST'])
def prediction():
gender = request.form['gender']
age = float(request.form['age'])
hypertension = int(request.form['hypertension'])
heartdisease = int(request.form['heartdisease'])
ever_married = request.form['ever_married']
work_type = request.form['work_type']
Residence_type = request.form['Residence_type']
avg_glucose_level = float(request.form['avg_glucose_level'])
answer = predictAnswer(ct, pipe, gender, age, hypertension, heartdisease, ever_married, work_type, Residence_type, avg_glucose_level)
return render_template('prediction.html', answer=answer)
def predictAnswer(ct, pipe, gender, age, hypertension, heartdisease, ever_married, work_type, Residence_type, avg_glucose_level):
row = [gender, age, hypertension, heartdisease, ever_married, work_type, Residence_type, avg_glucose_level]
row = ct.transform([row])
result = pipe.predict(row)
result = result[0]
if result == 1:
return "Yes, you may be likely to have a stroke. Please see a doctor."
elif result == 0:
return "No, you are not likely to have a stroke"
else:
return "A problem has occured in processing your data. Please reach out to Alex. She promises it was working before :("
if __name__ == '__main__':
# you can run init / fiting here
app.run(debug=True)